How smahmud10/vehicle-rental-system works
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: server.ts Server · booking.services.ts Bookings Service · db.ts DB · user.service.ts Users Service
Components 17
Infrastructure
Bootstrap, configuration, middleware, and shared types.
- Server · Creates the app, wires routes and middleware, and starts the HTTP server.
src/server.ts - Config · Central configuration entry point for environment and runtime settings.
src/config/index.ts - DB · Database connection boundary used by the service layer.
src/config/db.ts - JWT Guard · Protects authenticated routes by validating JWTs.
src/middleware/auth.ts - Express Types · Custom Express request typing for shared auth context.
src/types/express/index.d.ts
Auth
Registration, login, and token issuance.
- Auth Route · Exposes auth endpoints under the API namespace.
src/modules/auth/auth.router.ts - Auth Ctrl · Handles auth request parsing and HTTP responses.
src/modules/auth/auth.controller.ts - Auth Service · Implements signup, signin, and token issuance logic.
src/modules/auth/auth.services.ts
Users
User management feature module.
- Users Route · Exposes user endpoints under the API namespace.
src/modules/users/user.router.ts - Users Ctrl · Handles user request/response concerns.
src/modules/users/user.controller.ts - Users Service · Implements user CRUD and domain rules.
src/modules/users/user.service.ts
Vehicles
Vehicle management feature module.
- Vehicles Route · Exposes vehicle endpoints under the API namespace.
src/modules/vehicles/vehicle.router.ts - Vehicles Ctrl · Handles vehicle request/response concerns.
src/modules/vehicles/vehicle.controller.ts - Vehicles Service · Implements vehicle CRUD and related rules.
src/modules/vehicles/vehicle.service.ts
Bookings
Reservation and availability feature module.
- Bookings Route · Exposes booking endpoints under the API namespace.
src/modules/booking/booking.touter.ts - Bookings Ctrl · Handles booking request/response concerns.
src/modules/booking/booking.controller.ts - Bookings Service · Implements booking creation, updates, and availability logic.
src/modules/booking/booking.services.ts
Connections 21
- 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.