How shankar-va/evchargemate works
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: booking.controller.js HTTP controllers · api.js API client · App.jsx SPA entry & routes · booking.service.js Booking lifecycle
Components 21
React SPA
- SPA entry & routes
frontend/src/App.jsx - Auth state
frontend/src/context/AuthContext.jsx - API client
frontend/src/services/api.js - Discovery & dashboard
frontend/src/pages/Stations/Stations.jsx - Admin operations
frontend/src/pages/Admin/AdminStations.jsx - Station portal · Validates a presented QR credential to begin charging.
frontend/src/pages/StationPortal/StationPortal.jsx - Route map
frontend/src/components/Map/RouteMap.jsx
Express API
- API server
backend/src/server.js - Domain routes · User, booking, station, QR, and administration endpoints.
backend/src/routes/booking.routes.js - Auth & error boundary
backend/src/middleware/auth.middleware.js - HTTP controllers
backend/src/controllers/booking.controller.js
Core domain
- Identity & roles · Supports user/admin sessions and station-secret authentication.
backend/src/config/passport.js - Booking lifecycle · Creates payment-backed bookings and handles cancellation/refunds.
backend/src/services/booking/booking.service.js - Payment processing
backend/src/services/booking/payment.services.js - Station inventory & slots · Manages capacity, availability, and generated schedules.
backend/src/controllers/station.controller.js - Geospatial discovery · Combines local stations with external nearby-station data.
backend/src/services/geo.service/Ev-stations/nearByMongoStations.js - QR credentials · Generates encrypted booking credentials and stores artifacts.
backend/src/services/qr.service.js/genQr.js - MongoDB · Persists users, admins, stations, slots, bookings, and payments.
backend/src/database/mongodb.js
External services
- Razorpay
- Open Charge Map
- Cloudinary
backend/src/config/cloudinary.js
Connections 27
- 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