Skip to content

Drop-in Multi-Tenancy for Node.js

Tenant hierarchy with config inheritance, permission delegation, and three isolation strategies. Start with flat tenancy, grow into hierarchy as your product matures.
Tenant hierarchy
  1. d0AcmeSecroot tenant
  2. d1NorthStar MSPchild tenant

max_users: 1000inherited from d0

NorthStar MSP sets no value for max_users, so it resolves the value from its parent. The quick example builds this tree.

# Direct library (no HTTP overhead)
npm install @stratum-hq/lib pg
# Or use the SDK with Express/Fastify middleware
npm install @stratum-hq/sdk
import { Pool } from "pg";
import { Stratum } from "@stratum-hq/lib";
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
const stratum = new Stratum({ pool });
// Create a root tenant
const root = await stratum.createTenant({
name: "AcmeSec",
slug: "acmesec",
isolation_strategy: "SHARED_RLS",
});
// Create a child tenant
const msp = await stratum.createTenant({
name: "NorthStar MSP",
slug: "northstar_msp",
parent_id: root.id,
});
// Config with inheritance
await stratum.setConfig(root.id, "max_users", { value: 1000, locked: false });
const config = await stratum.resolveConfig(msp.id);
// { max_users: { value: 1000, inherited: true, source_tenant_id: root.id } }
  • Tenant hierarchies. Model tenants as a tree using PostgreSQL ltree. Parent-child relationships with efficient subtree queries, ancestor resolution, and cycle-safe moves.
  • Config inheritance. Config values flow root-to-leaf. Children inherit parent values unless they override. Parents can lock keys to prevent any descendant from changing them. Sensitive values are encrypted with AES-256-GCM.
  • Permission delegation. Three delegation modes: LOCKED (immutable), INHERITED (overridable), and DELEGATED (re-delegatable). Revocation controls blast radius with CASCADE, SOFT, or PERMANENT semantics.
  • Three isolation strategies. Choose per-tenant: Shared RLS (row-level security), Schema-per-Tenant (logical separation), or Database-per-Tenant (maximum isolation). Mix strategies within the same hierarchy.
  • Two integration paths. Embed @stratum-hq/lib directly for zero-HTTP-overhead performance, or run the control plane as a service and use @stratum-hq/sdk with Express/Fastify middleware.
  • Built-in compliance. GDPR data export (Article 20), hard-purge (Article 17), consent tracking with purpose and expiration, audit logging with before/after state, and multi-region data residency.

For the direct library, install @stratum-hq/lib and pg. @stratum-hq/core comes with @stratum-hq/lib as a dependency.

Package Description
@stratum-hq/lib Direct library: embed in Node.js with no HTTP
@stratum-hq/core Shared types, Zod schemas, error classes, constants. Installed with @stratum-hq/lib
Package Description
@stratum-hq/sdk HTTP client, LRU cache, Express/Fastify middleware
@stratum-hq/db-adapters PostgreSQL adapters: raw pg, Prisma, Sequelize, Drizzle
@stratum-hq/mongodb MongoDB tenant isolation: shared collection, collection-per-tenant, database-per-tenant
@stratum-hq/mysql MySQL tenant isolation: shared table, table-per-tenant, database-per-tenant + TypeORM, Knex, Sequelize
@stratum-hq/nestjs NestJS integration: guard, @Tenant() decorator, DI module
@stratum-hq/hono Hono middleware: tenant extraction, ALS context
@stratum-hq/test-utils Cross-tenant isolation test helpers
@stratum-hq/compliance Compliance kernel: coverage scoring, finding state machine, control types
@stratum-hq/create Project scaffolding: npx @stratum-hq/create my-app
@stratum-hq/cli Project init, DB migration, framework scaffolding
@stratum-hq/react React provider, tenant tree, config/permission editors