Tenelix
Documentation

Tenancy modes

Standard, Enterprise (cloud), and Enterprise (self-hosted) — how they differ, when to use each.

Tenelix supports three tenancy modes via the TENANCY_MODE environment variable:

ModeDescriptionBest for
sharedAll tenants share one database, scoped by tenant_idCost-effective SaaS, small clinics
enterpriseEach tenant gets a dedicated databaseLarge hospitals, strict compliance
hybridShared by default, dedicated on graduation (default)Flexible SaaS with enterprise options

Shared mode

In shared mode, all operational data lives in tenelix_tenants_shared. Every table has a tenant_id column, and queries are automatically scoped via Eloquent global scopes. This is the most cost-effective model, suitable for the majority of SaaS clinics.

Enterprise mode

In enterprise mode, every tenant has a dedicated PostgreSQL database named tenant_{uuid}. Tables don't carry a tenant_id column — the database itself is the isolation boundary. This provides the strongest isolation for compliance-sensitive customers (HIPAA, NDPA-2023).

Hybrid mode combines both: tenants start in shared mode for cost efficiency, and graduate to enterprise mode when they need dedicated resources. The graduation is operational — application code is unchanged. See the Hybrid multi-tenancy blog post for the architectural detail.

Service connection management

Laravel's session, cache, and queue services need to write to the correct tenant database. The HybridServiceConnectionBootstrapper handles this automatically — application code keeps using Cache::get() and Auth::user() like nothing changed.

ServiceShared tenantEnterprise tenant
Sessionstenelix_tenants_shared.sessionstenant_{uuid}.sessions
Cachetenelix_tenants_shared.cachetenant_{uuid}.cache
Queuetenelix_tenants_shared.jobstenant_{uuid}.jobs