How rasikjain/multi-tenant-org-team-roles-app works
Project type and purpose
• This is a backend API service (Node.js + TypeScript + Express) that provides a multi-tenant foundation for organizations, teams, role-based access control (RBAC), invites, and auditing. It exposes REST endpoints, stores data in Postgres via Drizzle ORM, and ships with OpenAPI/Swagger UI and a Postman collection for integration.
File structure
• Top-level:
• src/ – main application code
• scripts/ – DB seeding scripts
• drizzle/ – raw SQL migrations & metadata
• config files: .env.sample, drizzle.config.ts, tsconfig.json, vitest.config.ts
• src/ layers:
• src/server.ts – Express app setup and route mounting
• src/middleware/ – audit and auth middleware with tests
• src/auth/ – RBAC logic and tests
• src/routes/ – route handlers for orgs, teams, members, invites
• src/db/ – Drizzle client initialization and schema definitions
• src/utils/ and src/types/ – shared utilities and error types
README insights
• Multi-tenant boundary enforcement (org scope derived from route param and x-user-id header)
• Core domain: Orgs, Teams, Users, Memberships, Invites, Roles, Audit events
• Deployment/migration steps: drizzle:generate, drizzle:push, seed
• Testing with Vitest and coverage
a. Main components to include
• API Layer (Express server)
• Middleware Pipeline (Authentication → RBAC → Auditing)
• Route/Controller Modules (Orgs, Teams, Invites, Members)
• Service/Domain Layer (business logic, permission checks)
• Data Access Layer (Drizzle ORM client)
• Postgres Database (tables for orgs, teams, users, memberships, invites, audit logs)
• External Email Service (SMTP or 3rd-party) for invite delivery
• Documentation UI (Swagger UI serving docs/openapi.yaml)
• Clients/Consumers (CLI, Postman, frontend apps)
b. Relationships and interactions
• Client → HTTP → Express API
• API → middleware for auth & audit
• Route handlers invoke service methods → Drizzle client → Postgres
• On POST /invites: generate token → persist invite → email service call
• On invite acceptance: validate token → upsert user/memberships
• Swagger UI endpoint reads docs/openapi.yaml
c. Architectural patterns & principles
• Layered architecture: Presentation (Express/routes) → Middleware → Business logic → Data access
• Separation of concerns: auth, RBAC, auditing in middleware; domain logic in route modules
• Multi-tenant isolation: orgId scoping at middleware layer
• Idempotency and audit logging for mutating endpoints
• Migration-driven schema definition (Drizzle)
d. Key technologies/frameworks
• Node.js, TypeScript, Express
• Drizzle ORM + Postgres
• Vitest for testing
• Swagger/OpenAPI, Postman