@stratum-hq/cli
@stratum-hq/cli helps you integrate Stratum into existing projects. It detects your framework, generates boilerplate, manages database migrations, and scaffolds framework-specific code.
Installation
npm install -g @stratum-hq/cli
# Or use directly without installing:npx @stratum-hq/cli <command>Commands
stratum init
Interactive project setup wizard:
stratum initWhat it does:
- Detects your framework and ORM from
package.json(Express, Fastify, Next.js, Prisma, etc.) - Asks: direct library (
@stratum-hq/lib) or HTTP API + SDK (@stratum-hq/sdk)? - Generates config file, middleware/plugin, database setup,
.envtemplate - If React is detected, generates provider, tenant guard components, and custom hooks
- Prints install instructions for required packages
stratum health
Validate your database is ready for Stratum:
stratum healthstratum health --database-url postgres://user:pass@host:5432/mydbChecks:
- Database connectivity
- PostgreSQL version (16+ recommended, 14+ required)
- Required extensions:
uuid-osspandltree - BYPASSRLS privilege (must be disabled for the application role)
- Stratum schema tables (tenants, config_entries, etc.)
- RLS status on all user tables
stratum migrate
Add tenant isolation to existing database tables:
# Scan all tables and show RLS statusstratum migrate --scan
# Migrate a specific tablestratum migrate orders
# Migrate all unmigrated tables interactivelystratum migrate --allFor each table, migration:
- Adds
tenant_id UUID NOT NULLcolumn - Enables
ROW LEVEL SECURITY+FORCE ROW LEVEL SECURITY - Creates
tenant_isolationpolicy - Creates index on
tenant_id - Adds foreign key to
tenantstable (if it exists)
stratum generate api-key
Generate an API key from the command line:
stratum generate api-key --name "my-service"stratum generate api-key --name "admin" --tenant <tenant-uuid>The plaintext key is displayed once and never stored.
stratum scaffold
Generate framework-specific integration boilerplate without the full init wizard:
stratum scaffold express # Express middleware + routesstratum scaffold fastify # Fastify pluginstratum scaffold nextjs # Next.js middleware + API helpers + layoutstratum scaffold react # React provider + guards + hooksstratum scaffold prisma # Tenant-scoped Prisma clientstratum scaffold docker # Docker Compose for Stratum + PostgreSQLstratum scaffold env # .env template with all variablesscaffold express
Generates:
stratum-middleware.ts— SDK client +expressMiddlewaresetuptenant-routes.ts— example routes usingreq.tenant
scaffold fastify
Generates:
stratum-plugin.ts— SDK client +fastifyPluginsetup
scaffold nextjs
Generates:
middleware.ts— Edge middleware for tenant resolution (subdomain, header, or path)lib/stratum.ts— server-side helpers for API routes and Server Componentscomponents/tenant-layout.tsx— client component withStratumProvider
scaffold react
Generates:
stratum-provider.tsx—AppStratumProviderwrappertenant-guard.tsx—PermissionGuardandConfigGuardcomponentsuse-tenant.ts—usePermission(),useConfig(),useIsRootTenant()hooks
scaffold prisma
Generates:
stratum-prisma.ts— tenant-scoped Prisma client using@stratum-hq/db-adapters
scaffold docker
Generates:
docker-compose.stratum.yml— PostgreSQL + control plane services
scaffold env
Generates:
.env.stratum— all Stratum environment variables with defaults and descriptions
Global Options
| Flag | Description |
|---|---|
--database-url, -d | PostgreSQL connection string |
--name | Name for generated API key |
--tenant | Tenant ID for generated API key |
--out | Output directory for scaffolded files |
--force | Overwrite existing files |
--help, -h | Show help |
--version, -v | Show version |
Examples
# Initialize a new Express + Prisma projectnpx @stratum-hq/cli init
# Check database readinessnpx @stratum-hq/cli health -d postgres://user:pass@localhost/mydb
# Add RLS to your orders tablenpx @stratum-hq/cli migrate orders
# Scaffold React components into src/componentsnpx @stratum-hq/cli scaffold react --out src/components
# Generate a tenant-scoped API keynpx @stratum-hq/cli generate api-key --name "web-app" --tenant abc123