# titiksha1102/microservice-ride-booking-app architecture

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

- Interactive diagram: https://gitdiagram.com/titiksha1102/microservice-ride-booking-app
- Repository: https://github.com/titiksha1102/microservice-ride-booking-app

## Overview

##### Project type and purpose
- TezzRides is a full-stack, real-time ride-booking application built on a modular microservices architecture.
- It consists of multiple standalone Node.js/Express services (User, Captain, Ride), a React frontend, MongoDB databases, RabbitMQ for saga workflow, and Socket.IO for live updates.

##### File structure
- Top-level directories:
- CaptainService, RideService, UserService, SubscriberService (microservices)
- Frontend/uber-clone-frontend (React frontend)
- Root docker-compose.yaml orchestrates all services together.
- Each service includes controllers, routes, models, middleware, a RabbitMQ integration module, and its own Dockerfile.
- A socket-server.js in CaptainService indicates real-time WebSocket handling.

##### README for additional insights
- Confirms use of the Saga pattern via RabbitMQ for distributed transaction management.
- Mentions an API Gateway (not explicitly in code but implied) for routing and security.
- Highlights Socket.IO for sub-second communication and responsive React UI.

a. Main components:
- React Frontend (User and Captain interfaces)
- API Gateway / Load Balancer
- User Service (Express + MongoDB)
- Captain Service (Express + MongoDB + Socket.IO)
- Ride Service (Express + MongoDB)
- Subscriber Service (event listener)
- RabbitMQ Broker (message queues for Saga pattern)
- MongoDB instances for each service
- External dependencies (e.g., geolocation API, payment gateway – if applicable)

b. Relationships and interactions:
- Frontend → API Gateway → respective microservice endpoints
- Services communicate state changes via RabbitMQ exchanges/queues (e.g., ride-requested, ride-accepted)
- Subscriber Service listens to events for analytics or notifications
- Captain Service pushes real-time updates to connected clients over WebSockets
- Each service performs CRUD operations against its own MongoDB database

c. Architectural patterns and design principles:
- Microservices: independently deployable services, each with its own data store
- Saga pattern: asynchronous, event-driven workflow management via RabbitMQ
- API Gateway: unified entry point, security (authentication middleware), request routing
- Separation of concerns: controllers, services, models, middleware layers clearly defined

d. Relevant technologies and frameworks:
- Node.js + Express.js for all backend services
- React.js + Vite for frontend
- MongoDB for data persistence
- RabbitMQ as the message broker
- Socket.IO for real-time messaging
- Docker & Docker Compose for containerization and orchestration

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    Frontend["React Frontend"]:::frontend
    API["API Gateway / Load Balancer"]:::gateway

    Frontend -->|"REST/WebSocket"| API

    %% Services Layer
    subgraph "Backend Services"
        direction TB
        UserService["User Service\n(Express/MongoDB)"]:::service
        CaptainService["Captain Service\n(Express/MongoDB + Socket.IO)"]:::service
        RideService["Ride Service\n(Express/MongoDB)"]:::service
        SubscriberService["Subscriber Service\n(Event Listener)"]:::service
    end

    API -->|"HTTP API"| UserService
    API -->|"HTTP API"| CaptainService
    API -->|"HTTP API"| RideService

    %% Real-time channel
    CaptainService -->|"WebSocket (Socket.IO)"| Frontend

    %% Messaging Infrastructure
    RabbitMQ["RabbitMQ Broker\n(Saga Orchestration)"]:::message
    class message message
    UserService -->|"publish/consume events"| RabbitMQ
    CaptainService -->|"publish/consume events"| RabbitMQ
    RideService -->|"publish/consume events"| RabbitMQ
    SubscriberService -->|"consume events"| RabbitMQ

    %% Databases
    UserDB["User DB\n(MongoDB)"]:::db
    CaptainDB["Captain DB\n(MongoDB)"]:::db
    RideDB["Ride DB\n(MongoDB)"]:::db

    UserService -->|"CRUD"| UserDB
    CaptainService -->|"CRUD"| CaptainDB
    RideService -->|"CRUD"| RideDB

    %% Orchestration
    DockerCompose["Docker Compose\n(Orchestration)"]:::infra
    DockerCompose --> RabbitMQ
    DockerCompose --> UserService
    DockerCompose --> CaptainService
    DockerCompose --> RideService
    DockerCompose --> SubscriberService
    DockerCompose --> Frontend

    %% Click Events
    click Frontend "https://github.com/titiksha1102/microservice-ride-booking-app/tree/spaces-removed-from-folder-names/Frontend/uber-clone-frontend"
    click UserService "https://github.com/titiksha1102/microservice-ride-booking-app/blob/spaces-removed-from-folder-names/UserService/server.js"
    click CaptainService "https://github.com/titiksha1102/microservice-ride-booking-app/blob/spaces-removed-from-folder-names/CaptainService/server.js"
    click RideService "https://github.com/titiksha1102/microservice-ride-booking-app/blob/spaces-removed-from-folder-names/RideService/server.js"
    click SubscriberService "https://github.com/titiksha1102/microservice-ride-booking-app/blob/spaces-removed-from-folder-names/SubscriberService/server.js"
    click DockerCompose "https://github.com/titiksha1102/microservice-ride-booking-app/blob/spaces-removed-from-folder-names/docker-compose.yaml"

    %% Styles
    classDef frontend fill:#bbdefb,stroke:#0b5394,color:#0b5394;
    classDef gateway fill:#d0f0c0,stroke:#38761d,color:#38761d;
    classDef service fill:#c8e6c9,stroke:#2e7d32,color:#2e7d32;
    classDef db fill:#ffe0b2,stroke:#e65100,color:#e65100;
    classDef message fill:#e1bee7,stroke:#6a1b9a,color:#6a1b9a;
    classDef infra fill:#f0f0f0,stroke:#616161,color:#424242;
```
