Skip to main content

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 a companies 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:
Key Fields:
  • plan_type - Subscription tier (e.g., free, basic, premium)
  • subscription_status - Current status (active, suspended, inactive)
  • max_employees - Resource limit for employee accounts
  • storage_used - Track storage consumption per tenant

Tenant Isolation

Data Segregation

All tenant-specific resources include a company_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 the company_id claim to enforce tenant boundaries:
See Authentication for details on JWT implementation.

Request Validation

API handlers validate that the authenticated user’s company_id matches the requested resource:
/home/daytona/workspace/source/handlers/employee_handler.go:293-308
Attempting to access resources from a different company will result in a 400 Bad Request error.

Company Status

Companies can have the following status values: The authentication system validates company status during login to prevent access to non-active tenants.

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.

Authentication

Learn how JWT tokens enforce tenant isolation

Authorization

Understand role-based access control per tenant