|
|
||
|---|---|---|
| docs | ||
| src | ||
| .dockerignore | ||
| .env.example | ||
| .gitignore | ||
| API_DOCUMENTATION.md | ||
| Dockerfile | ||
| README.md | ||
| docker-compose.yml | ||
| errors.txt | ||
| fix-paths.js | ||
| package-lock.json | ||
| package.json | ||
| tsconfig.json | ||
| tsoa.json | ||
README.md
Gem Track Backend Starter
This repository is scaffolded as a production-ready modular monolith using:
- Node.js
- TypeScript
- Express
- TypeORM
- TSOA
- Swagger UI
Architecture Goals
- Clean Architecture + Domain Driven Design
- Strict separation of
domain,application,infrastructure, andinterfaces - Multi-tenant SaaS readiness
- Scalability through bounded contexts
- Swagger/OpenAPI documentation via TSOA
Folder Structure
src/
bootstrap/ # Composition root and dependency wiring
main.ts # Process startup and graceful shutdown
app.ts # Express application assembly
shared/
domain/ # Pure business abstractions
application/ # Cross-cutting use-case ports/contracts
infrastructure/ # DB, security, logging, config, messaging
interfaces/http/ # Middleware, presenters, TSOA, Swagger
modules/
tenancy/
domain/ # Aggregate, repository contract, events
application/ # Commands, queries, DTOs, handlers
infrastructure/ # TypeORM entity, mapper, repository impl
interfaces/http/controllers/ # TSOA controllers
types/ # Framework type augmentation
Dependency Flow
Dependencies always point inward:
interfaces -> application -> domain
infrastructure implements ports defined by application or contracts defined by domain.
Rules:
domaindoes not import Express, TSOA, TypeORM, or database code.applicationorchestrates use cases and depends only on domain contracts and abstract ports.interfacesis transport-only and should never hold business rules.repositoriesreturn domain aggregates, not ORM entities.TypeORM entitiesstay in infrastructure and are mapped to/from domain aggregates.
Multi-Tenant Strategy
The scaffold is built around a tenant-aware request context:
tenant.middlewareresolves tenant from headers, subdomain, or request metadata.TenantContextflows from the HTTP edge into application and infrastructure.tenant-data-source.resolver.tscentralizes tenancy-aware database access.- Shared-schema is the default mode, but the resolver is intentionally shaped so you can grow into schema-per-tenant or database-per-tenant.
Swagger
Swagger is exposed from:
GET /docsGET /swagger.json
TSOA controller decorators are used for OpenAPI generation, and the generated artifacts are written to:
src/shared/interfaces/http/tsoa/generated/routes.tssrc/shared/interfaces/http/tsoa/generated/swagger.json
The repository also includes starter generated files so the scaffold is understandable before running code generation.
Sample Module
The included tenancy bounded context demonstrates:
- Domain aggregate with business invariants
- Application command/query handlers
- Repository contract in the domain layer
- TypeORM repository implementation in infrastructure
- TSOA controller in interfaces
Suggested Next Steps
- Install dependencies with
npm install. - Generate TSOA artifacts with
npm run tsoa:spec && npm run tsoa:routes. - Extend
modules/with bounded contexts such asidentity-access,catalog,billing, andorders. - Add migrations, outbox processing, authentication policies, and integration tests.