# damarudhvarma/uber-microservices architecture

> Architecture diagram of the GitHub repository damarudhvarma/uber-microservices, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/damarudhvarma/uber-microservices
- Repository: https://github.com/damarudhvarma/uber-microservices

## Overview

##### Project type and purpose
- This is a microservices-based ride-hailing application (“Uber Microservices Project”).
- Purpose: allow users to register/login and request rides; captains register/login and accept rides; rides are created and managed; a gateway routes client requests.

##### File structure
- Four top-level services:
- gateway/ – Reverse proxy (express-http-proxy) listening on port 3000
- user/ – User Service (port 3001)
- captain/ – Captain Service (port 3002)
- rides/ – Ride Service (port 3003)
- Each service has:
- DB/connect.js – MongoDB connection
- controllers/ – Request handlers
- models/ – Mongoose schemas (e.g., userModel, rideModel)
- middlewares/ – JWT auth & token blacklisting
- routes/ – Express routes
- service/rabbit.js – RabbitMQ publisher/subscriber
- app.js & server.js – Express setup and startup
- Shared config: .env for MONGO_URI, JWT_SECRET, RABBIT_URL, BASE_URL

##### Key architectural insights from README
- Communication:
- HTTP via gateway proxy for client→service
- Internal HTTP calls (axios) for service-to-service
- RabbitMQ for event-driven, async messaging
- Datastore: MongoDB per service
- Auth: JWT + token blacklisting (Mongo)
- Scalability: independent scaling of each service, load balancing at gateway

a. Main components
- Client (Web/Mobile)
- API Gateway (Express + express-http-proxy)
- User Service
- Captain Service
- Ride Service
- RabbitMQ Broker
- MongoDB Databases (one per service)
b. Relationships & interactions
1. Client → Gateway (HTTP)
2. Gateway → appropriate Service (HTTP proxy)
3. Service ↔ MongoDB (CRUD via Mongoose)
4. Service ↔ RabbitMQ (publish/subscribe events like “ride-created”, “ride-accepted”)
5. Services may communicate directly via HTTP (axios) for synchronous operations
c. Architectural patterns & design principles
- Microservices for domain separation
- Reverse proxy (API Gateway) for unified entry point
- Event-driven architecture with RabbitMQ for decoupling
- Token-based authentication (JWT) and token blacklisting
- Asynchronous, non-blocking operations in Node.js
d. Key technologies & frameworks
- Node.js + Express.js
- MongoDB + Mongoose
- RabbitMQ
- JWT, bcrypt
- express-http-proxy, axios
- dotenv, cookie-parser

##### Detail and separation
- Token-blacklist flow: show blacklistModel in Mongo used by authMiddleware.
- Environment config (.env) feeding into services.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Legend
    subgraph "Legend"
        direction TB
        C["Client (Web/Mobile)"]:::client
        GW["API Gateway"]:::gateway
        MS["Microservice"]:::service
        MQ["RabbitMQ Broker"]:::broker
        MD["MongoDB"]:::db
        class C client
        class GW gateway
        class MS service
        class MQ broker
        class MD db
    end

    %% Client
    Client["Client (Web/Mobile)"]:::client

    %% API Gateway
    subgraph "API Gateway (port 3000)"
        direction TB
        GApp["app.js"]:::gateway
        GServer["server.js"]:::gateway
        GPkg["package.json"]:::gateway
    end

    %% User Service
    subgraph "User Service (port 3001)"
        direction TB
        UApp["app.js"]:::service
        UServer["server.js"]:::service
        UDBConn["DB/connect.js"]:::db
        UControllers["controllers/userController.js"]:::service
        UUserModel["models/userModel.js"]:::db
        UBlacklistModel["models/blacklistModel.js"]:::db
        URoutes["routes/userRoutes.js"]:::service
        UAuth["middlewares/authMiddleware.js"]:::service
        URabbit["service/rabbit.js"]:::service
        UDBConn -->|CRUD| MongoUser[(User MongoDB)]:::db
    end

    %% Captain Service
    subgraph "Captain Service (port 3002)"
        direction TB
        CApp["app.js"]:::service
        CServer["server.js"]:::service
        CDBConn["DB/connect.js"]:::db
        CControllers["controllers/captainController.js"]:::service
        CModel["models/captainModel.js"]:::db
        CBlacklistModel["models/blacklistModel.js"]:::db
        CRoutes["routes/captainRoutes.js"]:::service
        CAuth["middlewares/authMiddleware.js"]:::service
        CRabbit["service/rabbit.js"]:::service
        CDBConn -->|CRUD| MongoCaptain[(Captain MongoDB)]:::db
    end

    %% Ride Service
    subgraph "Ride Service (port 3003)"
        direction TB
        RApp["app.js"]:::service
        RServer["server.js"]:::service
        RDBConn["DB/connect.js"]:::db
        RControllers["controllers/rideController.js"]:::service
        RModel["models/rideModel.js"]:::db
        RBlacklistModel["models/blacklistModel.js"]:::db
        RRoutes["routes/rideRoutes.js"]:::service
        RAuth["middlewares/authMiddleware.js"]:::service
        RRabbit["service/rabbit.js"]:::service
        RDBConn -->|CRUD| MongoRide[(Ride MongoDB)]:::db
    end

    %% Message Broker
    RabbitMQ["RabbitMQ Broker"]:::broker

    %% Interactions
    Client -->|HTTP| GApp
    GApp -->|proxy /user HTTP| UApp
    GApp -->|proxy /captain HTTP| CApp
    GApp -->|proxy /ride HTTP| RApp

    %% Service Events
    UApp -->|AMQP publish/sub| RabbitMQ
    CApp -->|AMQP publish/sub| RabbitMQ
    RApp -->|AMQP publish/sub| RabbitMQ

    %% Click Events
    click GApp "https://github.com/damarudhvarma/uber-microservices/blob/main/gateway/app.js"
    click GServer "https://github.com/damarudhvarma/uber-microservices/blob/main/gateway/server.js"
    click GPkg "https://github.com/damarudhvarma/uber-microservices/blob/main/gateway/package.json"

    click UApp "https://github.com/damarudhvarma/uber-microservices/blob/main/user/app.js"
    click UServer "https://github.com/damarudhvarma/uber-microservices/blob/main/user/server.js"
    click UDBConn "https://github.com/damarudhvarma/uber-microservices/blob/main/user/DB/connect.js"
    click UControllers "https://github.com/damarudhvarma/uber-microservices/blob/main/user/controllers/userController.js"
    click UUserModel "https://github.com/damarudhvarma/uber-microservices/blob/main/user/models/userModel.js"
    click UBlacklistModel "https://github.com/damarudhvarma/uber-microservices/blob/main/user/models/blacklistModel.js"
    click URoutes "https://github.com/damarudhvarma/uber-microservices/blob/main/user/routes/userRoutes.js"
    click UAuth "https://github.com/damarudhvarma/uber-microservices/blob/main/user/middlewares/authMiddleware.js"
    click URabbit "https://github.com/damarudhvarma/uber-microservices/blob/main/user/service/rabbit.js"

    click CApp "https://github.com/damarudhvarma/uber-microservices/blob/main/captain/app.js"
    click CServer "https://github.com/damarudhvarma/uber-microservices/blob/main/captain/server.js"
    click CDBConn "https://github.com/damarudhvarma/uber-microservices/blob/main/captain/DB/connect.js"
    click CControllers "https://github.com/damarudhvarma/uber-microservices/blob/main/captain/controllers/captainController.js"
    click CModel "https://github.com/damarudhvarma/uber-microservices/blob/main/captain/models/captainModel.js"
    click CBlacklistModel "https://github.com/damarudhvarma/uber-microservices/blob/main/captain/models/blacklistModel.js"
    click CRoutes "https://github.com/damarudhvarma/uber-microservices/blob/main/captain/routes/captainRoutes.js"
    click CAuth "https://github.com/damarudhvarma/uber-microservices/blob/main/captain/middlewares/authMiddleware.js"
    click CRabbit "https://github.com/damarudhvarma/uber-microservices/blob/main/captain/service/rabbit.js"

    click RApp "https://github.com/damarudhvarma/uber-microservices/blob/main/rides/app.js"
    click RServer "https://github.com/damarudhvarma/uber-microservices/blob/main/rides/server.js"
    click RDBConn "https://github.com/damarudhvarma/uber-microservices/blob/main/rides/DB/connect.js"
    click RControllers "https://github.com/damarudhvarma/uber-microservices/blob/main/rides/controllers/rideController.js"
    click RModel "https://github.com/damarudhvarma/uber-microservices/blob/main/rides/models/rideModel.js"
    click RBlacklistModel "https://github.com/damarudhvarma/uber-microservices/blob/main/rides/models/blacklistModel.js"
    click RRoutes "https://github.com/damarudhvarma/uber-microservices/blob/main/rides/routes/rideRoutes.js"
    click RAuth "https://github.com/damarudhvarma/uber-microservices/blob/main/rides/middlewares/authMiddleware.js"
    click RRabbit "https://github.com/damarudhvarma/uber-microservices/blob/main/rides/service/rabbit.js"

    %% Styles
    classDef client fill:#D8BFFD,stroke:#000
    classDef gateway fill:#ADD8E6,stroke:#000
    classDef service fill:#90EE90,stroke:#000
    classDef broker fill:#FFA500,stroke:#000
    classDef db fill:#D3D3D3,stroke:#000
```
