# smahmud10/vehicle-rental-system architecture

> Architecture diagram of the GitHub repository smahmud10/vehicle-rental-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/smahmud10/vehicle-rental-system
- Repository: https://github.com/smahmud10/vehicle-rental-system

## Overview

1. **Overall shape**
   - This is a single **Node.js + Express + TypeScript REST API** for a vehicle rental system.
   - The codebase is organized by **feature modules** rather than by technical layer alone: `auth`, `users`, `vehicles`, and `bookings`.

2. **Application entrypoint**
   - `src/server.ts` is the bootstrap point.
   - It is responsible for creating the Express app, wiring middleware and routes, and starting the HTTP server.
   - The app is deployed on **Vercel** as indicated by `src/vercel.json` and the README live URL.

3. **Request routing boundary**
   - Each domain has its own router/controller/service trio:
     - `src/modules/auth/auth.router.ts`
     - `src/modules/users/user.router.ts`
     - `src/modules/vehicles/vehicle.router.ts`
     - `src/modules/booking/booking.touter.ts` (likely intended to be `booking.router.ts`)
   - These routers define the API surface under `/api/v1/...` and keep route-specific concerns out of the server bootstrap.

4. **Controller layer**
   - Controllers handle HTTP concerns: request parsing, response formatting, and status codes.
   - They act as the boundary between Express and business logic.
   - This keeps the route definitions thin and makes the services reusable outside HTTP if needed.

5. **Service layer**
   - `*.service.ts` files contain the application logic for each domain.
   - This is where the important behavior likely lives: user signup/signin, vehicle CRUD, booking creation/update, and availability calculations.
   - The README’s “availability tracking” feature strongly suggests booking logic affects vehicle state or query results in the service layer.

6. **Data access and database boundary**
   - `src/config/db.ts` and `src/config/index.ts` are the central configuration entry points.
   - The system uses **PostgreSQL**, and the services likely communicate with it directly through this config layer.
   - There is no separate repository/ORM folder in the tree, so the persistence boundary appears to be kept close to the service/config layer.

7. **Authentication flow**
   - `src/modules/auth` handles registration and login.
   - `src/middleware/auth.ts` is the protection layer for authenticated routes, enforcing **JWT-based authentication**.
   - The auth module issues tokens; the middleware validates them and gates protected endpoints like users, vehicles, and bookings as needed.

8. **Shared Express typing**
   - `src/types/express/index.d.ts` indicates custom Express type augmentation.
   - This usually means the app attaches auth-related context to the request object, such as a decoded JWT payload or user identity.
   - That is an important architecture clue because it connects the auth middleware to downstream controllers/services.

9. **Feature responsibilities**
   - **Auth**: signup/signin and token issuance.
   - **Users**: administrative or CRUD operations on users.
   - **Vehicles**: create/read/update/delete vehicles.
   - **Bookings**: create and update bookings, likely with availability checks against vehicles and existing reservations.
   - The API is cleanly split so each domain owns its own rules and endpoints.

10. **Infrastructure and deployment**
   - The system is stateless at the API layer, which fits **Vercel** deployment and JWT auth.
   - Persistent state lives in **PostgreSQL**, not in-memory server state.
   - This means horizontal scaling is driven by the database-backed design plus token-based authentication.

11. **Likely data flow**
   - Client request → Express route → optional JWT middleware → controller → service → PostgreSQL → service → controller → HTTP response.
   - The main cross-module dependency is that booking logic probably reads vehicle/user data to validate availability and ownership constraints.

12. **Architecture diagram takeaway**
   - Draw this repo as a **layered, module-per-domain API**:
     - HTTP edge at the top
     - Auth middleware as a cross-cutting guard
     - Controllers as request adapters
     - Services as domain logic
     - PostgreSQL as the persistence backend
   - Keep `auth` separate from the protected resource modules, with shared Express typing bridging middleware and request handlers.

Main entry points: [`src/server.ts`](https://github.com/smahmud10/vehicle-rental-system/blob/main/src/server.ts) (Server), [`src/modules/booking/booking.services.ts`](https://github.com/smahmud10/vehicle-rental-system/blob/main/src/modules/booking/booking.services.ts) (Bookings Service), [`src/config/db.ts`](https://github.com/smahmud10/vehicle-rental-system/blob/main/src/config/db.ts) (DB), [`src/modules/users/user.service.ts`](https://github.com/smahmud10/vehicle-rental-system/blob/main/src/modules/users/user.service.ts) (Users Service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_infra["Infrastructure"]
  node_server["Server<br/>Express bootstrap<br/>[server.ts]"]
  node_config_index["Config<br/>[index.ts]"]
  node_db_config[("DB<br/>PostgreSQL config<br/>[db.ts]")]
  node_auth_middleware{{"JWT Guard<br/>auth middleware<br/>[auth.ts]"}}
  node_express_types["Express Types<br/>type augmentation<br/>[index.d.ts]"]
end

subgraph group_auth["Auth"]
  node_auth_router["Auth Route<br/>router<br/>[auth.router.ts]"]
  node_auth_controller["Auth Ctrl<br/>controller<br/>[auth.controller.ts]"]
  node_auth_service["Auth Service<br/>[auth.services.ts]"]
end

subgraph group_users["Users"]
  node_users_router["Users Route<br/>router<br/>[user.router.ts]"]
  node_users_controller["Users Ctrl<br/>controller<br/>[user.controller.ts]"]
  node_users_service["Users Service<br/>[user.service.ts]"]
end

subgraph group_vehicles["Vehicles"]
  node_vehicles_router["Vehicles Route<br/>router<br/>[vehicle.router.ts]"]
  node_vehicles_controller["Vehicles Ctrl<br/>controller"]
  node_vehicles_service["Vehicles Service<br/>[vehicle.service.ts]"]
end

subgraph group_bookings["Bookings"]
  node_bookings_router["Bookings Route<br/>router<br/>[booking.touter.ts]"]
  node_bookings_controller["Bookings Ctrl<br/>controller"]
  node_bookings_service["Bookings Service"]
end

node_server -->|"loads"| node_config_index
node_server -->|"uses"| node_auth_middleware
node_server -->|"mounts"| node_auth_router
node_server -->|"mounts"| node_users_router
node_server -->|"mounts"| node_vehicles_router
node_server -->|"mounts"| node_bookings_router
node_auth_router -->|"delegates"| node_auth_controller
node_auth_controller -->|"calls"| node_auth_service
node_auth_service -->|"reads/writes"| node_db_config
node_users_router -->|"delegates"| node_users_controller
node_users_controller -->|"calls"| node_users_service
node_users_service -->|"reads/writes"| node_db_config
node_vehicles_router -->|"delegates"| node_vehicles_controller
node_vehicles_controller -->|"calls"| node_vehicles_service
node_vehicles_service -->|"reads/writes"| node_db_config
node_bookings_router -->|"delegates"| node_bookings_controller
node_bookings_controller -->|"calls"| node_bookings_service
node_bookings_service -->|"reads/writes"| node_db_config
node_auth_middleware -.->|"extends"| node_express_types
node_bookings_service -.->|"checks"| node_vehicles_service
node_bookings_service -.->|"verifies"| node_users_service

click node_server "https://github.com/smahmud10/vehicle-rental-system/blob/main/src/server.ts"
click node_config_index "https://github.com/smahmud10/vehicle-rental-system/blob/main/src/config/index.ts"
click node_db_config "https://github.com/smahmud10/vehicle-rental-system/blob/main/src/config/db.ts"
click node_auth_middleware "https://github.com/smahmud10/vehicle-rental-system/blob/main/src/middleware/auth.ts"
click node_express_types "https://github.com/smahmud10/vehicle-rental-system/blob/main/src/types/express/index.d.ts"
click node_auth_router "https://github.com/smahmud10/vehicle-rental-system/blob/main/src/modules/auth/auth.router.ts"
click node_auth_controller "https://github.com/smahmud10/vehicle-rental-system/blob/main/src/modules/auth/auth.controller.ts"
click node_auth_service "https://github.com/smahmud10/vehicle-rental-system/blob/main/src/modules/auth/auth.services.ts"
click node_users_router "https://github.com/smahmud10/vehicle-rental-system/blob/main/src/modules/users/user.router.ts"
click node_users_controller "https://github.com/smahmud10/vehicle-rental-system/blob/main/src/modules/users/user.controller.ts"
click node_users_service "https://github.com/smahmud10/vehicle-rental-system/blob/main/src/modules/users/user.service.ts"
click node_vehicles_router "https://github.com/smahmud10/vehicle-rental-system/blob/main/src/modules/vehicles/vehicle.router.ts"
click node_vehicles_controller "https://github.com/smahmud10/vehicle-rental-system/blob/main/src/modules/vehicles/vehicle.controller.ts"
click node_vehicles_service "https://github.com/smahmud10/vehicle-rental-system/blob/main/src/modules/vehicles/vehicle.service.ts"
click node_bookings_router "https://github.com/smahmud10/vehicle-rental-system/blob/main/src/modules/booking/booking.touter.ts"
click node_bookings_controller "https://github.com/smahmud10/vehicle-rental-system/blob/main/src/modules/booking/booking.controller.ts"
click node_bookings_service "https://github.com/smahmud10/vehicle-rental-system/blob/main/src/modules/booking/booking.services.ts"

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_server,node_config_index,node_db_config,node_auth_middleware,node_express_types toneBlue
class node_auth_router,node_auth_controller,node_auth_service toneAmber
class node_users_router,node_users_controller,node_users_service toneMint
class node_vehicles_router,node_vehicles_controller,node_vehicles_service toneRose
class node_bookings_router,node_bookings_controller,node_bookings_service toneIndigo
```

## Components

### Infrastructure

Bootstrap, configuration, middleware, and shared types.

- [Server](https://github.com/smahmud10/vehicle-rental-system/blob/main/src/server.ts): Express bootstrap · Creates the app, wires routes and middleware, and starts the HTTP server. · `src/server.ts`
- [Config](https://github.com/smahmud10/vehicle-rental-system/blob/main/src/config/index.ts): app config · Central configuration entry point for environment and runtime settings. · `src/config/index.ts`
- [DB](https://github.com/smahmud10/vehicle-rental-system/blob/main/src/config/db.ts): PostgreSQL config · Database connection boundary used by the service layer. · `src/config/db.ts`
- [JWT Guard](https://github.com/smahmud10/vehicle-rental-system/blob/main/src/middleware/auth.ts): auth middleware · Protects authenticated routes by validating JWTs. · `src/middleware/auth.ts`
- [Express Types](https://github.com/smahmud10/vehicle-rental-system/blob/main/src/types/express/index.d.ts): type augmentation · Custom Express request typing for shared auth context. · `src/types/express/index.d.ts`

### Auth

Registration, login, and token issuance.

- [Auth Route](https://github.com/smahmud10/vehicle-rental-system/blob/main/src/modules/auth/auth.router.ts): router · Exposes auth endpoints under the API namespace. · `src/modules/auth/auth.router.ts`
- [Auth Ctrl](https://github.com/smahmud10/vehicle-rental-system/blob/main/src/modules/auth/auth.controller.ts): controller · Handles auth request parsing and HTTP responses. · `src/modules/auth/auth.controller.ts`
- [Auth Service](https://github.com/smahmud10/vehicle-rental-system/blob/main/src/modules/auth/auth.services.ts): service · Implements signup, signin, and token issuance logic. · `src/modules/auth/auth.services.ts`

### Users

User management feature module.

- [Users Route](https://github.com/smahmud10/vehicle-rental-system/blob/main/src/modules/users/user.router.ts): router · Exposes user endpoints under the API namespace. · `src/modules/users/user.router.ts`
- [Users Ctrl](https://github.com/smahmud10/vehicle-rental-system/blob/main/src/modules/users/user.controller.ts): controller · Handles user request/response concerns. · `src/modules/users/user.controller.ts`
- [Users Service](https://github.com/smahmud10/vehicle-rental-system/blob/main/src/modules/users/user.service.ts): service · Implements user CRUD and domain rules. · `src/modules/users/user.service.ts`

### Vehicles

Vehicle management feature module.

- [Vehicles Route](https://github.com/smahmud10/vehicle-rental-system/blob/main/src/modules/vehicles/vehicle.router.ts): router · Exposes vehicle endpoints under the API namespace. · `src/modules/vehicles/vehicle.router.ts`
- [Vehicles Ctrl](https://github.com/smahmud10/vehicle-rental-system/blob/main/src/modules/vehicles/vehicle.controller.ts): controller · Handles vehicle request/response concerns. · `src/modules/vehicles/vehicle.controller.ts`
- [Vehicles Service](https://github.com/smahmud10/vehicle-rental-system/blob/main/src/modules/vehicles/vehicle.service.ts): service · Implements vehicle CRUD and related rules. · `src/modules/vehicles/vehicle.service.ts`

### Bookings

Reservation and availability feature module.

- [Bookings Route](https://github.com/smahmud10/vehicle-rental-system/blob/main/src/modules/booking/booking.touter.ts): router · Exposes booking endpoints under the API namespace. · `src/modules/booking/booking.touter.ts`
- [Bookings Ctrl](https://github.com/smahmud10/vehicle-rental-system/blob/main/src/modules/booking/booking.controller.ts): controller · Handles booking request/response concerns. · `src/modules/booking/booking.controller.ts`
- [Bookings Service](https://github.com/smahmud10/vehicle-rental-system/blob/main/src/modules/booking/booking.services.ts): service · Implements booking creation, updates, and availability logic. · `src/modules/booking/booking.services.ts`

## Connections

- Server → Config: loads · Bootstraps runtime configuration before wiring the app.
- Server → JWT Guard: uses · Registers JWT protection for guarded routes.
- Server → Auth Route: mounts · Attaches auth endpoints to the Express app.
- Server → Users Route: mounts · Attaches user endpoints to the Express app.
- Server → Vehicles Route: mounts · Attaches vehicle endpoints to the Express app.
- Server → Bookings Route: mounts · Attaches booking endpoints to the Express app.
- Auth Route → Auth Ctrl: delegates · Routes HTTP operations to the controller boundary.
- Auth Ctrl → Auth Service: calls · Delegates auth business logic to the service layer.
- Auth Service → DB: reads/writes · Persists and retrieves auth-related data through the database boundary.
- Users Route → Users Ctrl: delegates · Routes HTTP operations to the controller boundary.
- Users Ctrl → Users Service: calls · Delegates user business logic to the service layer.
- Users Service → DB: reads/writes · Persists and retrieves user data through the database boundary.
- Vehicles Route → Vehicles Ctrl: delegates · Routes HTTP operations to the controller boundary.
- Vehicles Ctrl → Vehicles Service: calls · Delegates vehicle business logic to the service layer.
- Vehicles Service → DB: reads/writes · Persists and retrieves vehicle data through the database boundary.
- Bookings Route → Bookings Ctrl: delegates · Routes HTTP operations to the controller boundary.
- Bookings Ctrl → Bookings Service: calls · Delegates booking business logic to the service layer.
- Bookings Service → DB: reads/writes · Persists booking state and availability data through the database boundary.
- JWT Guard → Express Types: extends · Relies on request augmentation for authenticated context.
- Bookings Service → Vehicles Service: checks · Uses vehicle data to validate availability and reservation rules.
- Bookings Service → Users Service: verifies · Uses user data when validating booking ownership or access rules.
