Skip to content

Quick Start

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

Terminal window
npm install @stratum-hq/lib pg

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

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.

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