# aditya18mew/api-gateway architecture

> Architecture diagram of the GitHub repository aditya18mew/api-gateway, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aditya18mew/api-gateway
- Repository: https://github.com/aditya18mew/api-gateway

## Overview

1. This repository is a small Node.js microservices system built around an API gateway plus three domain services: Auth, User, and Product. The top-level `compose.yaml` suggests the whole stack is intended to run together locally with container orchestration.

2. The `gateway/` service is the public entrypoint. It contains route wiring, shared middleware, service discovery/configuration, and a `public/docs.html` page for API documentation or a basic UI for testing. In architecture terms, this is the only component clients should talk to directly.

3. The gateway also hosts the main cross-cutting controls: `Authmiddleware`, `ratelimiter`, `circuitbreaker`, and `logger`. That means authentication/authorization, traffic shaping, resilience, and request logging are enforced before requests are forwarded to downstream services.

4. The `gateway/config/services.js` and `gateway/config/Redis.js` files indicate the gateway knows where the downstream services live and uses Redis for shared state. Redis is likely supporting rate limiting and/or circuit breaker state rather than business data.

5. `services/Auth-service/` is the credential and token boundary. Its utilities include `bcrypt.js` and `generatejwt.js`, which strongly suggests this service hashes passwords and issues JWTs. Its routes are isolated from the rest of the system, so login/registration/token flows stay separate from domain data services.

6. `services/user-service/` and `services/product-service/` are the domain backends. Each has its own `index.js`, `routes/`, `config/`, and `utils/mongoosedb.js`, which implies each service owns its own HTTP API and its own MongoDB connection setup.

7. The presence of `mongoosedb.js` in all three services points to a MongoDB-backed design, with persistence localized inside each service rather than through a shared database access layer. That keeps the service boundaries clear for an architecture diagram: each service is independently deployable and data-owning.

8. Request flow is therefore: client → gateway → appropriate service. For protected endpoints, the gateway authenticates the request first, then forwards it. For auth flows, the client likely hits the auth service through the gateway to obtain a JWT, which is then reused on later requests.

9. Operationally, `compose.yaml`, `.env.example` files in each service, and per-service `config/` folders show the system is environment-driven. Ports, backend URLs, Redis, and database settings are intended to be injected at runtime rather than hardcoded.

10. There is little evidence of shared business logic across services; the main shared concerns live in the gateway, while domain logic is siloed per service. For an architecture diagram, the important boundaries are: external clients, gateway, Redis for shared control-state, and the three isolated HTTP + Mongo-backed services.

Main entry points: [`gateway/index.js`](https://github.com/aditya18mew/api-gateway/blob/main/gateway/index.js) (Gateway), [`services/Auth-service/index.js`](https://github.com/aditya18mew/api-gateway/blob/main/services/Auth-service/index.js) (Auth service), [`compose.yaml`](https://github.com/aditya18mew/api-gateway/blob/main/compose.yaml) (Compose), [`gateway/routes/routes.js`](https://github.com/aditya18mew/api-gateway/blob/main/gateway/routes/routes.js) (Routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g1["Gateway"]
  node_n3["Gateway<br/>[index.js]"]
  node_n4["Routes<br/>routing<br/>[routes.js]"]
  node_n5["Auth guard<br/>middleware<br/>[Authmiddleware.js]"]
  node_n6["Rate limit<br/>middleware<br/>[ratelimiter.js]"]
  node_n7["Circuit breaker<br/>middleware<br/>[circuitbreaker.js]"]
  node_n8["Logger<br/>middleware<br/>[logger.js]"]
  node_n9["Service config<br/>service map<br/>[services.js]"]
  node_n10["Redis config<br/>[Redis.js]"]
  node_n11["Docs UI<br/>[docs.html]"]
end

subgraph group_g2["Services"]
  node_n12["Auth service<br/>auth api<br/>[index.js]"]
  node_n13["Auth routes<br/>[routes.js]"]
  node_n14["JWT utils<br/>auth utils<br/>[generatejwt.js]"]
  node_n15[("Auth DB<br/>mongo connection<br/>[mongoosedb.js]")]
  node_n16["User service<br/>user api<br/>[index.js]"]
  node_n17[("User DB<br/>mongo connection<br/>[mongoosedb.js]")]
  node_n18["Product service<br/>product api<br/>[index.js]"]
  node_n19[("Product DB<br/>mongo connection<br/>[mongoosedb.js]")]
end

subgraph group_g3["Infra"]
  node_n2["Compose<br/>orchestration<br/>[compose.yaml]"]
end

node_n1(("Client<br/>external"))

node_n1 -->|"calls"| node_n3
node_n2 -->|"starts"| node_n3
node_n2 -->|"starts"| node_n12
node_n2 -->|"starts"| node_n16
node_n2 -->|"starts"| node_n18
node_n3 -->|"uses"| node_n4
node_n3 -->|"enforces"| node_n5
node_n3 -->|"enforces"| node_n6
node_n3 -->|"enforces"| node_n7
node_n3 -->|"uses"| node_n8
node_n3 -->|"reads"| node_n9
node_n3 -->|"connects"| node_n10
node_n3 -->|"serves"| node_n11
node_n4 -->|"forwards to"| node_n12
node_n4 -->|"forwards to"| node_n16
node_n4 -->|"forwards to"| node_n18
node_n12 -->|"exposes"| node_n13
node_n12 -->|"uses"| node_n14
node_n12 -->|"persists to"| node_n15
node_n16 -->|"persists to"| node_n17
node_n18 -->|"persists to"| node_n19

click node_n2 "https://github.com/aditya18mew/api-gateway/blob/main/compose.yaml"
click node_n3 "https://github.com/aditya18mew/api-gateway/blob/main/gateway/index.js"
click node_n4 "https://github.com/aditya18mew/api-gateway/blob/main/gateway/routes/routes.js"
click node_n5 "https://github.com/aditya18mew/api-gateway/blob/main/gateway/middleware/Authmiddleware.js"
click node_n6 "https://github.com/aditya18mew/api-gateway/blob/main/gateway/middleware/ratelimiter.js"
click node_n7 "https://github.com/aditya18mew/api-gateway/blob/main/gateway/middleware/circuitbreaker.js"
click node_n8 "https://github.com/aditya18mew/api-gateway/blob/main/gateway/middleware/logger.js"
click node_n9 "https://github.com/aditya18mew/api-gateway/blob/main/gateway/config/services.js"
click node_n10 "https://github.com/aditya18mew/api-gateway/blob/main/gateway/config/Redis.js"
click node_n11 "https://github.com/aditya18mew/api-gateway/blob/main/gateway/public/docs.html"
click node_n12 "https://github.com/aditya18mew/api-gateway/blob/main/services/Auth-service/index.js"
click node_n13 "https://github.com/aditya18mew/api-gateway/blob/main/services/Auth-service/routes/routes.js"
click node_n14 "https://github.com/aditya18mew/api-gateway/blob/main/services/Auth-service/utils/generatejwt.js"
click node_n15 "https://github.com/aditya18mew/api-gateway/blob/main/services/Auth-service/utils/mongoosedb.js"
click node_n16 "https://github.com/aditya18mew/api-gateway/blob/main/services/user-service/index.js"
click node_n17 "https://github.com/aditya18mew/api-gateway/blob/main/services/user-service/utils/mongoosedb.js"
click node_n18 "https://github.com/aditya18mew/api-gateway/blob/main/services/product-service/index.js"
click node_n19 "https://github.com/aditya18mew/api-gateway/blob/main/services/product-service/utils/mongoosedb.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_n3,node_n4,node_n5,node_n6,node_n7,node_n8,node_n9,node_n10,node_n11 toneBlue
class node_n12,node_n13,node_n14,node_n15,node_n16,node_n17,node_n18,node_n19 toneAmber
class node_n2 toneMint
class node_n1 toneNeutral
```

## Components

### Gateway

Public entrypoint and cross-cutting controls

- [Gateway](https://github.com/aditya18mew/api-gateway/blob/main/gateway/index.js): api gateway · Public HTTP entrypoint · `gateway/index.js`
- [Routes](https://github.com/aditya18mew/api-gateway/blob/main/gateway/routes/routes.js): routing · Request forwarding and endpoint wiring · `gateway/routes/routes.js`
- [Auth guard](https://github.com/aditya18mew/api-gateway/blob/main/gateway/middleware/Authmiddleware.js): middleware · Authentication and authorization checks · `gateway/middleware/Authmiddleware.js`
- [Rate limit](https://github.com/aditya18mew/api-gateway/blob/main/gateway/middleware/ratelimiter.js): middleware · Traffic shaping and throttling · `gateway/middleware/ratelimiter.js`
- [Circuit breaker](https://github.com/aditya18mew/api-gateway/blob/main/gateway/middleware/circuitbreaker.js): middleware · Resilience and downstream protection · `gateway/middleware/circuitbreaker.js`
- [Logger](https://github.com/aditya18mew/api-gateway/blob/main/gateway/middleware/logger.js): middleware · Request logging and observability · `gateway/middleware/logger.js`
- [Service config](https://github.com/aditya18mew/api-gateway/blob/main/gateway/config/services.js): service map · Downstream service locations · `gateway/config/services.js`
- [Redis config](https://github.com/aditya18mew/api-gateway/blob/main/gateway/config/Redis.js): redis config · Shared control-state backend settings · `gateway/config/Redis.js`
- [Docs UI](https://github.com/aditya18mew/api-gateway/blob/main/gateway/public/docs.html): docs · Public documentation and test page · `gateway/public/docs.html`

### Services

Domain services with isolated APIs and data

- [Auth service](https://github.com/aditya18mew/api-gateway/blob/main/services/Auth-service/index.js): auth api · Credentials and token boundary · `services/Auth-service/index.js`
- [Auth routes](https://github.com/aditya18mew/api-gateway/blob/main/services/Auth-service/routes/routes.js): routes · Login and token endpoints · `services/Auth-service/routes/routes.js`
- [JWT utils](https://github.com/aditya18mew/api-gateway/blob/main/services/Auth-service/utils/generatejwt.js): auth utils · Password hashing and token issuance · `services/Auth-service/utils/generatejwt.js`
- [Auth DB](https://github.com/aditya18mew/api-gateway/blob/main/services/Auth-service/utils/mongoosedb.js): mongo connection · Service-local persistence · `services/Auth-service/utils/mongoosedb.js`
- [User service](https://github.com/aditya18mew/api-gateway/blob/main/services/user-service/index.js): user api · User domain backend · `services/user-service/index.js`
- [User DB](https://github.com/aditya18mew/api-gateway/blob/main/services/user-service/utils/mongoosedb.js): mongo connection · Service-local persistence · `services/user-service/utils/mongoosedb.js`
- [Product service](https://github.com/aditya18mew/api-gateway/blob/main/services/product-service/index.js): product api · Product domain backend · `services/product-service/index.js`
- [Product DB](https://github.com/aditya18mew/api-gateway/blob/main/services/product-service/utils/mongoosedb.js): mongo connection · Service-local persistence · `services/product-service/utils/mongoosedb.js`

### Infra

Shared runtime and orchestration

- [Compose](https://github.com/aditya18mew/api-gateway/blob/main/compose.yaml): orchestration · Local multi-service stack definition · `compose.yaml`

### Other components

- **Client**: external · Consumers of the API

## Connections

- Client → Gateway: calls · All client traffic enters through the gateway
- Compose → Gateway: starts · Compose runs the gateway alongside services
- Compose → Auth service: starts · Compose runs the auth service
- Compose → User service: starts · Compose runs the user service
- Compose → Product service: starts · Compose runs the product service
- Gateway → Routes: uses · Gateway routes incoming requests
- Gateway → Auth guard: enforces · Authentication/authorization happens before forwarding
- Gateway → Rate limit: enforces · Gateway applies throttling controls
- Gateway → Circuit breaker: enforces · Gateway protects downstreams with circuit breaking
- Gateway → Logger: uses · Gateway logs request flow
- Gateway → Service config: reads · Gateway resolves downstream endpoints
- Gateway → Redis config: connects · Gateway uses Redis for shared control state
- Gateway → Docs UI: serves · Gateway exposes docs/test page
- Routes → Auth service: forwards to · Auth-related requests go to the auth service
- Routes → User service: forwards to · User-related requests go to the user service
- Routes → Product service: forwards to · Product-related requests go to the product service
- Auth service → Auth routes: exposes · Auth endpoints are defined in service routes
- Auth service → JWT utils: uses · Auth service hashes passwords and issues JWTs
- Auth service → Auth DB: persists to · Auth service owns its MongoDB connection
- User service → User DB: persists to · User service owns its MongoDB connection
- Product service → Product DB: persists to · Product service owns its MongoDB connection
