# abhi-codex/ride_app_server architecture

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

- Interactive diagram: https://gitdiagram.com/abhi-codex/ride_app_server
- Repository: https://github.com/abhi-codex/ride_app_server

## Overview

##### Project type and purpose
- This is a Node.js/Express backend service for the “InstaAid” mobile app.
- It exposes RESTful endpoints (and WebSocket events) to support user authentication, ride requests, hospital & driver management, and real-time updates.

##### File structure
- Top-level files:
- app.js – entry point, wires up Express, middleware, routers, and socket server
- config/connect.js – MongoDB (or similar) connection setup
- package.json / .env.example – dependencies and environment variables
- Directories:
- routes/ – defines endpoint paths per domain (auth, driver, hospital, ride)
- controllers/ – request handlers implementing business logic
- models/ – Mongoose (or ORM) schemas: User, Hospital, Ride
- middleware/ – authentication checks, error handling, 404 handler
- errors/ – custom error classes (BadRequest, NotFound, Unauthenticated, etc.)
- utils/ – domain helpers (e.g., ambulance dispatch logic)
- docs/ – documentation.md for detailed API usage

##### README for additional insights
- The README confirms this is “Backend Server for the InstaAid app.”
- For end-to-end details, see docs/documentation.md

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Apps"
        direction TB
        RiderApp["Rider App"]:::external
        DriverApp["Driver App"]:::external
        HospitalApp["Hospital Staff App"]:::external
    end

    %% API Gateway
    API["Express Server (app.js)"]:::http

    %% Middleware Layer
    subgraph "Middleware"
        direction TB
        AuthMW["Auth Middleware"]:::middleware
        ErrMW["Error-Handler Middleware"]:::middleware
        NotFoundMW["Not-Found Middleware"]:::middleware
    end

    %% Routing Layer
    subgraph "Routes"
        direction TB
        AuthRoute["Auth Routes"]:::http
        DriverRoute["Driver Routes"]:::http
        HospitalRoute["Hospital Routes"]:::http
        RideRoute["Ride Routes"]:::http
    end

    %% Controller Layer
    subgraph "Controllers"
        direction TB
        AuthCtrl["Auth Controller"]:::business
        DriverCtrl["Driver Controller"]:::business
        HospitalCtrl["Hospital Controller"]:::business
        RideCtrl["Ride Controller"]:::business
        SocketCtrl["WebSocket Handlers"]:::websocket
    end

    %% Utilities
    Utils["Ambulance Dispatch Utility"]:::business

    %% Data Layer
    subgraph "Data & Models"
        direction TB
        Connect["DB Connection (config/connect.js)"]:::data
        MongoDB["MongoDB"]:::datastore
        UserModel["User Model"]:::datastore
        HospitalModel["Hospital Model"]:::datastore
        RideModel["Ride Model"]:::datastore
    end

    %% External Services
    subgraph "External Services"
        direction TB
        GeoAPI["Geolocation API"]:::external
        Notification["SMS/Push Service"]:::external
    end

    %% Flow Connections
    RiderApp -->|HTTP/WS Requests| API
    DriverApp -->|HTTP/WS Requests| API
    HospitalApp -->|HTTP/WS Requests| API

    API --> AuthMW
    API --> ErrMW
    API --> NotFoundMW

    AuthMW --> AuthRoute
    AuthMW --> DriverRoute
    AuthMW --> HospitalRoute
    AuthMW --> RideRoute

    AuthRoute --> AuthCtrl
    DriverRoute --> DriverCtrl
    HospitalRoute --> HospitalCtrl
    RideRoute --> RideCtrl

    AuthCtrl -->|DB Ops| Connect
    DriverCtrl -->|DB Ops| Connect
    HospitalCtrl -->|DB Ops| Connect
    RideCtrl -->|DB Ops| Connect

    Connect --> MongoDB
    MongoDB --> UserModel
    MongoDB --> HospitalModel
    MongoDB --> RideModel

    AuthCtrl -->|uses| Utils
    DriverCtrl -->|uses| Utils
    HospitalCtrl -->|uses| Utils
    RideCtrl -->|uses| Utils

    API --> SocketCtrl
    SocketCtrl --> RiderApp
    SocketCtrl --> DriverApp
    SocketCtrl --> HospitalApp

    SocketCtrl --> GeoAPI
    SocketCtrl --> Notification

    %% Click Events
    click API "https://github.com/abhi-codex/ride_app_server/blob/main/app.js"
    click Connect "https://github.com/abhi-codex/ride_app_server/blob/main/config/connect.js"
    click AuthRoute "https://github.com/abhi-codex/ride_app_server/blob/main/routes/auth.js"
    click DriverRoute "https://github.com/abhi-codex/ride_app_server/blob/main/routes/driver.js"
    click HospitalRoute "https://github.com/abhi-codex/ride_app_server/blob/main/routes/hospital.js"
    click RideRoute "https://github.com/abhi-codex/ride_app_server/blob/main/routes/ride.js"
    click AuthMW "https://github.com/abhi-codex/ride_app_server/blob/main/middleware/authentication.js"
    click ErrMW "https://github.com/abhi-codex/ride_app_server/blob/main/middleware/error-handler.js"
    click NotFoundMW "https://github.com/abhi-codex/ride_app_server/blob/main/middleware/not-found.js"
    click AuthCtrl "https://github.com/abhi-codex/ride_app_server/blob/main/controllers/auth.js"
    click DriverCtrl "https://github.com/abhi-codex/ride_app_server/blob/main/controllers/driver.js"
    click HospitalCtrl "https://github.com/abhi-codex/ride_app_server/blob/main/controllers/hospital.js"
    click RideCtrl "https://github.com/abhi-codex/ride_app_server/blob/main/controllers/ride.js"
    click SocketCtrl "https://github.com/abhi-codex/ride_app_server/blob/main/controllers/sockets.js"
    click UserModel "https://github.com/abhi-codex/ride_app_server/blob/main/models/User.js"
    click HospitalModel "https://github.com/abhi-codex/ride_app_server/blob/main/models/Hospital.js"
    click RideModel "https://github.com/abhi-codex/ride_app_server/blob/main/models/Ride.js"
    click Utils "https://github.com/abhi-codex/ride_app_server/blob/main/utils/ambulance.js"
    click Notification "https://github.com/abhi-codex/ride_app_server/blob/main/errors/index.js"
    click MongoDB "https://github.com/abhi-codex/ride_app_server/blob/main/docs/documentation.md"

    %% Styles
    classDef external fill:#f9f,stroke:#333,stroke-width:1px
    classDef http fill:#bbdefb,stroke:#333,stroke-width:1px
    classDef middleware fill:#ffe082,stroke:#333,stroke-width:1px
    classDef business fill:#c8e6c9,stroke:#333,stroke-width:1px
    classDef data fill:#ffe0b2,stroke:#333,stroke-width:1px
    classDef datastore fill:#d1c4e9,stroke:#333,stroke-width:1px
    classDef websocket fill:#b2ebf2,stroke:#333,stroke-width:1px
```
