Multi-Tenancy Architecture¶
Atlas ERP is designed to serve multiple organizations (tenants) from a single deployment while ensuring strict data isolation.
The Multi-Tenant Model¶
Atlas utilizes a Logical Isolation (Row-Level Isolation) strategy. - All tenants share the same application instances (NestJS APIs and Next.js Web Apps). - All tenants share the same PostgreSQL database. - Data isolation is enforced using a workspaceId (or organizationId) column on nearly every table.
Why Logical Isolation?¶
- Cost-Effective: Sharing infrastructure reduces hosting costs significantly compared to database-per-tenant or instance-per-tenant models.
- Easier Maintenance: Running migrations and updating the application happens once for all tenants.
- Scalability: Handles thousands of small to medium tenants efficiently on standard connection pools.
Database Schema Implementation¶
Almost every entity in the Prisma schema belongs to a Workspace (Organization).
Security & Data Isolation Enforcement¶
It is critical that Tenant A cannot access Tenant B's data. This is enforced at the API layer.
1. The Workspace Context¶
When a user logs in, they select an active workspace. The backend manages this context either through Better Auth's Organization plugin or by issuing a workspace-specific JWT (legacy flow).
2. The Workspace Guard¶
Every API endpoint that deals with tenant-specific data is protected by the WorkspaceGuard.
3. Service-Level Enforcement¶
Within NestJS Services, the workspaceId is extracted from the request context and always appended to Prisma queries.
By ensuring that workspaceId is a required parameter in all service methods and always included in where clauses, the risk of data leakage is minimized.