Domain Model
Core entities and business rules
Domain Model
Goal
Build a multi-tenant HR data model that supports employee management, time-off tracking, documents, team communication, goals, and workflows with flexible organizational relationships.
Core Entities (~20 entities)
| Entity | Purpose |
|---|---|
| Tenant | Company using the HRMS |
| User | Authentication account (linked to Employee) |
| Employee | Person working for a tenant |
| Department | Organizational unit |
| Team | Cross-functional or permanent grouping |
| Role | Job role within tenant |
| TimeOffPolicy | Policy defining leave types and allowances |
| TimeOffBalance | Employee's balance for a policy year |
| TimeOffRequest | Leave request with approval workflow |
| Document | Files and HR documents with access control |
| DocumentAccess | Fine-grained document sharing |
| TeamPost | Feed posts with likes/comments |
| Goal | OKR/goal tracking |
| KeyResult | Measurable outcomes for goals |
| Workflow | Onboarding/offboarding templates |
| WorkflowTask | Individual tasks in workflows |
| Tag | Flexible categorization system |
| TagCategory | Groups of related tags |
| CustomFieldDefinition | Tenant-defined metadata fields |
| Dashboard | Configurable widget dashboards |
Organizational Structure
Flexible Manager Relationships
The HRMS supports flexible organizational relationships, not just 1:1 manager-employee:
┌─────────────────────────────────────────────────────────────┐
│ Employee Relationships │
├─────────────────────────────────────────────────────────────┤
│ Primary Manager │ 0..1 │ Main reporting line │
│ Dotted-Line Mgrs │ 0..N │ Secondary reporting (projects) │
│ Departments │ 0..N │ Can belong to multiple depts │
│ Teams │ 0..N │ Cross-functional team members │
│ Roles │ 0..N │ Multiple job roles supported │
└─────────────────────────────────────────────────────────────┘Relationship Types
| Relationship | Cardinality | Purpose |
|---|---|---|
| Employee → Primary Manager | 0..1 | Main reporting line (nullable for CEO/founders) |
| Employee ↔ Dotted-Line Managers | 0..N | Project leads, matrix reporting |
| Employee ↔ Departments | 0..N | Multi-department assignments |
| Employee ↔ Teams | 0..N | Team memberships with roles |
| Employee ↔ Roles | 0..N | Job titles and responsibilities |
Circular Reference Prevention
The system automatically validates:
- No employee can be their own manager (direct cycle)
- No circular chains (A → B → C → A)
- Terminated employees cannot be managers
Time-Off System
Policy Structure
TimeOffPolicy
├── Code (e.g., "VACATION", "SICK")
├── Leave Type (PAID/UNPAID/PARENTAL/etc.)
├── Annual Allowance (days)
├── Accrual Schedule (ANNUAL/MONTHLY/NONE)
├── Carry-Over Rules
└── Required Approval LevelBalance Calculation
Available = Total Allocation
+ Carried Over
- Used (approved)
- Pending (awaiting approval)Document Access Control
Visibility Levels
| Level | Who Can View |
|---|---|
| PRIVATE | Only owner |
| TEAM | Owner's team members |
| DEPARTMENT | Owner's department |
| MANAGERS | All managers in tenant |
| COMPANY | All employees in tenant |
| CUSTOM | Specific users/teams/departments |
Documents also support:
- Tag-based categorization
- Time-limited sharing (expiration dates)
- Download vs view-only permissions
Goals/OKR Structure
Goal
├── Title, Description
├── Type (PERSONAL/TEAM/DEPARTMENT/COMPANY)
├── Time Period (Q1, Q2, H1, YEAR)
├── Status (DRAFT/ACTIVE/COMPLETED/CANCELLED)
├── Progress (0-100%)
└── Key Results (0..N)
├── Description
├── Target Value
├── Current Value
└── Unit (%, count, currency)Tag System
Tags provide flexible categorization:
TagCategory (e.g., "Skills", "Locations")
└── Tags (e.g., "Python", "Remote")
└── Can be assigned to:
├── Employees
├── Documents
└── GoalsRole-based permissions control who can assign/remove tags.
Custom Fields
Tenants can define additional fields for entities:
| Entity Type | Example Custom Fields |
|---|---|
| Employee | T-Shirt Size, Emergency Contact, Employee ID (external) |
| Department | Cost Center, Budget Code |
| Team | Project Code, Slack Channel |
| Goal | Priority Level, Business Unit |
Field types: TEXT, NUMBER, DATE, DROPDOWN, CHECKBOX, URL, EMAIL
Key Use Cases
- Flexible Org Structure - Primary managers + dotted-line managers + multi-team membership
- Time-Off Workflow - Submit → Manager(s) approve → Balance updates
- Document Access Control - Fine-grained sharing with expiration
- Team Communication - Posts with visibility controls (team, department, company)
- OKR Tracking - Goals with key results, progress tracking
- Workflow Automation - Onboarding/offboarding task templates
- Tagging - Flexible categorization with permissions
- Custom Fields - Tenant-specific metadata
Critical Rules
Multi-Tenancy
- Every entity (except Tenant) has
tenantId - Every query must filter by
tenantId - Complete data isolation between tenants
- PostgreSQL RLS as additional safety layer
IDs and Audit
- All IDs are UUIDs (v4)
- All entities have
createdAt,updatedAt - Soft deletes via
deletedAtfield - Audit logs for sensitive operations
Employee Rules
- Employee number unique within tenant
- Email unique within tenant
- Manager must be active employee in same tenant
- No circular management chains
- Terminated employees cannot be managers
- Status transitions: ONBOARDING → ACTIVE → ON_LEAVE → TERMINATED
Time-Off Rules
- Balance: available = total - used - pending
- Employees cannot approve own requests
- Managers approve for direct reports only
- No overlapping approved time-off
- Policies define accrual and carry-over rules
Document Rules
- Max 10MB per file
- Allowed: PDF, DOCX, DOC, XLS, XLSX, JPG, PNG, GIF
- No executables (.exe, .sh, .bat)
- Access checked on every request (not cached)
Tag Rules
- Tags belong to categories
- Categories define which entity types can use them
- Role-based permissions for tag assignment/removal
Complete Schema: See Database Schema for full Prisma models.