ADR-001: Multi-Tenant Architecture

Status: Accepted
Date: 2025-01-27
Deciders: Technical Architecture Team

Context

Zixly is an open-source internal operations platform for the Zixly service business. We need to decide on the data architecture approach for supporting multiple data isolation requirements.

Business Context:

Options Considered:

  1. Database-per-tenant (separate databases)
  2. Schema-per-tenant (separate schemas)
  3. Row-level security (shared database, RLS policies)

Decision

We will use Row-Level Security (RLS) with a shared PostgreSQL database.

Rationale:

Consequences

Positive:

Negative:

Implementation

Database Schema

RLS Policies

-- Set tenant context on login
SET app.tenant_id = 'zixly-org-001';

-- RLS policy ensures only Zixly data is accessible
CREATE POLICY tenant_isolation_users ON users
  USING (tenant_id = current_setting('app.tenant_id', true)::text);

CREATE POLICY tenant_isolation_clients ON client_kpis
  USING (tenant_id = current_setting('app.tenant_id', true)::text);

Prisma Integration

// All queries automatically scoped by tenant
const clients = await prisma.clientKPI.findMany({
  where: { tenantId }, // Automatically enforced by RLS
  include: {
    financials: true,
    leadEvents: true,
    customMetrics: true,
  },
})

Future Considerations

Multi-Tenant SaaS (Not Planned)

If Zixly were to become a multi-tenant SaaS platform in the future:

Open-Source Community

Review

Next Review: 2025-04-27
Reviewers: Technical Architecture Team
Status: Accepted and implemented


Document Version: 1.0
Last Updated: 2025-01-27
Owner: Technical Architecture Team