How srkhandagale1601-del/vehicle_rental_system works
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: app.js Express app · drivex.js Client app · paymentRoute.js Payment route · db.js PostgreSQL pool
Components 22
Browser App
Static SPA assets and client-side rental flow.
- DriveX page · Main static page for the rental experience.
public/drivex.html - Client app · Renders fleet data, filters vehicles, computes pricing, and calls the API with cookies.
public/drivex.js - Styles · Presentation layer for the static frontend.
public/drivex.css - Vehicle images · Served image assets for fleet display.
public/images/vehicles
Express API
HTTP entrypoint, routes, controllers, services, and middleware.
- server.js · Starts the Node process and boots the Express app.
server.js - Express app · Wires middleware, routes, static hosting, and error handling.
src/app.js - Auth routes · Login, signup, and logout endpoints.
src/routes/authRoutes.js - Vehicle routes · Vehicle listing and availability endpoints.
src/routes/vehicleRoutes.js - Booking routes · Booking creation and history endpoints.
src/routes/bookingRoutes.js - Payment route · Payment record endpoints tied to bookings.
src/routes/paymentRoute.js - Auth controller · Handles auth request/response flow.
src/controllers/authController.js - Vehicle controller · Serves vehicle discovery and filter responses.
src/controllers/vehicleController.js - Booking controller · Handles reservation requests and booking retrieval.
src/controllers/bookingController.js - Payment controller · Records payment details for completed bookings.
src/controllers/paymentController.js - Auth service · Signup/login logic and password verification.
src/services/authService.js - Vehicle service · Vehicle lookup, filtering, and availability checks.
src/services/vehicleService.js - Booking service · Manages reservation workflow with transactional overlap checks and locking.
src/services/bookingService.js - Hashing · Password hashing helper used by auth.
src/utils/hash.js - Pricing · Rental price calculation helper.
src/utils/priceCalculator.js - Session gate · Protects booking and payment endpoints using session cookies.
src/middlewares/authmiddleware.js - Error handler · Centralized API failure boundary.
src/middlewares/errorHandler.js
Persistence
PostgreSQL connection and durable rental records.
- PostgreSQL pool · Shared connection pool used by services.
src/config/db.js
Connections 29
- 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.