Skip to content

Quick Start

Get from zero to working multi-tenancy in 30 seconds. All you need is a PostgreSQL connection string.

1. Install

Terminal window
npm install @stratum-hq/lib pg

2. Start PostgreSQL

If you cloned the Stratum repo, one command gives you a ready-to-use database with uuid-ossp and ltree pre-loaded:

Terminal window
docker compose up db -d

Connection string: postgres://stratum:stratum_dev@localhost:5432/stratum

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 tenant
const tenant = await stratum.createTenant({
name: "Acme Corp",
slug: "acme",
});
// Set a config value
await stratum.setConfig(tenant.id, "theme", { value: "dark" });
// Read it back
const 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 databaseFlat tenancy with RLS
Use Prisma with Row-Level SecurityPrisma + PostgreSQL RLS
Use Drizzle ORM with tenant isolationDrizzle ORM multi-tenancy
Build a multi-tenant Next.js appNext.js multi-tenant SaaS
Build a multi-tenant Express APIExpress API with RLS
Model MSSPs, MSPs, and end-clients as a treeTenant hierarchy
Inherit config down a hierarchyConfig inheritance
Delegate permissions between tenantsPermission delegation
Add Stratum to Express / Next.js / FastifyPackages — SDK
Understand the full data modelConcepts