You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A backend API for a vehicle rental management system that handles:
Vehicles - Manage vehicle inventory with availability tracking
Customers - Manage customer accounts and profiles
Bookings - Handle vehicle rentals, returns and cost calculation
Authentication - Secure role-based access control (Admin and Customer roles)
Technology Stack:
Node.js + TypeScript
Express.js (web framework)
PostgreSQL (database)
bcrypt (password hashing)
jsonwebtoken (JWT authentication)
📁 Code Structure
IMPORTANT: followed modular pattern with clear separation of concerns. Organized the code into feature-based modules (e.g., auth, users, vehicles, bookings) with proper layering (routes, controllers, services).
📊 Database Tables
Users
Field
Notes
id
Auto-generated
name
Required
email
Required, unique, lowercase
password
Required, min 6 characters
phone
Required
role
'admin' or 'customer'
Vehicles
Field
Notes
id
Auto-generated
vehicle_name
Required
type
'car', 'bike', 'van' or 'SUV'
registration_number
Required, unique
daily_rent_price
Required, positive
availability_status
'available' or 'booked'
Bookings
Field
Notes
id
Auto-generated
customer_id
Links to Users table
vehicle_id
Links to Vehicles table
rent_start_date
Required
rent_end_date
Required, must be after start date
total_price
Required, positive
status
'active', 'cancelled' or 'returned'
🔐 Authentication & Authorization
User Roles
Admin - Full system access to manage vehicles, users and all bookings
Customer - Can register, view vehicles, create/manage own bookings
Authentication Flow
Passwords are hashed using bcrypt before storage into the database
User login via /api/v1/auth/signin and receives a JWT (JSON Web Token)
Protected endpoints require token in header: Authorization: Bearer <token>
Validates the token and checks user permissions
Access granted if authorized, otherwise returns 401 (Unauthorized) or 403 (Forbidden)
⚠️IMPORTANT: All API endpoint implementations exactly match the specifications defined in API Reference. This includes: