# maharabhi01/e-challan architecture

> Architecture diagram of the GitHub repository maharabhi01/e-challan, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/maharabhi01/e-challan
- Repository: https://github.com/maharabhi01/e-challan

## Overview

#### Purpose and Runtime Shape
This is a full-stack e-challan/traffic-violation system. It supports two roles: drivers view vehicles, violations, and payments; officers register and manage violations. The application is split into a Node.js backend API and a React frontend SPA.
- Backend entry point: `final echalllan/Backend/src/server.js`
- Frontend entry point and router: `final echalllan/frontend/src/main.jsx`, `final echalllan/frontend/src/routes/App.jsx`

#### Backend API and Routing Boundary
`server.js` composes the HTTP server and mounts role- and domain-oriented route modules. Routes are the API boundary consumed by the frontend service layer.
- `final echalllan/Backend/src/routes/auth.routes.js`
- `final echalllan/Backend/src/routes/driver.routes.js`
- `final echalllan/Backend/src/routes/officer.routes.js`
- `final echalllan/Backend/src/routes/payment.routes.js`
- `final echalllan/Backend/src/routes/public.routes.js`

#### Identity, Authentication, and Role Access
Authentication is centralized in the auth controller and middleware. The frontend maintains authenticated state and applies route protection before rendering private driver or officer areas.
- Backend: `final echalllan/Backend/src/controllers/auth.controller.js`, `final echalllan/Backend/src/middleware/auth.js`
- Frontend: `final echalllan/frontend/src/context/auth/AuthContext.jsx`, `final echalllan/frontend/src/routes/Protected.jsx`
- User onboarding screens: `final echalllan/frontend/src/pages/RegisterDriver.jsx`, `final echalllan/frontend/src/pages/RegisterOfficer.jsx`

#### Driver Workflow
Drivers operate through a dedicated layout and pages for vehicle records, issued violations, quick fine payment, and payment history. These flows call the backend driver and payment APIs through the shared API client.
- UI: `final echalllan/frontend/src/pages/driver/DriverLayout.jsx`, `final echalllan/frontend/src/pages/driver/MyViolations.jsx`, `final echalllan/frontend/src/pages/driver/PayFineQuick.jsx`
- API ownership: `final echalllan/Backend/src/controllers/driver.controller.js`, `final echalllan/Backend/src/controllers/payment.controller.js`
- Client boundary: `final echalllan/frontend/src/services/api.js`

#### Officer Violation Workflow
Officers use a separate protected layout to create violations and manage existing records. The officer controller and routes form the server-side boundary for enforcement operations.
- UI: `final echalllan/frontend/src/pages/officer/OfficerLayout.jsx`, `final echalllan/frontend/src/pages/officer/AddViolation.jsx`, `final echalllan/frontend/src/pages/officer/ManageViolations.jsx`
- API: `final echalllan/Backend/src/controllers/officer.controller.js`, `final echalllan/Backend/src/routes/officer.routes.js`

#### Persistence and Payment Integration
The backend uses a database connection module and SQL schema as its persistence boundary. Payment processing is isolated behind a payment controller and Razorpay configuration; the frontend exposes Razorpay and UPI payment components.
- Database: `final echalllan/Backend/src/config/db.js`, `final echalllan/Backend/src/models/schema.sql`
- Razorpay: `final echalllan/Backend/src/config/razorpay.config.js`, `final echalllan/Backend/src/controllers/payment.controller.js`
- Payment UI: `final echalllan/frontend/src/components/RazorpayPayment.jsx`, `final echalllan/frontend/src/components/UPIPayment.jsx`

#### Delivery and External Dependencies
The frontend is built as a static SPA, with compiled output under `final echalllan/frontend/dist/`; it must be served separately or by deployment infrastructure. Runtime configuration is environment-driven for both tiers.
- Backend environment: `final echalllan/Backend/.env`
- Frontend environment: `final echalllan/frontend/.env`
- Built frontend artifact: `final echalllan/frontend/dist/index.html`

Main entry points: [`final echalllan/Backend/src/server.js`](https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/Backend/src/server.js) (HTTP server), [`final echalllan/frontend/src/services/api.js`](https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/frontend/src/services/api.js) (API client), [`final echalllan/Backend/src/config/db.js`](https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/Backend/src/config/db.js) (Traffic system database), [`final echalllan/Backend/src/controllers/auth.controller.js`](https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/Backend/src/controllers/auth.controller.js) (Authentication & role checks)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["React SPA"]
  node_spa["SPA bootstrap &amp; router<br/>React entry<br/>[main.jsx]"]
  node_auth_ui["Auth state &amp; guards<br/>React auth<br/>[AuthContext.jsx]"]
  node_onboarding["Driver &amp; officer registration<br/>React pages<br/>[RegisterDriver.jsx]"]
  node_driver_ui["Driver portal<br/>React layout/pages<br/>[DriverLayout.jsx]"]
  node_officer_ui["Officer portal<br/>React layout/pages<br/>[OfficerLayout.jsx]"]
  node_api_client["API client<br/>frontend service<br/>[api.js]"]
  node_payment_ui["Payment components<br/>React payment UI"]
end

subgraph group_backend["Node.js API"]
  node_server["HTTP server<br/>Node.js entry<br/>[server.js]"]
  node_auth_routes["Auth routes<br/>API routes<br/>[auth.routes.js]"]
  node_driver_routes["Driver routes<br/>API routes<br/>[driver.routes.js]"]
  node_officer_routes["Officer routes<br/>API routes<br/>[officer.routes.js]"]
  node_payment_routes["Payment routes<br/>API routes<br/>[payment.routes.js]"]
  node_public_routes["Public routes<br/>API routes<br/>[public.routes.js]"]
  node_auth_service["Authentication &amp; role checks<br/>controller/middleware<br/>[auth.controller.js]"]
  node_driver_service["Driver workflow<br/>controller"]
  node_officer_service["Violation enforcement<br/>controller"]
  node_payment_service["Payment processing<br/>controller"]
end

subgraph group_data["Persistence"]
  node_database[("Traffic system database<br/>SQL database<br/>[db.js]")]
  node_schema["Database schema<br/>SQL schema<br/>[schema.sql]"]
end

subgraph group_external["Payment Provider"]
  node_razorpay{{"Razorpay<br/>payment gateway<br/>[razorpay.config.js]"}}
end

node_spa -->|"provides session"| node_auth_ui
node_spa -->|"routes"| node_onboarding
node_auth_ui -->|"authorizes driver"| node_driver_ui
node_auth_ui -->|"authorizes officer"| node_officer_ui
node_onboarding -->|"registers via"| node_api_client
node_driver_ui -->|"uses"| node_api_client
node_officer_ui -->|"uses"| node_api_client
node_driver_ui -->|"pays fines with"| node_payment_ui
node_payment_ui -->|"creates payment"| node_api_client
node_api_client -->|"HTTP API"| node_server
node_server -->|"mounts"| node_auth_routes
node_server -->|"mounts"| node_driver_routes
node_server -->|"mounts"| node_officer_routes
node_server -->|"mounts"| node_payment_routes
node_server -->|"mounts"| node_public_routes
node_auth_routes -->|"delegates"| node_auth_service
node_driver_routes -->|"delegates"| node_driver_service
node_officer_routes -->|"delegates"| node_officer_service
node_payment_routes -->|"delegates"| node_payment_service
node_driver_routes -.->|"requires access control"| node_auth_service
node_officer_routes -.->|"requires access control"| node_auth_service
node_auth_service -->|"reads users"| node_database
node_driver_service -->|"reads vehicles &amp; violations"| node_database
node_officer_service -->|"creates and manages violations"| node_database
node_payment_service -->|"records payments"| node_database
node_payment_service -->|"processes payment"| node_razorpay
node_schema -.->|"defines"| node_database

click node_spa "https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/frontend/src/main.jsx"
click node_auth_ui "https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/frontend/src/context/auth/AuthContext.jsx"
click node_onboarding "https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/frontend/src/pages/RegisterDriver.jsx"
click node_driver_ui "https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/frontend/src/pages/driver/DriverLayout.jsx"
click node_officer_ui "https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/frontend/src/pages/officer/OfficerLayout.jsx"
click node_api_client "https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/frontend/src/services/api.js"
click node_payment_ui "https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/frontend/src/components/RazorpayPayment.jsx"
click node_server "https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/Backend/src/server.js"
click node_auth_routes "https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/Backend/src/routes/auth.routes.js"
click node_driver_routes "https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/Backend/src/routes/driver.routes.js"
click node_officer_routes "https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/Backend/src/routes/officer.routes.js"
click node_payment_routes "https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/Backend/src/routes/payment.routes.js"
click node_public_routes "https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/Backend/src/routes/public.routes.js"
click node_auth_service "https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/Backend/src/controllers/auth.controller.js"
click node_driver_service "https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/Backend/src/controllers/driver.controller.js"
click node_officer_service "https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/Backend/src/controllers/officer.controller.js"
click node_payment_service "https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/Backend/src/controllers/payment.controller.js"
click node_database "https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/Backend/src/config/db.js"
click node_schema "https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/Backend/src/models/schema.sql"
click node_razorpay "https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/Backend/src/config/razorpay.config.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_spa,node_auth_ui,node_onboarding,node_driver_ui,node_officer_ui,node_api_client,node_payment_ui toneBlue
class node_server,node_auth_routes,node_driver_routes,node_officer_routes,node_payment_routes,node_public_routes,node_auth_service,node_driver_service,node_officer_service,node_payment_service toneAmber
class node_database,node_schema toneMint
class node_razorpay toneRose
```

## Components

### React SPA

- [SPA bootstrap & router](https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/frontend/src/main.jsx): React entry · `final echalllan/frontend/src/main.jsx`
- [Auth state & guards](https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/frontend/src/context/auth/AuthContext.jsx): React auth · `final echalllan/frontend/src/context/auth/AuthContext.jsx`
- [Driver & officer registration](https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/frontend/src/pages/RegisterDriver.jsx): React pages · `final echalllan/frontend/src/pages/RegisterDriver.jsx`
- [Driver portal](https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/frontend/src/pages/driver/DriverLayout.jsx): React layout/pages · `final echalllan/frontend/src/pages/driver/DriverLayout.jsx`
- [Officer portal](https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/frontend/src/pages/officer/OfficerLayout.jsx): React layout/pages · `final echalllan/frontend/src/pages/officer/OfficerLayout.jsx`
- [API client](https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/frontend/src/services/api.js): frontend service · `final echalllan/frontend/src/services/api.js`
- [Payment components](https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/frontend/src/components/RazorpayPayment.jsx): React payment UI · `final echalllan/frontend/src/components/RazorpayPayment.jsx`

### Node.js API

- [HTTP server](https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/Backend/src/server.js): Node.js entry · `final echalllan/Backend/src/server.js`
- [Auth routes](https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/Backend/src/routes/auth.routes.js): API routes · `final echalllan/Backend/src/routes/auth.routes.js`
- [Driver routes](https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/Backend/src/routes/driver.routes.js): API routes · `final echalllan/Backend/src/routes/driver.routes.js`
- [Officer routes](https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/Backend/src/routes/officer.routes.js): API routes · `final echalllan/Backend/src/routes/officer.routes.js`
- [Payment routes](https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/Backend/src/routes/payment.routes.js): API routes · `final echalllan/Backend/src/routes/payment.routes.js`
- [Public routes](https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/Backend/src/routes/public.routes.js): API routes · `final echalllan/Backend/src/routes/public.routes.js`
- [Authentication & role checks](https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/Backend/src/controllers/auth.controller.js): controller/middleware · `final echalllan/Backend/src/controllers/auth.controller.js`
- [Driver workflow](https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/Backend/src/controllers/driver.controller.js): controller · `final echalllan/Backend/src/controllers/driver.controller.js`
- [Violation enforcement](https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/Backend/src/controllers/officer.controller.js): controller · `final echalllan/Backend/src/controllers/officer.controller.js`
- [Payment processing](https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/Backend/src/controllers/payment.controller.js): controller · `final echalllan/Backend/src/controllers/payment.controller.js`

### Persistence

- [Traffic system database](https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/Backend/src/config/db.js): SQL database · Stores users, vehicles, violations, and payments. · `final echalllan/Backend/src/config/db.js`
- [Database schema](https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/Backend/src/models/schema.sql): SQL schema · `final echalllan/Backend/src/models/schema.sql`

### Payment Provider

- [Razorpay](https://github.com/maharabhi01/e-challan/blob/main/final%20echalllan/Backend/src/config/razorpay.config.js): payment gateway · `final echalllan/Backend/src/config/razorpay.config.js`

## Connections

- SPA bootstrap & router → Auth state & guards: provides session
- SPA bootstrap & router → Driver & officer registration: routes
- Auth state & guards → Driver portal: authorizes driver
- Auth state & guards → Officer portal: authorizes officer
- Driver & officer registration → API client: registers via
- Driver portal → API client: uses
- Officer portal → API client: uses
- Driver portal → Payment components: pays fines with
- Payment components → API client: creates payment
- API client → HTTP server: HTTP API
- HTTP server → Auth routes: mounts
- HTTP server → Driver routes: mounts
- HTTP server → Officer routes: mounts
- HTTP server → Payment routes: mounts
- HTTP server → Public routes: mounts
- Auth routes → Authentication & role checks: delegates
- Driver routes → Driver workflow: delegates
- Officer routes → Violation enforcement: delegates
- Payment routes → Payment processing: delegates
- Driver routes → Authentication & role checks: requires access control
- Officer routes → Authentication & role checks: requires access control
- Authentication & role checks → Traffic system database: reads users
- Driver workflow → Traffic system database: reads vehicles & violations
- Violation enforcement → Traffic system database: creates and manages violations
- Payment processing → Traffic system database: records payments
- Payment processing → Razorpay: processes payment
- Database schema → Traffic system database: defines
