CarConnect is a robust and secure backend API for managing a vehicle rental service. It handles everything from user authentication and vehicle inventory management to booking creation, price calculation, and role-based access control.
The system is designed to provide a comprehensive management solution for a vehicle rental business. It features a modular architecture with a clear separation of concerns, supporting two main user roles: Admin and Customer.
- Secure Authentication: User registration and JWT-based login.
- Role-Based Access Control (RBAC): Restricts administrative actions (vehicle and user management) to Admin users.
- Vehicle Management: CRUD operations for the vehicle inventory, including availability tracking.
- Booking Management: Create, view, cancel, and mark bookings as returned, with automatic price calculation.
- Data Integrity: Constraints on deletion (users/vehicles cannot be deleted with active bookings).
The CarConnect API is built with a modern and scalable stack:
| Category | Technology | Purpose |
|---|---|---|
| Backend | Node.js + TypeScript | Runtime environment and primary language. |
| Web Framework | Express.js | Minimalist and flexible web application framework. |
| Database | PostgreSQL | Reliable and scalable relational database. |
| Authentication | jsonwebtoken (JWT) | Secure token-based authentication. |
| Security | bcrypt | Hashing for secure password storage. |
The system uses a relational database structure with three primary tables: Users, Vehicles, and Bookings.
| Field | Notes |
|---|---|
id |
Auto-generated |
name |
Required |
email |
Required, unique, lowercase |
password |
Required, min 6 characters (hashed) |
phone |
Required |
role |
'admin' or 'customer' |
| 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' |
| 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 (calculated) |
status |
'active', 'cancelled', or 'returned' |
Protected endpoints require a JSON Web Token (JWT) passed in the Authorization header.
Header Format: Authorization: Bearer <your_jwt_token>
- Admin Role: Has full system access to manage vehicles, users, and all bookings.
- Customer Role: Can register, view vehicles, create/manage their own bookings.
- Password Storage: Passwords are hashed using bcrypt before being saved to the database.
The CarConnect API is deployed and can be accessed via the following base URL:
Base URL: https://car-connect-five.vercel.app/
You can test the endpoints by appending the paths from the API Endpoints Reference to the Base URL (e.g., https://car-connect-five.vercel.app/api/v1/vehicles).
All endpoints are prefixed with /api/v1.
| Method | Endpoint | Access | Description |
|---|---|---|---|
POST |
/auth/signup |
Public | Register a new user account. |
POST |
/auth/signin |
Public | Login and receive an authentication JWT token. |
| Method | Endpoint | Access | Description |
|---|---|---|---|
POST |
/vehicles |
Admin only | Add a new vehicle to the inventory. |
GET |
/vehicles |
Public | Retrieve a list of all vehicles. |
GET |
/vehicles/:vehicleId |
Public | Retrieve details for a specific vehicle. |
PUT |
/vehicles/:vehicleId |
Admin only | Update vehicle details, price, or status. |
DELETE |
/vehicles/:vehicleId |
Admin only | Delete a vehicle (only if no active bookings exist). |
| Method | Endpoint | Access | Description |
|---|---|---|---|
GET |
/users |
Admin only | Retrieve a list of all users in the system. |
PUT |
/users/:userId |
Admin or Own | Update user details or role (Admin can update any user, Customer updates own profile only). |
DELETE |
/users/:userId |
Admin only | Delete a user (only if no active bookings exist). |
| Method | Endpoint | Access | Description |
|---|---|---|---|
POST |
/bookings |
Customer/Admin | Create a new booking, validates availability, and calculates total price. |
GET |
/bookings |
Role-based | Admin views all bookings; Customer views only their own. |
PUT |
/bookings/:bookingId |
Role-based | Customer can cancel (before start date); Admin can mark as "returned". |
-
Booking Price Calculation: The total price is calculated by multiplying the vehicle's daily rent price by the number of rental days.
$$total_price = daily_rent_price \times (rent_end_date - rent_start_date)$$ -
Vehicle Availability Updates:
- Vehicle status changes to
"booked"upon new booking creation. - Vehicle status changes back to
"available"when a booking is marked as"returned"or"cancelled".
- Vehicle status changes to
-
Auto-Return: The system automatically marks bookings as
"returned"when therent_end_datehas passed. -
Deletion Constraints: Users and Vehicles cannot be deleted if they are associated with any active bookings (status:
"active").
Ensure you have Node.js (LTS version) and npm/yarn installed.
git clone https://github.com/ShaharearSabbir/CarConnect
cd CarConnectnpm install
# or
yarn install
Create a file named .env in the root directory and configure it with the following:
| Variable | Description |
|---|---|
APP_NAME |
The name of the application. |
VERSION |
Current API version. |
PORT |
The port the server will run on (e.g., 5000). |
CONNECTION_STR |
Your PostgreSQL database connection string. |
JWT_SECRET |
A long, secure secret key for JWT signing. |
The API will be accessible locally at http://localhost:5000/api/v1.