# sujal-github/routeify architecture

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

- Interactive diagram: https://gitdiagram.com/sujal-github/routeify
- Repository: https://github.com/sujal-github/routeify

## Overview

##### Project Type and Purpose
- This is a full-stack ride-sharing application (“Routeify”) with:
- A React/Redux frontend (mobile-first, responsive UI)
- A Node.js/Express.js backend (REST APIs + Socket.io for real-time)
- MongoDB for persistence (including geospatial queries)
- An external payment service (Razorpay)
- Purpose: Allow passengers to book rides in real time, drivers to accept/manage rides, and display live location updates.

##### File Structure
- Top-Level Directories:
- frontend/ – React code, Redux store, TailwindCSS, WebSocket context
- backend/ – Express app, MVC structure (controllers, services, models), Socket.io setup, scheduling utility
- tests/ – end-to-end or unit tests
- Backend Pattern:
- server.js & app.js bootstrap the Express app
- routes/* → controllers/* → services/* → models/* (MVC + service layer)
- middlewares/auth.middleware.js for JWT auth
- socket.js for real-time event handling
- Frontend Pattern:
- src/pages/ – page-level components (captain, user flows)
- src/components/ – presentational & container components
- src/actions + src/reducers + store.js – Redux architecture
- src/context/socketContext – WebSocket provider for real-time updates
- Config & Deployment:
- vite.config.js, tailwind.config.js, postcss.config.js
- package.json scripts for dev/build

##### Key Insights from README
- Real-time tracking via Socket.io
- MongoDB geospatial indexing for optimized matching
- Razorpay integration for secure payments
- Designed for high concurrency (800+ users)

##### Detail
- Every layer: client UI → Redux → API layer → service layer → data layer.
- Scheduler as a separate worker node if it runs on its own process.
- Real-time event channel (Socket.io), distinct from REST.

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% Frontend Layer
  subgraph "Frontend Layer"
    Components["UI Components"]:::frontend
    Pages["Page-Level Components"]:::frontend
    Actions["Redux Actions"]:::frontend
    Reducers["Redux Reducers"]:::frontend
    Store["Redux Store Configuration"]:::frontend
    SocketContext["WebSocket Context Provider"]:::frontend
    React["React UI"]:::frontend
  end

  %% Backend Layer
  subgraph "Backend Layer"
    AppBootstrap["Express App Bootstrap"]:::backend
    DBConn["Database Connection (MongoDB)"]:::backend
    AuthMW["Authentication Middleware (JWT)"]:::backend

    subgraph "API Routes"
      CapRoutes["Captain Routes"]:::backend
      UserRoutes["User Routes"]:::backend
      RideRoutes["Ride Routes"]:::backend
      MapRoutes["Map Routes"]:::backend
      PaymentRoutes["Payment Routes"]:::backend
    end

    subgraph "Controllers"
      CaptainController["CaptainController"]:::backend
      UserController["UserController"]:::backend
      RideController["RideController"]:::backend
      MapController["MapController"]:::backend
      PaymentController["PaymentController"]:::backend
    end

    subgraph "Services"
      CaptainService["CaptainService"]:::backend
      UserService["UserService"]:::backend
      RideService["RideService"]:::backend
      MapsService["MapsService"]:::backend
    end

    subgraph "Models"
      UserModel["User Model"]:::backend
      CaptainModel["Captain Model"]:::backend
      RideModel["Ride Model"]:::backend
      BlacklistModel["BlacklistTokens Model"]:::backend
    end

    SocketSrv["Real-Time Socket Service"]:::backend
    Scheduler["Scheduler/Worker Utility"]:::backend
  end

  %% Database and External Services
  DB["MongoDB Cluster"]:::db
  extRazor["Razorpay API"]:::external
  extMap["External Map API"]:::external

  %% Frontend connections
  React -->|REST calls| AppBootstrap
  React -- WebSocket --> SocketContext
  Pages --> Store
  Components --> Store
  Store -->|dispatches| Actions
  Actions -->|updates| Reducers
  Store -->|provides| SocketContext
  SocketContext -- WebSocket --> SocketSrv

  %% Backend connections
  AppBootstrap --> DBConn
  AppBootstrap --> AuthMW
  AppBootstrap --> CapRoutes
  AppBootstrap --> UserRoutes
  AppBootstrap --> RideRoutes
  AppBootstrap --> MapRoutes
  AppBootstrap --> PaymentRoutes

  DBConn --> DB
  AuthMW --> CapRoutes
  AuthMW --> UserRoutes
  AuthMW --> RideRoutes

  CapRoutes --> CaptainController
  UserRoutes --> UserController
  RideRoutes --> RideController
  MapRoutes --> MapController
  PaymentRoutes --> PaymentController

  CaptainController --> CaptainService
  UserController --> UserService
  RideController --> RideService
  MapController --> MapsService
  PaymentController -->|Razorpay SDK| extRazor

  CaptainService --> CaptainModel
  UserService --> UserModel
  RideService --> RideModel
  RideService --> DB
  ScheduleDB["Scheduler DB Tasks"]:::backend
  Scheduler --> ScheduleDB
  Scheduler -->|emits events| SocketSrv

  ServicesEmit["Service Emits"]:::backend
  RideService -->|geospatial queries| DB
  MapController -->|calls| extMap

  ControllersSocket["Controllers Emits"]:::backend
  RideController -->|emit updates| SocketSrv

  %% External connections
  extRazor -->|webhook callback| PaymentController
  extMap --> MapController

  %% Click Events
  click Components "https://github.com/sujal-github/routeify/tree/main/frontend/src/components"
  click Pages "https://github.com/sujal-github/routeify/tree/main/frontend/src/pages"
  click Actions "https://github.com/sujal-github/routeify/tree/main/frontend/src/actions"
  click Reducers "https://github.com/sujal-github/routeify/tree/main/frontend/src/reducers"
  click Store "https://github.com/sujal-github/routeify/blob/main/frontend/src/store.js"
  click SocketContext "https://github.com/sujal-github/routeify/blob/main/frontend/src/context/socketContext.jsx"
  click AppBootstrap "https://github.com/sujal-github/routeify/blob/main/backend/app.js"
  click AppBootstrap "https://github.com/sujal-github/routeify/blob/main/backend/server.js"
  click DBConn "https://github.com/sujal-github/routeify/blob/main/backend/db/db.js"
  click AuthMW "https://github.com/sujal-github/routeify/blob/main/backend/middlewares/auth.middleware.js"
  click CapRoutes "https://github.com/sujal-github/routeify/blob/main/backend/routes/captain.routes.js"
  click UserRoutes "https://github.com/sujal-github/routeify/blob/main/backend/routes/user.routes.js"
  click RideRoutes "https://github.com/sujal-github/routeify/blob/main/backend/routes/ride.routes.js"
  click MapRoutes "https://github.com/sujal-github/routeify/blob/main/backend/routes/map.routes.js"
  click PaymentRoutes "https://github.com/sujal-github/routeify/blob/main/backend/routes/payment.routes.js"
  click CaptainController "https://github.com/sujal-github/routeify/blob/main/backend/controllers/captain.controller.js"
  click UserController "https://github.com/sujal-github/routeify/blob/main/backend/controllers/user.controller.js"
  click RideController "https://github.com/sujal-github/routeify/blob/main/backend/controllers/ride.controller.js"
  click MapController "https://github.com/sujal-github/routeify/blob/main/backend/controllers/map.controller.js"
  click PaymentController "https://github.com/sujal-github/routeify/blob/main/backend/controllers/payment.controller.js"
  click CaptainService "https://github.com/sujal-github/routeify/blob/main/backend/services/captain.service.js"
  click UserService "https://github.com/sujal-github/routeify/blob/main/backend/services/user.service.js"
  click RideService "https://github.com/sujal-github/routeify/blob/main/backend/services/ride.service.js"
  click MapsService "https://github.com/sujal-github/routeify/blob/main/backend/services/maps.service.js"
  click UserModel "https://github.com/sujal-github/routeify/blob/main/backend/models/user.model.js"
  click CaptainModel "https://github.com/sujal-github/routeify/blob/main/backend/models/captain.model.js"
  click RideModel "https://github.com/sujal-github/routeify/blob/main/backend/models/ride.model.js"
  click BlacklistModel "https://github.com/sujal-github/routeify/blob/main/backend/models/blacklistToken.model.js"
  click SocketSrv "https://github.com/sujal-github/routeify/blob/main/backend/socket.js"
  click Scheduler "https://github.com/sujal-github/routeify/blob/main/backend/utils/scheduler.js"

  %% Styles
  classDef frontend fill:#D0E8FF,stroke:#007BFF,color:#002766
  classDef backend fill:#DFFFE0,stroke:#28A745,color:#165C26
  classDef db fill:#FFE5B4,stroke:#FF8C00,color:#8B4513
  classDef external fill:#E0E0E0,stroke:#808080,color:#404040
```
