Overview
The Platform API is built on a multi-tenant architecture where each company represents an isolated workspace (tenant). Users can belong to multiple companies, and all company data is completely isolated from other tenants.Core Concepts
Companies as Tenants
Each Company represents an independent workspace with:- Unique identifier: UUID-based company ID
- Slug: Human-readable unique identifier for URLs (e.g.,
acme-corp) - Metadata: Flexible JSON field for custom tenant configuration
- Status: Controls tenant access and availability
- Soft delete: Archive companies without data loss
Company Model
Tenant Status
Companies can have the following statuses:ACTIVE
ACTIVE
The company is fully operational. Members can access all resources and features.
SUSPENDED
SUSPENDED
The company is suspended. Access is blocked for all members except platform admins. This status is automatically applied when a company is soft-deleted.
Data Isolation
Automatic Tenant Scoping
All tenant-scoped resources are automatically isolated bycompanyId:
- Memberships: User-Company relationships
- Roles & Permissions: Company-specific RBAC configuration
- Projects: Company work items
- Time Entries: Employee time tracking
- Clients: Company customer records
- Invitations: Member invite management
Access Control Middleware
The API uses middleware to enforce tenant boundaries:Example: Company Access Check
Database-Level Isolation
The database schema enforces isolation through:- Foreign Keys: All tenant resources reference
companyId - Composite Indexes: Optimized queries on
(companyId, ...) - Cascade Deletes: Removing a company cascades to all related resources
- Unique Constraints: Tenant-scoped uniqueness (e.g.,
companyId + namefor roles)
Company Lifecycle
1. Creation
Companies can be created through:Platform Admin Invite
Admin creates a
CompanyInvite with a secure token. The invited user registers and creates their company using the invite token.User Request Flow
User submits a
CompanyRequest with company details. Platform admin reviews and approves/rejects the request. User creates company after approval.2. Initialization
When a company is created, the system automatically:Default Setup
3. Active Usage
During normal operation:- Members interact with company resources through their memberships
- Roles define what actions members can perform
- Permissions are scoped to the company (with exceptions for global permissions)
- Data is isolated and never accessible across company boundaries
4. Suspension
Companies can be suspended by platform admins:- All members lose access (except platform admins)
- API requests to company resources return 403 Forbidden
- Company appears as suspended in listings
5. Soft Delete
Companies can be soft-deleted (archived):- Sets
deletedAttimestamp andstatus: SUSPENDED - Company hidden from default listings
- All relationships preserved for potential restoration
- Can be restored by platform admins:
Multi-Tenancy Patterns
User Context Switching
Users can belong to multiple companies and switch between them:User's Companies
- Store the currently selected
companyIdin state - Include it in API requests where needed
- Switch context when user selects a different company
- Refresh permissions and roles for the new context
Platform Admin Override
Platform administrators have special privileges:- Access all companies regardless of membership
- Bypass permission checks within companies
- Manage company lifecycle (create, suspend, delete, restore)
- View and manage all members across companies
isPlatformAdmin flag is set by middleware and checked throughout the system:
Best Practices
Always Filter by Company
When querying tenant-scoped resources, always include
companyId in your WHERE clause to prevent accidental cross-tenant data leaks.Use Middleware
Apply
checkCompanyAccess middleware to all company-scoped routes to enforce tenant boundaries at the API level.Validate Company Context
Before creating resources, verify that all referenced entities (users, roles, projects, etc.) belong to the same company.
Test Isolation
Write integration tests that verify users cannot access data from companies they don’t belong to.
Related Concepts
Memberships
Learn how users connect to companies through memberships
RBAC
Understand role-based access control within companies
Invitations
Explore company creation and member invitation flows