# ayush30s/nest-microservices architecture

> Architecture diagram of the GitHub repository ayush30s/nest-microservices, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ayush30s/nest-microservices
- Repository: https://github.com/ayush30s/nest-microservices

## Overview

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: [`apps/api-gateway`](https://github.com/ayush30s/nest-microservices/tree/master/apps/api-gateway) (API Gateway), [`apps/auth-service`](https://github.com/ayush30s/nest-microservices/tree/master/apps/auth-service) (Auth Service), [`apps/user-service`](https://github.com/ayush30s/nest-microservices/tree/master/apps/user-service) (User Service), [`apps/gym-service`](https://github.com/ayush30s/nest-microservices/tree/master/apps/gym-service) (Gym Service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingress["Ingress"]
  node_api_gateway["API Gateway<br/>Nest gateway"]
  node_gateway_auth["Auth API<br/>Gateway module"]
  node_gateway_users["Users API<br/>Gateway module"]
  node_gateway_gym["Gym API<br/>Gateway module"]
  node_circuit_breaker(("Circuit Breaker<br/>gateway protection<br/>[circuitBreaker.ts]"))
end

subgraph group_services["Services"]
  node_auth_service["Auth Service<br/>Nest service"]
  node_auth_prisma[("Auth DB<br/>Prisma schema<br/>[schema.prisma]")]
  node_user_service["User Service<br/>Nest service"]
  node_user_prisma[("User DB<br/>Prisma schema<br/>[schema.prisma]")]
  node_gym_service["Gym Service<br/>Nest service"]
  node_gym_prisma[("Gym DB<br/>Prisma schema<br/>[schema.prisma]")]
  node_product_service["Product Service<br/>Nest service"]
end

subgraph group_shared["Shared"]
  node_shared_dto["DTO Contracts<br/>shared contracts"]
  node_shared_auth["JWT Auth<br/>shared security"]
  node_shared_aws["AWS Integration<br/>shared integration"]
  node_shared_errors(("Exception Filter<br/>shared error handling"))
end

subgraph group_ops["Ops"]
  node_deploy_workflow["Deploy Workflow<br/>CI/CD<br/>[deploy.yml]"]
  node_pm2_config["Process Config<br/>runtime config"]
end

node_api_gateway -->|"exposes"| node_gateway_auth
node_api_gateway -->|"exposes"| node_gateway_users
node_api_gateway -->|"exposes"| node_gateway_gym
node_gateway_auth -->|"uses"| node_circuit_breaker
node_gateway_users -->|"uses"| node_circuit_breaker
node_gateway_gym -->|"uses"| node_circuit_breaker
node_api_gateway -->|"routes to"| node_auth_service
node_api_gateway -->|"routes to"| node_user_service
node_api_gateway -->|"routes to"| node_gym_service
node_api_gateway -->|"routes to"| node_product_service
node_auth_service -->|"persists to"| node_auth_prisma
node_user_service -->|"persists to"| node_user_prisma
node_gym_service -->|"persists to"| node_gym_prisma
node_api_gateway -->|"shares contracts"| node_shared_dto
node_auth_service -->|"shares contracts"| node_shared_dto
node_user_service -->|"shares contracts"| node_shared_dto
node_gym_service -->|"shares contracts"| node_shared_dto
node_api_gateway -->|"guards with"| node_shared_auth
node_auth_service -->|"validates with"| node_shared_auth
node_user_service -->|"validates with"| node_shared_auth
node_gym_service -->|"validates with"| node_shared_auth
node_api_gateway -->|"handles errors"| node_shared_errors
node_auth_service -->|"handles errors"| node_shared_errors
node_user_service -->|"handles errors"| node_shared_errors
node_gym_service -->|"handles errors"| node_shared_errors
node_product_service -->|"handles errors"| node_shared_errors
node_api_gateway -.->|"integrates with"| node_shared_aws
node_auth_service -.->|"integrates with"| node_shared_aws
node_user_service -.->|"integrates with"| node_shared_aws
node_gym_service -.->|"integrates with"| node_shared_aws
node_deploy_workflow -->|"deploys"| node_api_gateway
node_deploy_workflow -->|"deploys"| node_auth_service
node_deploy_workflow -->|"deploys"| node_user_service
node_deploy_workflow -->|"deploys"| node_gym_service
node_deploy_workflow -->|"deploys"| node_product_service
node_pm2_config -.->|"runs"| node_api_gateway
node_pm2_config -.->|"runs"| node_auth_service
node_pm2_config -.->|"runs"| node_user_service
node_pm2_config -.->|"runs"| node_gym_service
node_pm2_config -.->|"runs"| node_product_service

click node_api_gateway "https://github.com/ayush30s/nest-microservices/tree/master/apps/api-gateway"
click node_gateway_auth "https://github.com/ayush30s/nest-microservices/tree/master/apps/api-gateway/src/auth"
click node_gateway_users "https://github.com/ayush30s/nest-microservices/tree/master/apps/api-gateway/src/users"
click node_gateway_gym "https://github.com/ayush30s/nest-microservices/tree/master/apps/api-gateway/src/gym"
click node_circuit_breaker "https://github.com/ayush30s/nest-microservices/blob/master/apps/api-gateway/src/common/circuitBreaker.ts"
click node_auth_service "https://github.com/ayush30s/nest-microservices/tree/master/apps/auth-service"
click node_auth_prisma "https://github.com/ayush30s/nest-microservices/blob/master/apps/auth-service/prisma/schema.prisma"
click node_user_service "https://github.com/ayush30s/nest-microservices/tree/master/apps/user-service"
click node_user_prisma "https://github.com/ayush30s/nest-microservices/blob/master/apps/user-service/prisma/schema.prisma"
click node_gym_service "https://github.com/ayush30s/nest-microservices/tree/master/apps/gym-service"
click node_gym_prisma "https://github.com/ayush30s/nest-microservices/blob/master/apps/gym-service/prisma/schema.prisma"
click node_product_service "https://github.com/ayush30s/nest-microservices/tree/master/apps/product-service"
click node_shared_dto "https://github.com/ayush30s/nest-microservices/tree/master/libs/common/DTO"
click node_shared_auth "https://github.com/ayush30s/nest-microservices/tree/master/libs/common/auth"
click node_shared_aws "https://github.com/ayush30s/nest-microservices/tree/master/libs/common/aws"
click node_shared_errors "https://github.com/ayush30s/nest-microservices/blob/master/libs/common/exception-filter.ts"
click node_deploy_workflow "https://github.com/ayush30s/nest-microservices/blob/master/.github/workflows/deploy.yml"
click node_pm2_config "https://github.com/ayush30s/nest-microservices/blob/master/ecosystem.config.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api_gateway,node_gateway_auth,node_gateway_users,node_gateway_gym,node_circuit_breaker toneBlue
class node_auth_service,node_auth_prisma,node_user_service,node_user_prisma,node_gym_service,node_gym_prisma,node_product_service toneAmber
class node_shared_dto,node_shared_auth,node_shared_aws,node_shared_errors toneMint
class node_deploy_workflow,node_pm2_config toneRose
```

## Components

### Ingress

Client-facing entry point and request orchestration

- [API Gateway](https://github.com/ayush30s/nest-microservices/tree/master/apps/api-gateway): Nest gateway · Main ingress that routes auth, users, and gym requests · `apps/api-gateway`
- [Auth API](https://github.com/ayush30s/nest-microservices/tree/master/apps/api-gateway/src/auth): Gateway module · Gateway auth endpoints and orchestration · `apps/api-gateway/src/auth`
- [Users API](https://github.com/ayush30s/nest-microservices/tree/master/apps/api-gateway/src/users): Gateway module · Gateway users endpoints and orchestration · `apps/api-gateway/src/users`
- [Gym API](https://github.com/ayush30s/nest-microservices/tree/master/apps/api-gateway/src/gym): Gateway module · Gateway gym endpoints and orchestration · `apps/api-gateway/src/gym`
- [Circuit Breaker](https://github.com/ayush30s/nest-microservices/blob/master/apps/api-gateway/src/common/circuitBreaker.ts): gateway protection · Failure protection for downstream calls · `apps/api-gateway/src/common/circuitBreaker.ts`

### Services

Independently runnable domain services

- [Auth Service](https://github.com/ayush30s/nest-microservices/tree/master/apps/auth-service): Nest service · Authentication bounded context · `apps/auth-service`
- [Auth DB](https://github.com/ayush30s/nest-microservices/blob/master/apps/auth-service/prisma/schema.prisma): Prisma schema · Service-owned persistence for auth · `apps/auth-service/prisma/schema.prisma`
- [User Service](https://github.com/ayush30s/nest-microservices/tree/master/apps/user-service): Nest service · User-domain bounded context · `apps/user-service`
- [User DB](https://github.com/ayush30s/nest-microservices/blob/master/apps/user-service/prisma/schema.prisma): Prisma schema · Service-owned persistence for users · `apps/user-service/prisma/schema.prisma`
- [Gym Service](https://github.com/ayush30s/nest-microservices/tree/master/apps/gym-service): Nest service · Gym-domain bounded context · `apps/gym-service`
- [Gym DB](https://github.com/ayush30s/nest-microservices/blob/master/apps/gym-service/prisma/schema.prisma): Prisma schema · Service-owned persistence for gyms · `apps/gym-service/prisma/schema.prisma`
- [Product Service](https://github.com/ayush30s/nest-microservices/tree/master/apps/product-service): Nest service · Standalone product service without Prisma in tree · `apps/product-service`

### Shared

Cross-cutting libraries reused across apps

- [DTO Contracts](https://github.com/ayush30s/nest-microservices/tree/master/libs/common/DTO): shared contracts · Shared auth, gym, and user request/response shapes · `libs/common/DTO`
- [JWT Auth](https://github.com/ayush30s/nest-microservices/tree/master/libs/common/auth): shared security · JWT guard and strategy used for protected flows · `libs/common/auth`
- [AWS Integration](https://github.com/ayush30s/nest-microservices/tree/master/libs/common/aws): shared integration · Reusable AWS module, service, and controller · `libs/common/aws`
- [Exception Filter](https://github.com/ayush30s/nest-microservices/blob/master/libs/common/exception-filter.ts): shared error handling · Centralized exception translation and formatting · `libs/common/exception-filter.ts`

### Ops

Deployment and runtime tooling

- [Deploy Workflow](https://github.com/ayush30s/nest-microservices/blob/master/.github/workflows/deploy.yml): CI/CD · Automated deployment pipeline · `.github/workflows/deploy.yml`
- [Process Config](https://github.com/ayush30s/nest-microservices/blob/master/ecosystem.config.js): runtime config · Process manager configuration for deployed services · `ecosystem.config.js`

## Connections

- 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
