Tenant Starter
Demo testedA multi-tenant SaaS starter using FastAPI, OIDC identity, and PostgreSQL row-level security.

- 2
- synthetic tenants
- 5
- tests run against PostgreSQL 17
Overview
Two synthetic tenants use the same API and database. To list or create an item, a user must provide a valid token and belong to the selected tenant.
The model builds on the membership and access policy concepts used in the condo management project.
What it does
- Identity and membership
- The API validates JWT signature, issuer, audience, and expiration. The backend checks membership before setting data scope.
- Database policies
- PostgreSQL scopes reads and inserts to the transaction tenant. RLS applies to the API role.
Architecture
Decisions and trade-offs
- Transaction-scoped access
- The tenant context ends with the transaction. This allows connections to return to the pool after commit or rollback.
Quality and operations
- Tests verify read and write isolation, fail-closed behavior without context, and scope cleanup on the same pooled connection.
- Signed JWTs were validated against a simulated JWKS in tests.
Status and next steps
- Integrate an identity provider and prepare migrations and membership management for a persistent deployment.
Stack
PythonFastAPISQLAlchemyPostgreSQLRLSOIDCpytestDocker Compose