Skip to content

Orders App (Sequelize + Express)

End-to-end demo: 3 tenants on separate Postgres databases, resolved by subdomain.

Source: examples/sequelize-express/


What it covers

FeatureWhere
Subdomain-based tenant resolutionserver.tsSubdomainResolver
Per-tenant Sequelize instanceregistry.tsSequelizeAdapter
Model registrationregistry.registerModels([OrderModel])
useTenant() in handlersserver.ts routes
onCreate hook (schema sync)registry.ts hooks
Tenant provisioningprovision.ts
Connection cache statsGET /health

Running it

bash
# 1 — start four Postgres containers (master + 3 tenant DBs)
docker-compose up -d

# 2 — install dependencies (from repo root)
pnpm install

# 3 — create tenant rows and sync schemas
pnpm provision

# 4 — start the server
pnpm start

Try it

The server reads the tenant from the request subdomain.

bash
# Tenant "acme"
curl -H "Host: acme.localhost" http://localhost:3000/
curl -H "Host: acme.localhost" http://localhost:3000/orders

# Create an order
curl -H "Host: acme.localhost" -X POST http://localhost:3000/orders \
  -H "Content-Type: application/json" \
  -d '{"product":"Widget","quantity":2,"total":"19.99"}'

# Tenant "globex" — completely separate database
curl -H "Host: globex.localhost" http://localhost:3000/orders

# Health / cache stats
curl http://localhost:3000/health

Ports

ServicePort
master DB5432
acme DB5433
globex DB5434
initech DB5435
HTTP server3000

Released under the MIT License.