# srkhandagale1601-del/vehicle_rental_system architecture

> Architecture diagram of the GitHub repository srkhandagale1601-del/vehicle_rental_system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/srkhandagale1601-del/vehicle_rental_system
- Repository: https://github.com/srkhandagale1601-del/vehicle_rental_system

## Overview

1. **Overall shape**
   - DriveX is a two-part application: a static single-page frontend in `public/` and an Express API backend in `src/`.
   - The browser talks to the backend over REST, and the backend persists state in PostgreSQL.

2. **Entry points and hosting**
   - `server.js` is the runtime entry point and starts the Express app defined in `src/app.js`.
   - The backend also serves the frontend files and vehicle images from `public/`, so the app is effectively self-hosted.

3. **Frontend boundary**
   - `public/drivex.html`, `drivex.css`, and `drivex.js` form a no-framework SPA.
   - The frontend is responsible for rendering the fleet, handling filtering/date selection, calculating pricing, and sending API requests with session cookies included.

4. **API layer**
   - Route modules under `src/routes/` split the backend by domain: auth, vehicles, bookings, and payments.
   - These routes are thin boundaries that map HTTP requests to controller functions.

5. **Controller/service split**
   - Controllers in `src/controllers/` handle request/response concerns.
   - Business logic is pushed into `src/services/`, which keeps auth, vehicle lookup, and booking workflows separated from transport details.

6. **Authentication subsystem**
   - Auth uses session cookies rather than JWTs, with login/signup/logout endpoints under `authRoutes`.
   - Passwords are hashed via utilities in `src/utils/hash.js`, and `authmiddleware.js` protects booking and payment endpoints by requiring a valid session.

7. **Vehicle discovery and availability**
   - `vehicleController`/`vehicleService` handle listing vehicles and filtering by type, seats, and rating.
   - Availability checks are date-range based and depend on booking data to exclude already reserved vehicles.

8. **Booking workflow**
   - Booking logic is centralized in `bookingService.js` and uses PostgreSQL transactions.
   - The service checks for overlapping reservations for both the target vehicle and the current user, using row-level locking to avoid race conditions and double-booking.

9. **Payments subsystem**
   - Payments are modeled as backend records rather than an external gateway integration.
   - `paymentController`/`paymentRoute` record payment details tied to a booking, user, and vehicle, with a transaction ID and payment method.

10. **Persistence and database boundary**
   - `src/config/db.js` sets up the PostgreSQL connection pool used across services.
   - The schema described in the README centers on four tables: users, vehicles, bookings, and payments, with foreign keys linking the booking and payment lifecycle.

11. **Cross-cutting concerns**
   - `src/middlewares/errorHandler.js` provides a centralized failure boundary for API errors.
   - `cors` and cookie-based sessions are important runtime concerns because the frontend and backend can be served from different origins during development.

12. **Utility layer**
   - `src/utils/priceCalculator.js` supports rental pricing calculations.
   - Pricing is partly client-driven: the frontend computes the final amount from duration and vehicle rate, then sends that to the payment endpoint.

13. **Operational characteristics**
   - This is a Node.js/Express backend with PostgreSQL as the single durable store; there are no additional infrastructure dependencies shown.
   - The app is designed for local/dev-friendly usage, with a hardcoded backend port reference in the frontend and a session secret noted in the README.

14. **Diagram takeaway**
   - The most important architecture boundaries are: browser UI, REST API, auth/session gate, booking transaction logic, and PostgreSQL.
   - The key data flow is: browse vehicles → check availability → create booking under transaction → submit payment record → retrieve booking/payment history for the logged-in user.

Main entry points: [`src/app.js`](https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/app.js) (Express app), [`public/drivex.js`](https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/public/drivex.js) (Client app), [`src/routes/paymentRoute.js`](https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/routes/paymentRoute.js) (Payment route), [`src/config/db.js`](https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/config/db.js) (PostgreSQL pool)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Browser App"]
  node_drivex_html["DriveX page<br/>spa shell<br/>[drivex.html]"]
  node_drivex_js["Client app<br/>client logic<br/>[drivex.js]"]
  node_drivex_css["Styles<br/>ui assets<br/>[drivex.css]"]
  node_vehicle_images["Vehicle images<br/>static assets"]
end

subgraph group_backend["Express API"]
  node_server_js["server.js<br/>entrypoint<br/>[server.js]"]
  node_app_js["Express app<br/>[app.js]"]
  node_auth_routes["Auth routes<br/>route boundary<br/>[authRoutes.js]"]
  node_vehicle_routes["Vehicle routes<br/>route boundary<br/>[vehicleRoutes.js]"]
  node_booking_routes["Booking routes<br/>route boundary<br/>[bookingRoutes.js]"]
  node_payment_route["Payment route<br/>route boundary<br/>[paymentRoute.js]"]
  node_auth_controller["Auth controller<br/>[authController.js]"]
  node_vehicle_controller["Vehicle controller"]
  node_booking_controller["Booking controller"]
  node_payment_controller["Payment controller"]
  node_auth_service["Auth service<br/>[authService.js]"]
  node_vehicle_service["Vehicle service<br/>[vehicleService.js]"]
  node_booking_service["Booking service<br/>transactional service<br/>[bookingService.js]"]
  node_hash_utils["Hashing<br/>[hash.js]"]
  node_price_utils["Pricing<br/>[priceCalculator.js]"]
  node_auth_middleware["Session gate<br/>middleware<br/>[authmiddleware.js]"]
  node_error_handler["Error handler<br/>middleware<br/>[errorHandler.js]"]
end

subgraph group_storage["Persistence"]
  node_db_pool[("PostgreSQL pool<br/>db connection<br/>[db.js]")]
end

node_server_js -->|"starts"| node_app_js
node_app_js -->|"mounts"| node_auth_routes
node_app_js -->|"mounts"| node_vehicle_routes
node_app_js -->|"mounts"| node_booking_routes
node_app_js -->|"mounts"| node_payment_route
node_app_js -->|"serves"| node_drivex_html
node_app_js -->|"serves"| node_vehicle_images
node_drivex_html -->|"loads"| node_drivex_js
node_drivex_html -->|"styles"| node_drivex_css
node_drivex_js -->|"fetches"| node_vehicle_routes
node_drivex_js -->|"fetches"| node_booking_routes
node_drivex_js -->|"fetches"| node_payment_route
node_auth_routes -->|"delegates"| node_auth_controller
node_vehicle_routes -->|"delegates"| node_vehicle_controller
node_booking_routes -->|"delegates"| node_booking_controller
node_payment_route -->|"delegates"| node_payment_controller
node_auth_controller -->|"uses"| node_auth_service
node_vehicle_controller -->|"uses"| node_vehicle_service
node_booking_controller -->|"uses"| node_booking_service
node_payment_controller -->|"writes"| node_db_pool
node_auth_service -->|"uses"| node_hash_utils
node_vehicle_service -->|"queries"| node_db_pool
node_booking_service -->|"transacts"| node_db_pool
node_booking_service -.->|"protected by"| node_auth_middleware
node_payment_route -.->|"protected by"| node_auth_middleware
node_app_js -->|"applies"| node_auth_middleware
node_app_js -->|"handles errors"| node_error_handler
node_drivex_js -->|"calculates"| node_price_utils
node_price_utils -.->|"reflects"| node_db_pool

click node_server_js "https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/server.js"
click node_app_js "https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/app.js"
click node_drivex_html "https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/public/drivex.html"
click node_drivex_js "https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/public/drivex.js"
click node_drivex_css "https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/public/drivex.css"
click node_vehicle_images "https://github.com/srkhandagale1601-del/vehicle_rental_system/tree/main/public/images/vehicles"
click node_auth_routes "https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/routes/authRoutes.js"
click node_vehicle_routes "https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/routes/vehicleRoutes.js"
click node_booking_routes "https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/routes/bookingRoutes.js"
click node_payment_route "https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/routes/paymentRoute.js"
click node_auth_controller "https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/controllers/authController.js"
click node_vehicle_controller "https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/controllers/vehicleController.js"
click node_booking_controller "https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/controllers/bookingController.js"
click node_payment_controller "https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/controllers/paymentController.js"
click node_auth_service "https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/services/authService.js"
click node_vehicle_service "https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/services/vehicleService.js"
click node_booking_service "https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/services/bookingService.js"
click node_hash_utils "https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/utils/hash.js"
click node_price_utils "https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/utils/priceCalculator.js"
click node_auth_middleware "https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/middlewares/authmiddleware.js"
click node_error_handler "https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/middlewares/errorHandler.js"
click node_db_pool "https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/config/db.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_drivex_html,node_drivex_js,node_drivex_css,node_vehicle_images toneBlue
class node_server_js,node_app_js,node_auth_routes,node_vehicle_routes,node_booking_routes,node_payment_route,node_auth_controller,node_vehicle_controller,node_booking_controller,node_payment_controller,node_auth_service,node_vehicle_service,node_booking_service,node_hash_utils,node_price_utils,node_auth_middleware,node_error_handler toneAmber
class node_db_pool toneMint
```

## Components

### Browser App

Static SPA assets and client-side rental flow.

- [DriveX page](https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/public/drivex.html): spa shell · Main static page for the rental experience. · `public/drivex.html`
- [Client app](https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/public/drivex.js): client logic · Renders fleet data, filters vehicles, computes pricing, and calls the API with cookies. · `public/drivex.js`
- [Styles](https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/public/drivex.css): ui assets · Presentation layer for the static frontend. · `public/drivex.css`
- [Vehicle images](https://github.com/srkhandagale1601-del/vehicle_rental_system/tree/main/public/images/vehicles): static assets · Served image assets for fleet display. · `public/images/vehicles`

### Express API

HTTP entrypoint, routes, controllers, services, and middleware.

- [server.js](https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/server.js): entrypoint · Starts the Node process and boots the Express app. · `server.js`
- [Express app](https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/app.js): express app · Wires middleware, routes, static hosting, and error handling. · `src/app.js`
- [Auth routes](https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/routes/authRoutes.js): route boundary · Login, signup, and logout endpoints. · `src/routes/authRoutes.js`
- [Vehicle routes](https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/routes/vehicleRoutes.js): route boundary · Vehicle listing and availability endpoints. · `src/routes/vehicleRoutes.js`
- [Booking routes](https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/routes/bookingRoutes.js): route boundary · Booking creation and history endpoints. · `src/routes/bookingRoutes.js`
- [Payment route](https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/routes/paymentRoute.js): route boundary · Payment record endpoints tied to bookings. · `src/routes/paymentRoute.js`
- [Auth controller](https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/controllers/authController.js): controller · Handles auth request/response flow. · `src/controllers/authController.js`
- [Vehicle controller](https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/controllers/vehicleController.js): controller · Serves vehicle discovery and filter responses. · `src/controllers/vehicleController.js`
- [Booking controller](https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/controllers/bookingController.js): controller · Handles reservation requests and booking retrieval. · `src/controllers/bookingController.js`
- [Payment controller](https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/controllers/paymentController.js): controller · Records payment details for completed bookings. · `src/controllers/paymentController.js`
- [Auth service](https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/services/authService.js): service · Signup/login logic and password verification. · `src/services/authService.js`
- [Vehicle service](https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/services/vehicleService.js): service · Vehicle lookup, filtering, and availability checks. · `src/services/vehicleService.js`
- [Booking service](https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/services/bookingService.js): transactional service · Manages reservation workflow with transactional overlap checks and locking. · `src/services/bookingService.js`
- [Hashing](https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/utils/hash.js): utility · Password hashing helper used by auth. · `src/utils/hash.js`
- [Pricing](https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/utils/priceCalculator.js): utility · Rental price calculation helper. · `src/utils/priceCalculator.js`
- [Session gate](https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/middlewares/authmiddleware.js): middleware · Protects booking and payment endpoints using session cookies. · `src/middlewares/authmiddleware.js`
- [Error handler](https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/middlewares/errorHandler.js): middleware · Centralized API failure boundary. · `src/middlewares/errorHandler.js`

### Persistence

PostgreSQL connection and durable rental records.

- [PostgreSQL pool](https://github.com/srkhandagale1601-del/vehicle_rental_system/blob/main/src/config/db.js): db connection · Shared connection pool used by services. · `src/config/db.js`

## Connections

- server.js → Express app: starts · Runtime entrypoint launches the Express application.
- Express app → Auth routes: mounts · Registers auth API routes.
- Express app → Vehicle routes: mounts · Registers vehicle API routes.
- Express app → Booking routes: mounts · Registers booking API routes.
- Express app → Payment route: mounts · Registers payment API routes.
- Express app → DriveX page: serves · Hosts the static frontend shell.
- Express app → Vehicle images: serves · Exposes vehicle image assets.
- DriveX page → Client app: loads · Browser page loads client-side app logic.
- DriveX page → Styles: styles · Page references the stylesheet.
- Client app → Vehicle routes: fetches · Client requests vehicle lists and availability.
- Client app → Booking routes: fetches · Client creates bookings and reads booking data.
- Client app → Payment route: fetches · Client submits payment records.
- Auth routes → Auth controller: delegates · Route handlers pass auth requests to controllers.
- Vehicle routes → Vehicle controller: delegates · Route handlers pass vehicle requests to controllers.
- Booking routes → Booking controller: delegates · Route handlers pass booking requests to controllers.
- Payment route → Payment controller: delegates · Route handlers pass payment requests to controllers.
- Auth controller → Auth service: uses · Controller defers auth business logic.
- Vehicle controller → Vehicle service: uses · Controller defers vehicle lookup logic.
- Booking controller → Booking service: uses · Controller defers booking workflow logic.
- Payment controller → PostgreSQL pool: writes · Payment records are persisted in PostgreSQL.
- Auth service → Hashing: uses · Password hashing and verification helper.
- Vehicle service → PostgreSQL pool: queries · Reads vehicles and booking-backed availability from the database.
- Booking service → PostgreSQL pool: transacts · Uses transactions and locking for reservation integrity.
- Booking service → Session gate: protected by · Booking operations require a valid session.
- Payment route → Session gate: protected by · Payment endpoints require a valid session.
- Express app → Session gate: applies · Express app installs session-based protection.
- Express app → Error handler: handles errors · Centralized request failure handling.
- Client app → Pricing: calculates · Client pricing mirrors rental duration and rate calculations.
- Pricing → PostgreSQL pool: reflects · Pricing uses persisted vehicle data and booking context.
