How ayush30s/nest-microservices works
1. Overall shape
- This is a NestJS/TypeScript monorepo organized as a small microservice system.
- There is one API gateway plus several independently runnable backend services, with shared libraries under libs/common.
2. Edge entry point
- apps/api-gateway is the main request ingress.
- It is split into auth, users, and gym modules, with a common/circuitBreaker.ts, which suggests the gateway routes requests to downstream services and protects those calls from failure cascades.
3. Domain services
- apps/auth-service, apps/user-service, and apps/gym-service each follow the same Nest service pattern: main.ts, *.module.ts, *.controller.ts, *.service.ts.
- apps/product-service is a separate service with the same Nest structure, but no Prisma layer is present in the tree.
4. Service boundaries
- The repository is split by bounded context:
- Auth handles authentication concerns.
- User handles user-domain data.
- Gym handles gym-domain data.
- Product is its own independent service.
- The gateway likely composes these domains into a single client-facing API.
5. Data persistence
- auth-service, user-service, and gym-service each contain a Prisma schema and migration history.
- That strongly indicates service-owned databases/schemas rather than one shared database.
- prisma.config.ts in each of those services reinforces that the database layer is managed per service.
6. Cross-cutting shared code
- libs/common/DTO contains shared request/response contracts for auth, gym, and user flows.
- libs/common/auth includes a JWT auth guard and JWT strategy, indicating token-based authentication is a shared concern across the system.
- libs/common/exception-filter.ts centralizes error handling behavior.
7. External integration layer
- libs/common/aws provides an AWS module/service/controller, which suggests one cross-cutting integration with AWS-managed resources.
- Because it is packaged as shared code, AWS access is likely reused by multiple services rather than implemented ad hoc in each app.
8. Likely request flow
- A typical flow is: client → API gateway → domain service → service database.
- Authenticated requests likely pass through the shared JWT guard/strategy boundary before reaching protected gateway routes or downstream services.
9. Runtime and tooling
- The repo is built around NestJS, Node.js, TypeScript, and Prisma.
- Root-level config files (nest-cli.json, tsconfig*.json, ESLint, Prettier) indicate a single coordinated build/lint toolchain across the monorepo.
10. Operational/deployment signals
- .github/workflows/deploy.yml indicates automated CI/CD deployment.
- ecosystem.config.js suggests the services are also designed to be run under a process manager such as PM2 in deployed environments.
11. Testing
- apps/product-service/test/app.e2e-spec.ts and test/jest-e2e.json show at least one service has end-to-end test coverage.
- The root test/ directory suggests the repository also retains the default Nest app test scaffold.
12. Diagram takeaway
- The clean architecture picture is: gateway at the front, multiple domain services behind it, shared auth/DTO/AWS libraries in the middle, and separate Prisma-backed persistence inside selected services.
- The most important boundaries to draw are gateway vs. services, shared libraries vs. service-specific code, and service-owned databases.
Main entry points: api-gateway API Gateway · auth-service Auth Service · user-service User Service · gym-service Gym Service
Components 18
Ingress
Client-facing entry point and request orchestration
- API Gateway · Main ingress that routes auth, users, and gym requests
apps/api-gateway - Auth API · Gateway auth endpoints and orchestration
apps/api-gateway/src/auth - Users API · Gateway users endpoints and orchestration
apps/api-gateway/src/users - Gym API · Gateway gym endpoints and orchestration
apps/api-gateway/src/gym - Circuit Breaker · Failure protection for downstream calls
apps/api-gateway/src/common/circuitBreaker.ts
Services
Independently runnable domain services
- Auth Service · Authentication bounded context
apps/auth-service - Auth DB · Service-owned persistence for auth
apps/auth-service/prisma/schema.prisma - User Service · User-domain bounded context
apps/user-service - User DB · Service-owned persistence for users
apps/user-service/prisma/schema.prisma - Gym Service · Gym-domain bounded context
apps/gym-service - Gym DB · Service-owned persistence for gyms
apps/gym-service/prisma/schema.prisma - Product Service · Standalone product service without Prisma in tree
apps/product-service
Shared
Cross-cutting libraries reused across apps
- DTO Contracts · Shared auth, gym, and user request/response shapes
libs/common/DTO - JWT Auth · JWT guard and strategy used for protected flows
libs/common/auth - AWS Integration · Reusable AWS module, service, and controller
libs/common/aws - Exception Filter · Centralized exception translation and formatting
libs/common/exception-filter.ts
Ops
Deployment and runtime tooling
- Deploy Workflow · Automated deployment pipeline
.github/workflows/deploy.yml - Process Config · Process manager configuration for deployed services
ecosystem.config.js
Connections 40
- API Gateway → Auth API: exposes · Gateway splits into auth routes
- API Gateway → Users API: exposes · Gateway splits into users routes
- API Gateway → Gym API: exposes · Gateway splits into gym routes
- Auth API → Circuit Breaker: uses · Protects downstream auth calls
- Users API → Circuit Breaker: uses · Protects downstream users calls
- Gym API → Circuit Breaker: uses · Protects downstream gym calls
- API Gateway → Auth Service: routes to · Gateway forwards auth traffic
- API Gateway → User Service: routes to · Gateway forwards user traffic
- API Gateway → Gym Service: routes to · Gateway forwards gym traffic
- API Gateway → Product Service: routes to · Client-facing access to product service
- Auth Service → Auth DB: persists to · Auth service owns its database schema
- User Service → User DB: persists to · User service owns its database schema
- Gym Service → Gym DB: persists to · Gym service owns its database schema
- API Gateway → DTO Contracts: shares contracts · Gateway uses shared request/response DTOs
- Auth Service → DTO Contracts: shares contracts · Auth service uses shared DTOs
- User Service → DTO Contracts: shares contracts · User service uses shared DTOs
- Gym Service → DTO Contracts: shares contracts · Gym service uses shared DTOs
- API Gateway → JWT Auth: guards with · Gateway protected routes rely on JWT auth
- Auth Service → JWT Auth: validates with · Auth service participates in JWT-based auth
- User Service → JWT Auth: validates with · User service participates in JWT-based auth
- Gym Service → JWT Auth: validates with · Gym service participates in JWT-based auth
- API Gateway → Exception Filter: handles errors · Gateway uses centralized exception handling
- Auth Service → Exception Filter: handles errors · Auth service uses centralized exception handling
- User Service → Exception Filter: handles errors · User service uses centralized exception handling
- Gym Service → Exception Filter: handles errors · Gym service uses centralized exception handling
- Product Service → Exception Filter: handles errors · Product service uses centralized exception handling
- API Gateway → AWS Integration: integrates with · Gateway can reuse shared AWS integration
- Auth Service → AWS Integration: integrates with · Services may reuse shared AWS integration
- User Service → AWS Integration: integrates with · Services may reuse shared AWS integration
- Gym Service → AWS Integration: integrates with · Services may reuse shared AWS integration
- Deploy Workflow → API Gateway: deploys · CI/CD covers the gateway
- Deploy Workflow → Auth Service: deploys · CI/CD covers auth service
- Deploy Workflow → User Service: deploys · CI/CD covers user service
- Deploy Workflow → Gym Service: deploys · CI/CD covers gym service
- Deploy Workflow → Product Service: deploys · CI/CD covers product service
- Process Config → API Gateway: runs · Process manager can host the gateway
- Process Config → Auth Service: runs · Process manager can host auth service
- Process Config → User Service: runs · Process manager can host user service
- Process Config → Gym Service: runs · Process manager can host gym service
- Process Config → Product Service: runs · Process manager can host product service