Quick Start
Get from zero to working multi-tenancy in 30 seconds. All you need is a PostgreSQL connection string.
1. Install
npm install @stratum-hq/lib pg2. Start PostgreSQL
If you cloned the Stratum repo, one command gives you a ready-to-use
database with uuid-ossp and ltree pre-loaded:
docker compose up db -dConnection string: postgres://stratum:stratum_dev@localhost:5432/stratum
docker run -d --name stratum-db \ -e POSTGRES_USER=stratum \ -e POSTGRES_PASSWORD=stratum_dev \ -e POSTGRES_DB=stratum \ -p 5432:5432 postgres:16Then enable extensions:
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";CREATE EXTENSION IF NOT EXISTS "ltree";Enable the required extensions in your database:
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";CREATE EXTENSION IF NOT EXISTS "ltree";3. Create your first tenant
The simplest setup: a single tenant with autoMigrate so Stratum creates
its tables on first run.
import { Pool } from "pg";import { Stratum } from "@stratum-hq/lib";
const pool = new Pool({ connectionString: "postgres://stratum:stratum_dev@localhost:5432/stratum",});
const stratum = new Stratum({ pool, autoMigrate: true });await stratum.initialize();
// Create a root tenantconst tenant = await stratum.createTenant({ name: "Acme Corp", slug: "acme",});
// Set a config valueawait stratum.setConfig(tenant.id, "theme", { value: "dark" });
// Read it backconst config = await stratum.resolveConfig(tenant.id);console.log(config.theme.value); // "dark"That’s it. autoMigrate: true handles schema setup automatically — no CLI
or migration step required to get started.
What’s next
The example above uses a single flat tenant. Most real apps need either multi-tenant isolation or a parent/child hierarchy. Pick your path:
| I want to… | Guide |
|---|---|
| Isolate multiple customers in one database | Flat tenancy with RLS |
| Use Prisma with Row-Level Security | Prisma + PostgreSQL RLS |
| Use Drizzle ORM with tenant isolation | Drizzle ORM multi-tenancy |
| Build a multi-tenant Next.js app | Next.js multi-tenant SaaS |
| Build a multi-tenant Express API | Express API with RLS |
| Model MSSPs, MSPs, and end-clients as a tree | Tenant hierarchy |
| Inherit config down a hierarchy | Config inheritance |
| Delegate permissions between tenants | Permission delegation |
| Add Stratum to Express / Next.js / Fastify | Packages — SDK |
| Understand the full data model | Concepts |