# sawastik7-bit/distributed-api-gateway-analytics architecture

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

- Interactive diagram: https://gitdiagram.com/sawastik7-bit/distributed-api-gateway-analytics
- Repository: https://github.com/sawastik7-bit/distributed-api-gateway-analytics

## Overview

This is a distributed API gateway and request-analytics product. A client request passes through gateway rate limiting, logging and JWT authentication, then is proxied to the users or products service. Separately, the logger queues request records for worker-side processing and dashboard updates; the React dashboard receives live stats and renders cards, charts, routes and recent logs. The README documents Redis, BullMQ, MongoDB and Socket.io roles, while worker internals and service-to-store details are not excerpted, so those relationships are shown only where documented.

Main entry points: [`Backend/gateway/server.js`](https://github.com/sawastik7-bit/distributed-api-gateway-analytics/blob/main/Backend/gateway/server.js) (Gateway Server), [`Frontend/Client/src/App.jsx`](https://github.com/sawastik7-bit/distributed-api-gateway-analytics/blob/main/Frontend/Client/src/App.jsx) (Dashboard App), [`Backend/routes/proxy.js`](https://github.com/sawastik7-bit/distributed-api-gateway-analytics/blob/main/Backend/routes/proxy.js) (Reverse Proxy), [`Backend/worker/index.js`](https://github.com/sawastik7-bit/distributed-api-gateway-analytics/blob/main/Backend/worker/index.js) (Analytics Worker)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_gateway["Gateway Controls"]
  node_gateway["Gateway Server<br/>[server.js]"]
  node_limiter["Rate Limiter<br/>[rateLimiter.js]"]
  node_auth["JWT Authentication<br/>[auth.js]"]
  node_proxy["Reverse Proxy<br/>[proxy.js]"]
end

subgraph group_services["API Services"]
  node_users["Users Service<br/>[index.js]"]
  node_products["Products Service<br/>[index.js]"]
end

subgraph group_analytics["Analytics Pipeline"]
  node_logger["Request Logger<br/>[logger.js]"]
  node_redis[("Redis")]
  node_logqueue["BullMQ Log Queue"]
  node_worker["Analytics Worker<br/>[index.js]"]
  node_mongodb[("MongoDB")]
  node_socket["Socket.io Server<br/>[index.js]"]
end

subgraph group_dashboard["Dashboard"]
  node_dashboard["Dashboard App<br/>[App.jsx]"]
  node_stats["Stats Cards<br/>[StatsCard.jsx]"]
  node_chart["Live Chart<br/>[LiveChart.jsx]"]
  node_routes["Top Routes<br/>[TopRoutes.jsx]"]
  node_recent["Recent Logs<br/>[RecentLogs.jsx]"]
end

node_client(("API Client"))

node_client -->|"sends requests"| node_gateway
node_gateway -->|"applies limits"| node_limiter
node_limiter -->|"checks counters"| node_redis
node_gateway -->|"records requests"| node_logger
node_gateway -->|"authenticates routes"| node_auth
node_gateway -->|"dispatches routes"| node_proxy
node_proxy -->|"proxies users"| node_users
node_proxy -->|"proxies products"| node_products
node_logger -->|"enqueues logs"| node_logqueue
node_logqueue -->|"delivers jobs"| node_worker
node_worker -->|"stores analytics"| node_mongodb
node_worker -->|"publishes stats"| node_socket
node_socket -->|"streams stats"| node_dashboard
node_dashboard -->|"renders values"| node_stats
node_dashboard -->|"renders series"| node_chart
node_dashboard -->|"renders rankings"| node_routes
node_dashboard -->|"renders requests"| node_recent

click node_gateway "https://github.com/sawastik7-bit/distributed-api-gateway-analytics/blob/main/Backend/gateway/server.js"
click node_limiter "https://github.com/sawastik7-bit/distributed-api-gateway-analytics/blob/main/Backend/gateway/middleware/rateLimiter.js"
click node_auth "https://github.com/sawastik7-bit/distributed-api-gateway-analytics/blob/main/Backend/gateway/middleware/auth.js"
click node_logger "https://github.com/sawastik7-bit/distributed-api-gateway-analytics/blob/main/Backend/gateway/middleware/logger.js"
click node_proxy "https://github.com/sawastik7-bit/distributed-api-gateway-analytics/blob/main/Backend/routes/proxy.js"
click node_users "https://github.com/sawastik7-bit/distributed-api-gateway-analytics/blob/main/Backend/services/service_A/index.js"
click node_products "https://github.com/sawastik7-bit/distributed-api-gateway-analytics/blob/main/Backend/services/service_B/index.js"
click node_worker "https://github.com/sawastik7-bit/distributed-api-gateway-analytics/blob/main/Backend/worker/index.js"
click node_socket "https://github.com/sawastik7-bit/distributed-api-gateway-analytics/blob/main/Backend/worker/index.js"
click node_dashboard "https://github.com/sawastik7-bit/distributed-api-gateway-analytics/blob/main/Frontend/Client/src/App.jsx"
click node_stats "https://github.com/sawastik7-bit/distributed-api-gateway-analytics/blob/main/Frontend/Client/src/components/StatsCard.jsx"
click node_chart "https://github.com/sawastik7-bit/distributed-api-gateway-analytics/blob/main/Frontend/Client/src/components/LiveChart.jsx"
click node_routes "https://github.com/sawastik7-bit/distributed-api-gateway-analytics/blob/main/Frontend/Client/src/components/TopRoutes.jsx"
click node_recent "https://github.com/sawastik7-bit/distributed-api-gateway-analytics/blob/main/Frontend/Client/src/components/RecentLogs.jsx"

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_gateway,node_limiter,node_auth,node_proxy,node_client toneBlue
class node_users,node_products toneAmber
class node_logger,node_redis,node_logqueue,node_worker,node_mongodb,node_socket toneMint
class node_dashboard,node_stats,node_chart,node_routes,node_recent toneRose
```

## Components

### Gateway Controls

- [Gateway Server](https://github.com/sawastik7-bit/distributed-api-gateway-analytics/blob/main/Backend/gateway/server.js): `Backend/gateway/server.js`
- [Rate Limiter](https://github.com/sawastik7-bit/distributed-api-gateway-analytics/blob/main/Backend/gateway/middleware/rateLimiter.js): `Backend/gateway/middleware/rateLimiter.js`
- [JWT Authentication](https://github.com/sawastik7-bit/distributed-api-gateway-analytics/blob/main/Backend/gateway/middleware/auth.js): `Backend/gateway/middleware/auth.js`
- [Reverse Proxy](https://github.com/sawastik7-bit/distributed-api-gateway-analytics/blob/main/Backend/routes/proxy.js): `Backend/routes/proxy.js`

### API Services

- [Users Service](https://github.com/sawastik7-bit/distributed-api-gateway-analytics/blob/main/Backend/services/service_A/index.js): `Backend/services/service_A/index.js`
- [Products Service](https://github.com/sawastik7-bit/distributed-api-gateway-analytics/blob/main/Backend/services/service_B/index.js): `Backend/services/service_B/index.js`

### Analytics Pipeline

- [Request Logger](https://github.com/sawastik7-bit/distributed-api-gateway-analytics/blob/main/Backend/gateway/middleware/logger.js): `Backend/gateway/middleware/logger.js`
- **Redis**
- **BullMQ Log Queue**
- [Analytics Worker](https://github.com/sawastik7-bit/distributed-api-gateway-analytics/blob/main/Backend/worker/index.js): `Backend/worker/index.js`
- **MongoDB**
- [Socket.io Server](https://github.com/sawastik7-bit/distributed-api-gateway-analytics/blob/main/Backend/worker/index.js): `Backend/worker/index.js`

### Dashboard

- [Dashboard App](https://github.com/sawastik7-bit/distributed-api-gateway-analytics/blob/main/Frontend/Client/src/App.jsx): `Frontend/Client/src/App.jsx`
- [Stats Cards](https://github.com/sawastik7-bit/distributed-api-gateway-analytics/blob/main/Frontend/Client/src/components/StatsCard.jsx): `Frontend/Client/src/components/StatsCard.jsx`
- [Live Chart](https://github.com/sawastik7-bit/distributed-api-gateway-analytics/blob/main/Frontend/Client/src/components/LiveChart.jsx): `Frontend/Client/src/components/LiveChart.jsx`
- [Top Routes](https://github.com/sawastik7-bit/distributed-api-gateway-analytics/blob/main/Frontend/Client/src/components/TopRoutes.jsx): `Frontend/Client/src/components/TopRoutes.jsx`
- [Recent Logs](https://github.com/sawastik7-bit/distributed-api-gateway-analytics/blob/main/Frontend/Client/src/components/RecentLogs.jsx): `Frontend/Client/src/components/RecentLogs.jsx`

### Other components

- **API Client**

## Connections

- API Client → Gateway Server: sends requests (evidence: `README.md`)
- Gateway Server → Rate Limiter: applies limits (evidence: `Backend/gateway/server.js`)
- Rate Limiter → Redis: checks counters (evidence: `Backend/gateway/middleware/rateLimiter.js`)
- Gateway Server → Request Logger: records requests (evidence: `Backend/gateway/server.js`)
- Gateway Server → JWT Authentication: authenticates routes (evidence: `Backend/gateway/server.js`)
- Gateway Server → Reverse Proxy: dispatches routes (evidence: `Backend/gateway/server.js`)
- Reverse Proxy → Users Service: proxies users (evidence: `Backend/routes/proxy.js`)
- Reverse Proxy → Products Service: proxies products (evidence: `Backend/routes/proxy.js`)
- Request Logger → BullMQ Log Queue: enqueues logs (evidence: `Backend/gateway/middleware/logger.js`)
- BullMQ Log Queue → Analytics Worker: delivers jobs (evidence: `README.md`)
- Analytics Worker → MongoDB: stores analytics (evidence: `README.md`)
- Analytics Worker → Socket.io Server: publishes stats (evidence: `README.md`)
- Socket.io Server → Dashboard App: streams stats (evidence: `README.md`)
- Dashboard App → Stats Cards: renders values (evidence: `Frontend/Client/src/App.jsx`)
- Dashboard App → Live Chart: renders series (evidence: `Frontend/Client/src/App.jsx`)
- Dashboard App → Top Routes: renders rankings (evidence: `Frontend/Client/src/App.jsx`)
- Dashboard App → Recent Logs: renders requests (evidence: `Frontend/Client/src/App.jsx`)
