A simple and secure backend API for managing a complete vehicle rental system. This project is designed with role-based authentication to allow administrators and customers to manage vehicles, users, and bookings efficiently.
- User Authentication: Secure authentication using JSON Web Tokens (JWT).
- Role-Based Access: Distinct access levels for Admin and Customer roles.
- Vehicle Management: Full CRUD operations (Add, Update, Delete, View) for vehicles.
- User Management: Admin controls for all users, plus self-profile updates for all users.
- Comprehensive Booking System:
- Availability checks before booking.
- Automatic price calculation.
- Automatic status updates (Booked / Returned / Cancelled).
| Technology | Purpose |
|---|---|
| Node.js | Runtime Environment |
| TypeScript | Language for type safety |
| Express.js | Web Framework |
| PostgreSQL | Database |
bcryptjs |
Password Hashing |
jsonwebtoken (JWT) |
Authentication |
dotenv |
Environment Variables |
The project follows a modular, feature-based structure:
src/modules
Each module (auth, users, etc.) is cleanly separated into:
routescontrollersservices
Follow these steps to set up and run the project locally.
- git clone
- cd vehicle-rental
- Install dependenciesBash
npm install
- Create a file named .env in the root folder and add your configuration details:Code snippet
PORT=5000CONNECTION_SRT=postgresql://your connection credentialsJWT_SECRET=your_jwt_secret
- Run the project
npm run dev
The server will start on: http://localhost:5000
Register: POST /api/v1/auth/signupLogin: POST /api/v1/auth/signinProtected Routes For all protected endpoints, an authorization header is required: Authorization: Bearer <your_token>
- Register a user
- Login to receive a JWT token.
- Use the token in the Authorization header to access protected routes.
- Admin users can manage vehicles and all users.
- Customer users can create and manage their own bookings.