Skip to content

3. Multi‐Tenancy Approach

Max Geller edited this page Oct 5, 2024 · 4 revisions

Multi-Tenancy Approach

This starter project implements a single-database multi-tenant architecture using Angular 18 and Supabase. The approach isolates tenant data within separate schemas of a single database, ensuring data security and scalability.

Key Components

  1. Database Structure

    • Single database with separate schemas for each tenant
    • Tenant-specific tables in individual schemas
    • Shared tables (e.g., 'tenants') in the public schema
  2. Row-Level Security (RLS)

    • Supabase RLS policies ensure data isolation between tenants
    • Policies filter data based on tenant ID
  3. Authentication and Authorization

    • Supabase Auth for secure user authentication
    • Role-Based Access Control (RBAC) for managing permissions within each tenant
    • TenantGuard and TenantService in Angular to enforce tenant-specific access
  4. Tenant Isolation

    • Users can only access data belonging to their assigned tenant
    • Angular guards implemented to enforce isolation at the application level
  5. Performance Optimization

    • Indexing strategies for efficient tenant-specific queries
    • Consideration for caching frequently accessed data
  6. Scalability

    • Database schema and application architecture designed for horizontal scaling
    • Connection pooling for efficient database connection management

Implementation Notes

  • Custom Claims: While not used in this starter project, JWT custom claims can be utilized for storing tenant-specific information and enhancing access control.

  • Data Access: The combination of database schema isolation, RLS policies, and Angular guards ensures that users can only interact with data from their assigned tenant.

  • Extensibility: This starter project provides a foundation for building multi-tenant SaaS applications. You can extend the existing structure to accommodate your specific business requirements and additional features.

Getting Started

To begin using this multi-tenant starter:

  1. Review the database schema and RLS policies in Supabase
  2. Familiarize yourself with the TenantGuard and TenantService implementations in the Angular codebase
  3. Customize the tenant onboarding process as needed for your application
  4. Extend the RBAC system to match your specific permission requirements

Remember to thoroughly test the tenant isolation and access controls as you build upon this starter project.

Clone this wiki locally