Overview
The Platform API uses a flexible Role-Based Access Control (RBAC) system with two permission scopes:- Company-scoped permissions: Managed through roles within each company (tenant)
- Global permissions: Platform-level permissions assigned directly to users
Architecture
Permissions
Permission Model
Permissions are defined globally and can be assigned at two levels:Permission Structure
key: Unique identifier in dot notation (e.g.,members.invite,projects.delete)description: Human-readable explanation of what the permission allowsscope: Determines how the permission can be assigned
Permission Scopes
- COMPANY Scope
- GLOBAL Scope
Company-scoped permissions are managed through roles within each company.
- Assigned to Roles, which are then assigned to Memberships
- Only effective within a specific company context
- Each company can configure roles independently
- Default scope for most business logic permissions
members.invite- Invite new members to the companyprojects.create- Create projects within the companytime-entries.manage- Manage time entries for the company
Permission Assignment
Roles
Role Model
Roles are company-specific and group related permissions:Role Structure
name: Must be unique within the companycolor: Hex color for UI display (defaults to#6366F1)isSystem: Protected system roles that cannot be deletedisDefault: One role per company marked as default for new members
System Roles
When a company is created, four default roles are automatically generated:Owner
Color:
System: Yes
Default: NoFull control over the company. Typically assigned to the company creator.
#EF4444 (Red)System: Yes
Default: NoFull control over the company. Typically assigned to the company creator.
Admin
Color:
System: Yes
Default: NoElevated privileges for managing company resources and members.
#F59E0B (Orange)System: Yes
Default: NoElevated privileges for managing company resources and members.
Manager
Color:
System: No
Default: NoTeam oversight and project management capabilities.
#3B82F6 (Blue)System: No
Default: NoTeam oversight and project management capabilities.
Member
Color:
System: Yes
Default: YesStandard member with basic access. Automatically assigned to new members.
#6B7280 (Gray)System: Yes
Default: YesStandard member with basic access. Automatically assigned to new members.
Role Management
Create Role
Create Role
Update Role
Update Role
Delete Role
Delete Role
- Role has
isSystem: true - Role is assigned to any members (delete restriction)
Set Default Role
Set Default Role
Membership Roles
Many-to-Many Relationship
A membership can have multiple roles, and a role can be assigned to multiple memberships:MembershipRole Join Table
- Primary key on
(membershipId, roleId)prevents duplicates ON DELETE Cascadeon membership - removing membership deletes role assignmentsON DELETE Restricton role - cannot delete role if assigned to any member
Assigning Roles to Members
Update Member Roles
- Removes all existing role assignments for the member
- Creates new assignments for the provided role IDs
- Returns the updated membership with new roles
Permission Checks
Global Permission Check
Use thecheckGlobalPermission middleware for platform-level operations:
- Checks if user is a platform admin (bypass)
- Looks up permission by key with
scope: GLOBAL - Verifies
UserGlobalPermissionexists for the user - Throws 403 Forbidden if permission not found
Company Permission Check
For company-scoped permissions, check through membership roles:Platform Admin Bypass
Platform administrators automatically pass all permission checks:- Access all companies and their resources
- Perform any action regardless of role assignments
- Manage system-level configurations
Permission Request System
Users can request global permissions through a formal approval workflow:Request Flow
Request Statuses:
PENDING- Awaiting admin reviewAPPROVED- Admin approved, permission grantedREJECTED- Admin rejected with reasonCANCELLED- User cancelled their own request
Best Practices
Principle of Least Privilege
Grant only the minimum permissions required for a role. Start with restricted access and expand as needed.
Use Descriptive Keys
Permission keys should follow the pattern
resource.action (e.g., members.invite, projects.delete) for clarity.Protect System Roles
Mark critical roles with
isSystem: true to prevent accidental deletion. Validate this flag in your application logic.Audit Permission Changes
Log all permission grants, revocations, and role assignments for security auditing and compliance.
Related Concepts
Multi-Tenancy
Learn how companies provide tenant isolation
Memberships
Understand how roles connect to user memberships
Invitations
See how default roles are assigned during invitation