# shankar-va/evchargemate architecture

> Architecture diagram of the GitHub repository shankar-va/evchargemate, 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/shankar-va/evchargemate
- Repository: https://github.com/shankar-va/evchargemate

## Overview

#### Purpose and Entry Points
EV-ChargeMate is a full-stack EV charging workflow: users find stations, reserve slots, pay, receive a QR credential, and present it to a station portal to begin charging. Admins manage stations and monitor bookings.

Frontend startup and route composition are centered in `frontend/src/main.jsx`, `frontend/src/App.jsx`, and `frontend/src/app.js`. The Express API starts in `backend/src/server.js`.

#### Client Applications
The React/Vite SPA provides distinct user, admin, and station-facing experiences. Authentication state is shared through `frontend/src/context/AuthContext.jsx`, while backend requests are centralized in `frontend/src/services/api.js`.

Primary screens are:
- User discovery/dashboard: `frontend/src/pages/Stations/Stations.jsx`, `frontend/src/pages/Dashboard/Dashboard.jsx`
- Administrative station operations: `frontend/src/pages/Admin/AdminStations.jsx`, `frontend/src/pages/AdminDashboard/AdminDashboard.jsx`
- Hardware simulation: `frontend/src/pages/StationPortal/StationPortal.jsx`

The route map visualizes station/route data through `frontend/src/components/Map/RouteMap.jsx`.

#### API and Access Boundary
Express routes expose the domain API for users, stations, bookings, payments, QR verification, and administration: `backend/src/routes/user.routes.js`, `backend/src/routes/booking.routes.js`, `backend/src/routes/station.routes.js`, and `backend/src/routes/qr.routes.js`.

Controllers form the HTTP orchestration layer, notably `backend/src/controllers/auth.controller.js`, `backend/src/controllers/booking.controller.js`, and `backend/src/controllers/payment.controller.js`. Authentication/authorization and failure normalization are cross-cutting middleware in `backend/src/middleware/auth.middleware.js` and `backend/src/middleware/error.middleware.js`.

#### Identity and Roles
Users can authenticate through JWT-backed sessions and Google OAuth integration. Passport configuration resides in `backend/src/config/passport.js`; token creation is in `backend/src/utils/generateToken.js`. JWTs are intended for HTTP-only, cross-site secure cookies.

Separate persistence models support user and admin roles: `backend/src/models/user.js` and `backend/src/models/admin.js`. Station portal authentication uses station identity/secret validation rather than the normal user session flow.

#### Booking, Payment, and Charging Lifecycle
The core transaction is coordinated by booking services: `backend/src/services/booking/booking.service.js` and `backend/src/services/booking/payment.services.js`. It transitions a selected station slot into a payment-backed booking, verifies Razorpay payment completion, then enables QR issuance.

Persistent lifecycle records are represented by `backend/src/models/bookings.js`, `backend/src/models/payment.js`, and `backend/src/models/slot.js`. The station portal submits scanned or pasted encrypted QR data through the QR API; successful validation confirms the booking and starts the simulated charging session. Cancellation can trigger refund handling.

#### Station and Geospatial Domain
Charging station inventory and availability are backed by `backend/src/models/chargingStation.js`, administered through `backend/src/controllers/admin.controller.js` and `backend/src/controllers/station.controller.js`. Slot generation supports station capacity/scheduling via `backend/src/utils/slotGenerator.js`.

Station discovery can combine locally stored MongoDB stations with external Open Charge Map data: `backend/src/services/geo.service/Ev-stations/nearByMongoStations.js`, `backend/src/services/geo.service/Ev-stations/openChargeMap.service.js`, and `backend/src/services/geo.service/save.station.todb.js`. Route/direction calculations are separated under `backend/src/services/geo.service/Directions/`.

#### QR, Storage, and Infrastructure
QR generation and associated artifact handling are isolated in `backend/src/services/qr.service.js/genQr.js` and `backend/src/services/qr.service.js/cloudinary.service.js`, with Cloudinary configuration in `backend/src/config/cloudinary.js`.

MongoDB connectivity is established by `backend/src/database/mongodb.js`. External dependencies include Razorpay for payments, Google OAuth, Cloudinary, and Open Charge Map. The React SPA is deployed to Vercel (`vercel.json`), while the Node/Express API is intended for Render; runtime URLs and secrets are environment-driven.

Main entry points: [`backend/src/controllers/booking.controller.js`](https://github.com/shankar-va/evchargemate/blob/main/backend/src/controllers/booking.controller.js) (HTTP controllers), [`frontend/src/services/api.js`](https://github.com/shankar-va/evchargemate/blob/main/frontend/src/services/api.js) (API client), [`frontend/src/App.jsx`](https://github.com/shankar-va/evchargemate/blob/main/frontend/src/App.jsx) (SPA entry & routes), [`backend/src/services/booking/booking.service.js`](https://github.com/shankar-va/evchargemate/blob/main/backend/src/services/booking/booking.service.js) (Booking lifecycle)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["React SPA"]
  node_spa_entry["SPA entry &amp; routes<br/>React/Vite<br/>[App.jsx]"]
  node_auth_context["Auth state<br/>React context<br/>[AuthContext.jsx]"]
  node_api_client["API client<br/>HTTP client<br/>[api.js]"]
  node_user_experience["Discovery &amp; dashboard<br/>user screens<br/>[Stations.jsx]"]
  node_admin_experience["Admin operations<br/>admin screens<br/>[AdminStations.jsx]"]
  node_station_portal["Station portal<br/>hardware simulation<br/>[StationPortal.jsx]"]
  node_route_map["Route map<br/>map component<br/>[RouteMap.jsx]"]
end

subgraph group_api["Express API"]
  node_express_server["API server<br/>Express<br/>[server.js]"]
  node_api_routes["Domain routes<br/>HTTP routes<br/>[booking.routes.js]"]
  node_access_middleware["Auth &amp; error boundary<br/>middleware<br/>[auth.middleware.js]"]
  node_controllers["HTTP controllers<br/>orchestration"]
end

subgraph group_domain["Core domain"]
  node_identity["Identity &amp; roles<br/>JWT / OAuth<br/>[passport.js]"]
  node_booking_service["Booking lifecycle<br/>domain service<br/>[booking.service.js]"]
  node_payment_service["Payment processing<br/>payment service"]
  node_station_domain["Station inventory &amp; slots<br/>station domain"]
  node_geo_discovery["Geospatial discovery<br/>geo service"]
  node_qr_service["QR credentials<br/>QR service<br/>[genQr.js]"]
  node_mongodb[("MongoDB<br/>database<br/>[mongodb.js]")]
end

subgraph group_integrations["External services"]
  node_razorpay["Razorpay<br/>payment gateway"]
  node_open_charge_map["Open Charge Map<br/>station data API"]
  node_cloudinary["Cloudinary<br/>artifact storage<br/>[cloudinary.js]"]
end

node_spa_entry -->|"initializes"| node_auth_context
node_spa_entry -->|"routes to"| node_user_experience
node_spa_entry -->|"routes to"| node_admin_experience
node_spa_entry -->|"routes to"| node_station_portal
node_user_experience -->|"visualizes"| node_route_map
node_auth_context -->|"supplies session"| node_api_client
node_user_experience -->|"uses"| node_api_client
node_admin_experience -->|"uses"| node_api_client
node_station_portal -->|"submits QR"| node_api_client
node_api_client -->|"HTTP requests"| node_express_server
node_express_server -->|"mounts"| node_api_routes
node_api_routes -->|"passes through"| node_access_middleware
node_access_middleware -->|"authorizes"| node_controllers
node_controllers -->|"authenticates"| node_identity
node_controllers -->|"coordinates"| node_booking_service
node_controllers -->|"manages"| node_station_domain
node_controllers -->|"queries"| node_geo_discovery
node_controllers -->|"issues / verifies"| node_qr_service
node_identity -->|"reads roles"| node_mongodb
node_booking_service -->|"charges / refunds"| node_payment_service
node_booking_service -->|"enables issuance"| node_qr_service
node_booking_service -->|"persists lifecycle"| node_mongodb
node_station_domain -->|"persists stations and slots"| node_mongodb
node_geo_discovery -->|"reads / saves stations"| node_mongodb
node_geo_discovery -->|"fetches nearby data"| node_open_charge_map
node_payment_service -->|"verifies payment"| node_razorpay
node_qr_service -->|"stores artifacts"| node_cloudinary

click node_spa_entry "https://github.com/shankar-va/evchargemate/blob/main/frontend/src/App.jsx"
click node_auth_context "https://github.com/shankar-va/evchargemate/blob/main/frontend/src/context/AuthContext.jsx"
click node_api_client "https://github.com/shankar-va/evchargemate/blob/main/frontend/src/services/api.js"
click node_user_experience "https://github.com/shankar-va/evchargemate/blob/main/frontend/src/pages/Stations/Stations.jsx"
click node_admin_experience "https://github.com/shankar-va/evchargemate/blob/main/frontend/src/pages/Admin/AdminStations.jsx"
click node_station_portal "https://github.com/shankar-va/evchargemate/blob/main/frontend/src/pages/StationPortal/StationPortal.jsx"
click node_route_map "https://github.com/shankar-va/evchargemate/blob/main/frontend/src/components/Map/RouteMap.jsx"
click node_express_server "https://github.com/shankar-va/evchargemate/blob/main/backend/src/server.js"
click node_api_routes "https://github.com/shankar-va/evchargemate/blob/main/backend/src/routes/booking.routes.js"
click node_access_middleware "https://github.com/shankar-va/evchargemate/blob/main/backend/src/middleware/auth.middleware.js"
click node_controllers "https://github.com/shankar-va/evchargemate/blob/main/backend/src/controllers/booking.controller.js"
click node_identity "https://github.com/shankar-va/evchargemate/blob/main/backend/src/config/passport.js"
click node_booking_service "https://github.com/shankar-va/evchargemate/blob/main/backend/src/services/booking/booking.service.js"
click node_payment_service "https://github.com/shankar-va/evchargemate/blob/main/backend/src/services/booking/payment.services.js"
click node_station_domain "https://github.com/shankar-va/evchargemate/blob/main/backend/src/controllers/station.controller.js"
click node_geo_discovery "https://github.com/shankar-va/evchargemate/blob/main/backend/src/services/geo.service/Ev-stations/nearByMongoStations.js"
click node_qr_service "https://github.com/shankar-va/evchargemate/blob/main/backend/src/services/qr.service.js/genQr.js"
click node_mongodb "https://github.com/shankar-va/evchargemate/blob/main/backend/src/database/mongodb.js"
click node_cloudinary "https://github.com/shankar-va/evchargemate/blob/main/backend/src/config/cloudinary.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_entry,node_auth_context,node_api_client,node_user_experience,node_admin_experience,node_station_portal,node_route_map toneBlue
class node_express_server,node_api_routes,node_access_middleware,node_controllers toneAmber
class node_identity,node_booking_service,node_payment_service,node_station_domain,node_geo_discovery,node_qr_service,node_mongodb toneMint
class node_razorpay,node_open_charge_map,node_cloudinary toneRose
```

## Components

### React SPA

- [SPA entry & routes](https://github.com/shankar-va/evchargemate/blob/main/frontend/src/App.jsx): React/Vite · `frontend/src/App.jsx`
- [Auth state](https://github.com/shankar-va/evchargemate/blob/main/frontend/src/context/AuthContext.jsx): React context · `frontend/src/context/AuthContext.jsx`
- [API client](https://github.com/shankar-va/evchargemate/blob/main/frontend/src/services/api.js): HTTP client · `frontend/src/services/api.js`
- [Discovery & dashboard](https://github.com/shankar-va/evchargemate/blob/main/frontend/src/pages/Stations/Stations.jsx): user screens · `frontend/src/pages/Stations/Stations.jsx`
- [Admin operations](https://github.com/shankar-va/evchargemate/blob/main/frontend/src/pages/Admin/AdminStations.jsx): admin screens · `frontend/src/pages/Admin/AdminStations.jsx`
- [Station portal](https://github.com/shankar-va/evchargemate/blob/main/frontend/src/pages/StationPortal/StationPortal.jsx): hardware simulation · Validates a presented QR credential to begin charging. · `frontend/src/pages/StationPortal/StationPortal.jsx`
- [Route map](https://github.com/shankar-va/evchargemate/blob/main/frontend/src/components/Map/RouteMap.jsx): map component · `frontend/src/components/Map/RouteMap.jsx`

### Express API

- [API server](https://github.com/shankar-va/evchargemate/blob/main/backend/src/server.js): Express · `backend/src/server.js`
- [Domain routes](https://github.com/shankar-va/evchargemate/blob/main/backend/src/routes/booking.routes.js): HTTP routes · User, booking, station, QR, and administration endpoints. · `backend/src/routes/booking.routes.js`
- [Auth & error boundary](https://github.com/shankar-va/evchargemate/blob/main/backend/src/middleware/auth.middleware.js): middleware · `backend/src/middleware/auth.middleware.js`
- [HTTP controllers](https://github.com/shankar-va/evchargemate/blob/main/backend/src/controllers/booking.controller.js): orchestration · `backend/src/controllers/booking.controller.js`

### Core domain

- [Identity & roles](https://github.com/shankar-va/evchargemate/blob/main/backend/src/config/passport.js): JWT / OAuth · Supports user/admin sessions and station-secret authentication. · `backend/src/config/passport.js`
- [Booking lifecycle](https://github.com/shankar-va/evchargemate/blob/main/backend/src/services/booking/booking.service.js): domain service · Creates payment-backed bookings and handles cancellation/refunds. · `backend/src/services/booking/booking.service.js`
- [Payment processing](https://github.com/shankar-va/evchargemate/blob/main/backend/src/services/booking/payment.services.js): payment service · `backend/src/services/booking/payment.services.js`
- [Station inventory & slots](https://github.com/shankar-va/evchargemate/blob/main/backend/src/controllers/station.controller.js): station domain · Manages capacity, availability, and generated schedules. · `backend/src/controllers/station.controller.js`
- [Geospatial discovery](https://github.com/shankar-va/evchargemate/blob/main/backend/src/services/geo.service/Ev-stations/nearByMongoStations.js): geo service · Combines local stations with external nearby-station data. · `backend/src/services/geo.service/Ev-stations/nearByMongoStations.js`
- [QR credentials](https://github.com/shankar-va/evchargemate/blob/main/backend/src/services/qr.service.js/genQr.js): QR service · Generates encrypted booking credentials and stores artifacts. · `backend/src/services/qr.service.js/genQr.js`
- [MongoDB](https://github.com/shankar-va/evchargemate/blob/main/backend/src/database/mongodb.js): database · Persists users, admins, stations, slots, bookings, and payments. · `backend/src/database/mongodb.js`

### External services

- **Razorpay**: payment gateway
- **Open Charge Map**: station data API
- [Cloudinary](https://github.com/shankar-va/evchargemate/blob/main/backend/src/config/cloudinary.js): artifact storage · `backend/src/config/cloudinary.js`

## Connections

- SPA entry & routes → Auth state: initializes
- SPA entry & routes → Discovery & dashboard: routes to
- SPA entry & routes → Admin operations: routes to
- SPA entry & routes → Station portal: routes to
- Discovery & dashboard → Route map: visualizes
- Auth state → API client: supplies session
- Discovery & dashboard → API client: uses
- Admin operations → API client: uses
- Station portal → API client: submits QR
- API client → API server: HTTP requests
- API server → Domain routes: mounts
- Domain routes → Auth & error boundary: passes through
- Auth & error boundary → HTTP controllers: authorizes
- HTTP controllers → Identity & roles: authenticates
- HTTP controllers → Booking lifecycle: coordinates
- HTTP controllers → Station inventory & slots: manages
- HTTP controllers → Geospatial discovery: queries
- HTTP controllers → QR credentials: issues / verifies
- Identity & roles → MongoDB: reads roles
- Booking lifecycle → Payment processing: charges / refunds
- Booking lifecycle → QR credentials: enables issuance
- Booking lifecycle → MongoDB: persists lifecycle
- Station inventory & slots → MongoDB: persists stations and slots
- Geospatial discovery → MongoDB: reads / saves stations
- Geospatial discovery → Open Charge Map: fetches nearby data
- Payment processing → Razorpay: verifies payment
- QR credentials → Cloudinary: stores artifacts
