How amanxchaubey/multi-tenant-saas works
Ledger is a multi-tenant B2B SaaS API. Its main workflow resolves an organization, authenticates a user, applies role checks, and serves organization, project, task, or billing operations; PostgreSQL RLS enforces tenant isolation. Authentication also covers organization selection, token renewal, email verification, and password recovery. The README documents Redis caching, optional RabbitMQ, Stripe billing, and Sentry; the sampled source does not show every service’s internal wiring.
Main entry points: app.js Express API · organization.routes.js Organization routes · auth.service.js Auth service · billing.controller.js Billing API
Components 31
API and access
- Express API
src/app.js - Tenant resolver
src/middleware/tenant.js - Access auth
src/middleware/auth.js - Role checks
src/middleware/authorize.js
Identity
- Auth routes
src/modules/auth/auth.routes.js - Auth API
src/modules/auth/auth.controller.js - Auth service
src/modules/auth/auth.service.js
Workspace data
- Organization routes
src/modules/organizations/organization.routes.js - Organization API
src/modules/organizations/organization.controller.js - Organization service
src/modules/organizations/organization.service.js - Project routes
src/modules/projects/project.routes.js - Project API
src/modules/projects/project.controller.js - Project service
src/modules/projects/project.service.js - Task routes
src/modules/tasks/task.routes.js - Task API
src/modules/tasks/task.controller.js - Task service
src/modules/tasks/task.service.js - Database access
src/config/db.js - PostgreSQL with RLS
- RLS schema
database/migrations/002_tasks_and_rls.sql
External services
- Redis client
src/config/redis.js - Redis cache
- Email delivery
src/lib/email.js - Resend
- Billing API
src/modules/billing/billing.controller.js - Billing service
src/modules/billing/billing.service.js - Stripe client
src/config/stripe.js - Stripe
- Sentry reporting
src/config/sentry.js - RabbitMQ client
src/config/rabbitmq.js - RabbitMQ
Other components
- Client
Connections 31
- Client → Express API: sends requests
- Express API → Tenant resolver: resolves tenant
- Express API → Access auth: authenticates requests
- Express API → Organization routes: routes requests
- Express API → Project routes: routes requests
- Express API → Task routes: routes requests
- Express API → Auth routes: routes requests
- Express API → Billing API: handles webhook
- Organization routes → Organization API: dispatches
- Project routes → Project API: dispatches
- Task routes → Task API: dispatches
- Auth routes → Auth API: dispatches
- Organization API → Organization service: calls
- Project API → Project service: calls
- Task API → Task service: calls
- Auth API → Auth service: calls
- Organization routes → Tenant resolver: resolves tenant
- Organization routes → Access auth: authenticates requests
- Organization routes → Role checks: checks roles
- Billing API → Billing service: calls
- Billing API → Stripe client: verifies webhook
- Auth service → Database access: queries
- Database access → PostgreSQL with RLS: reads and writes
- RLS schema → PostgreSQL with RLS: defines policies
- Auth service → Email delivery: sends mail
- Email delivery → Resend: delivers mail
- Tenant resolver → Redis client: looks up cached tenant
- Redis client → Redis cache: reads and writes
- Billing service → Stripe client: uses billing API
- Stripe client → Stripe: calls
- Express API → Sentry reporting: reports errors