Multi-Tenancy

ContractSpec is designed from the ground up for multi-tenancy. Apps built with ContractSpec can serve multiple organizations (tenants) from a single deployment, while ensuring strict data isolation and configuration separation.

Core Concepts

  • Tenant: An organization or customer that uses your app. Each tenant has a unique tenantId.
  • Tenant Isolation: Data and configuration for one tenant is never accessible to another tenant unless explicitly shared.
  • Tenant Context: Every request and operation runs within the context of a specific tenant.

Tenant Resolution

The runtime automatically resolves the tenant context for every request based on:

  • Subdomain (e.g., acme.app.com)
  • Custom Domain (e.g., portal.acme.com)
  • Header (e.g., x-tenant-id: acme-corp)
  • Authentication Token (embedded tenant claim)

Configuration Isolation

Each tenant has its own TenantAppConfig which defines:

type TenantAppConfig = {
  tenantId: string;
  blueprintId: string;
  // ...
  integrationBindings: AppIntegrationBinding[];
  knowledgeBindings: AppKnowledgeBinding[];
  featureFlags: Record<string, boolean>;
};

This allows you to customize feature flags, integration connections, and knowledge sources per tenant without changing the application code.