# rahulks01/bequem architecture

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

- Interactive diagram: https://gitdiagram.com/rahulks01/bequem
- Repository: https://github.com/rahulks01/bequem

## Overview

##### Project type and purpose
- This is a full‑stack, real‑time cab‑booking application called **βequem**.
- Frontend: React + Vite for User and Captain (driver) interfaces.
- Backend: Node.js/Express API with Socket.IO for real‑time events, MongoDB for persistence, and Google Maps API for geocoding and maps.

##### File structure
- Top-level directories:
- Backend/ – Express app with MVC‑style structure:
– controllers/ (HTTP handlers)
– services/ (business logic)
– models/ (Mongoose schemas)
– routes/ (REST endpoints)
– middlewares/ (auth)
– db/ (DB connection)
– socket.js (real‑time events bootstrapping)
- Frontend/ – Vite‑powered React app:
– src/pages/ (route‑level components for User & Captain flows)
– src/components/ (UI pieces: ride popups, tracking, etc.)
– src/context/ (React Context for User, Captain, Socket)
– public/, index.html, config files

##### Key insights from README
- Real‑time ride requests: user searches locations → ride requested → backend notifies nearby captains via WebSocket → captain accepts → OTP handshake → ride lifecycle → trip completion resets UI.
- External dependencies: MongoDB, JWT for auth, Google Maps API, Socket.IO real‑time layer.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Clients
    subgraph "User Web Client" 
        direction TB
        UPages["Pages"]:::frontend
        UContext["UserContext"]:::frontend
        UComponents["UI Components"]:::frontend
    end
    subgraph "Captain Web Client"
        direction TB
        CPages["Pages"]:::frontend
        CContext["CaptainContext"]:::frontend
        CComponents["UI Components"]:::frontend
    end

    %% Backend API & Real‑Time
    subgraph "Backend (Node.js/Express)" 
        direction TB
        Entry["app.js / server.js"]:::backend
        AuthMW["auth.middleware.js"]:::backend

        subgraph "Routes"
            direction TB
            URoutes["user.routes.js"]:::backend
            CRoutes["captain.routes.js"]:::backend
            RRoutes["ride.routes.js"]:::backend
            MRoutes["maps.routes.js"]:::backend
        end

        subgraph "Controllers"
            direction TB
            UController["user.controller.js"]:::backend
            CController["captain.controller.js"]:::backend
            RController["ride.controller.js"]:::backend
            MController["map.controller.js"]:::backend
        end

        subgraph "Services"
            direction TB
            UService["user.service.js"]:::backend
            CService["captain.service.js"]:::backend
            RService["ride.service.js"]:::backend
            MService["maps.service.js"]:::backend
        end

        subgraph "Models"
            direction TB
            UModel["user.model.js"]:::backend
            CModel["captain.model.js"]:::backend
            RModel["ride.model.js"]:::backend
            BModel["blacklistToken.model.js"]:::backend
        end

        DBInit["db.js"]:::backend
        SocketServer["socket.js"]:::backend
    end

    %% Database
    subgraph "MongoDB" 
        direction TB
        Collections["users, captains, rides,\nblacklistTokens"]:::db
    end

    %% External Services
    GoogleMaps["Google Maps API"]:::external

    %% Connections: HTTP
    UPages -->|"HTTPS Request"| Entry
    CPages -->|"HTTPS Request"| Entry
    Entry -->|routes| URoutes & CRoutes & RRoutes & MRoutes
    URoutes -->|calls| UController
    CRoutes -->|calls| CController
    RRoutes -->|calls| RController
    MRoutes -->|calls| MController
    UController -->|uses| UService
    CController -->|uses| CService
    RController -->|uses| RService
    MController -->|uses| MService
    UService -->|CRUD| UModel
    CService -->|CRUD| CModel
    RService -->|CRUD| RModel
    AuthMW -->|revokes| BModel
    DBInit -->|connects| Collections

    %% Real‑Time WebSocket Connections
    UContext -->|"ws connect"| SocketServer
    CContext -->|"ws connect"| SocketServer
    SocketServer -->|emit newRide| CComponents
    CComponents -->|"acceptRide"| SocketServer
    SocketServer -->|emit rideAccepted| UComponents
    UComponents -->|"confirmOTP"| SocketServer
    CComponents -->|"locationUpdate"| SocketServer
    SocketServer -->|emit locationUpdate| UComponents
    CComponents -->|"completeRide"| SocketServer
    SocketServer -->|emit rideComplete| UComponents

    %% Maps API flow
    UComponents -->|"search location"| MService
    MService -->|HTTP| GoogleMaps
    GoogleMaps -->|geocode data| MService
    MService -->|result| UComponents

    %% Click Events
    click UPages "https://github.com/rahulks01/bequem/tree/main/Frontend/src/pages"
    click UContext "https://github.com/rahulks01/bequem/blob/main/Frontend/src/context/UserContext.jsx"
    click UComponents "https://github.com/rahulks01/bequem/tree/main/Frontend/src/components"
    click CPages "https://github.com/rahulks01/bequem/tree/main/Frontend/src/pages"
    click CContext "https://github.com/rahulks01/bequem/blob/main/Frontend/src/context/CapatainContext.jsx"
    click CComponents "https://github.com/rahulks01/bequem/tree/main/Frontend/src/components"
    click SocketServer "https://github.com/rahulks01/bequem/blob/main/Backend/socket.js"
    click Entry "https://github.com/rahulks01/bequem/blob/main/Backend/server.js"
    click Entry "https://github.com/rahulks01/bequem/blob/main/Backend/app.js"
    click URoutes "https://github.com/rahulks01/bequem/blob/main/Backend/routes/user.routes.js"
    click CRoutes "https://github.com/rahulks01/bequem/blob/main/Backend/routes/captain.routes.js"
    click RRoutes "https://github.com/rahulks01/bequem/blob/main/Backend/routes/ride.routes.js"
    click MRoutes "https://github.com/rahulks01/bequem/blob/main/Backend/routes/maps.routes.js"
    click UController "https://github.com/rahulks01/bequem/blob/main/Backend/controllers/user.controller.js"
    click CController "https://github.com/rahulks01/bequem/blob/main/Backend/controllers/captain.controller.js"
    click RController "https://github.com/rahulks01/bequem/blob/main/Backend/controllers/ride.controller.js"
    click MController "https://github.com/rahulks01/bequem/blob/main/Backend/controllers/map.controller.js"
    click UService "https://github.com/rahulks01/bequem/blob/main/Backend/services/user.service.js"
    click CService "https://github.com/rahulks01/bequem/blob/main/Backend/services/captain.service.js"
    click RService "https://github.com/rahulks01/bequem/blob/main/Backend/services/ride.service.js"
    click MService "https://github.com/rahulks01/bequem/blob/main/Backend/services/maps.service.js"
    click UModel "https://github.com/rahulks01/bequem/blob/main/Backend/models/user.model.js"
    click CModel "https://github.com/rahulks01/bequem/blob/main/Backend/models/captain.model.js"
    click RModel "https://github.com/rahulks01/bequem/blob/main/Backend/models/ride.model.js"
    click BModel "https://github.com/rahulks01/bequem/blob/main/Backend/models/blacklistToken.model.js"
    click AuthMW "https://github.com/rahulks01/bequem/blob/main/Backend/middlewares/auth.middleware.js"
    click DBInit "https://github.com/rahulks01/bequem/blob/main/Backend/db/db.js"

    %% Styles
    classDef frontend fill:#E8F4FC,stroke:#0366D6,stroke-width:1px;
    classDef backend fill:#F0F0F0,stroke:#333,stroke-width:1px;
    classDef db fill:#FFF4E5,stroke:#DFA90A,stroke-width:1px;
    classDef external fill:#EFEFEF,stroke:#888,stroke-width:1px;
```
