How sensitiky/nest-microservices-boilerplate works
Project Type and Purpose
• This is a NestJS‑based microservices boilerplate that implements a hexagonal (ports & adapters) architecture.
• It provides four discrete services—Gateway, Auth, User, Product—plus shared libraries (Common, Config) to handle cross‑cutting concerns like DTOs, entities, database connection, guards, and interceptors.
High‑Level File Structure Analysis
• apps/
• gateway/ (API Gateway)
• auth/ (Authentication service)
• user/ (User management service)
• product/ (Product management service)
• libs/
• common/ (shared DTOs & entities)
• config/ (database modules, guards, interceptors)
• docker-compose.yml & docker‑scripts/ (container orchestration & multi‑DB setup)
• Root configs: nest‑cli.json, tsconfig.*, package.json
Key Insights from README
• Each microservice follows the hexagonal pattern with three layers:
• Domain: entities, port interfaces (repositories, service interfaces)
• Application: implements use‑cases via domain ports
• Infrastructure: NestJS controllers, ORM entity definitions, repository implementations
• Gateway routes incoming HTTP requests to the appropriate microservice.
• Shared libs hold common DTOs/entities and global configuration (DB connection, guards, interceptors).
a. Main Components
• Clients (Browser, Mobile App, CLI)
• API Gateway (apps/gateway)
• Microservices: Auth, User, Product (apps/auth, apps/user, apps/product)
• Databases: one PostgreSQL instance hosting multiple schemas/DBs (per microservice)
• Shared Libraries: Common, Config
• Docker Compose / Container Network
b. Relationships & Interactions
1. Clients → HTTP → API Gateway
2. API Gateway → (HTTP or TCP RPC) → Auth/User/Product services
3. Each microservice → ORM → its own PostgreSQL schema/DB
4. All services import libs/common and libs/config modules at compile time
5. Docker Compose orchestrates network links among containers
c. Architectural Patterns & Principles
• Hexagonal Architecture within each microservice (Ports & Adapters)
• Microservices pattern: independently deployable, scoped by business domain
• API Gateway pattern: central routing, composition of downstream services
• Shared‑library pattern: avoid duplication for DTOs, entities, and common config
d. Core Technologies & Frameworks
• NestJS (framework)
• TypeScript (language)
• Bun or Node.js (runtime)
• PostgreSQL (relational database)
• Docker & Docker Compose (containerization)
• Scripts to create multiple DBs (docker‑scripts/create‑multiple‑postgresql‑databases.sh)
Diagramming Conventions
• Gray for shared libraries
• Rectangles for services/components
• Rounded rectangles for libraries/modules