Overview
CompanyFlow uses a multi-tenant architecture where each company operates as an isolated tenant with its own data, settings, and user base. This design ensures complete data separation between organizations while maintaining a single unified application.Core Concepts
Company Entity
Every tenant is represented by acompanies record that stores organizational information:
The
slug field enables subdomain-based routing (e.g., acme.companyflow.com) for tenant identification.Tenant Metadata
Each company has associated tenant configuration that manages subscription and resource limits:plan_type- Subscription tier (e.g., free, basic, premium)subscription_status- Current status (active, suspended, inactive)max_employees- Resource limit for employee accountsstorage_used- Track storage consumption per tenant
Tenant Isolation
Data Segregation
All tenant-specific resources include acompany_id foreign key to enforce data isolation:
- Employees - Each employee belongs to one company
- Roles - Custom roles are scoped to a company
- Departments - Organizational structure per tenant
- Leaves - Time-off requests isolated by company
- Permissions - Access controls per company
JWT Token Scoping
Authentication tokens include thecompany_id claim to enforce tenant boundaries:
Request Validation
API handlers validate that the authenticated user’scompany_id matches the requested resource:
/home/daytona/workspace/source/handlers/employee_handler.go:293-308
Company Status
Companies can have the following status values:| Status | Description |
|---|---|
active | Normal operations, all features available |
suspended | Temporary access restriction (e.g., payment issue) |
inactive | Deactivated account, no access permitted |
Best Practices
Always Include Company ID
Include the
company_id in API requests or rely on the JWT token to extract it automatically.Validate Tenant Access
Never assume cross-tenant access is valid. Always verify the authenticated user belongs to the requested company.
Use Cascading Deletes
The schema uses
ON DELETE CASCADE to ensure complete data cleanup when a company is removed.Monitor Resource Limits
Check tenant limits (e.g.,
max_employees) before allowing resource creation.Related Concepts
Authentication
Learn how JWT tokens enforce tenant isolation
Authorization
Understand role-based access control per tenant