This Project Provides Complete solution for managing vehicle rentals, user accounts, bookings, and role-based authentication and A robust RESTFUL API backend built with Node.js, TypeScript, Express.js, and PostgreSQL.
- Admin User:
- Email: admin@admin.com
- Password: adminpassword
- Customer User:
- Email: jony@customer.com
- Password: customerpassword1
/api/v1
This project is a modular, scalable, and production-ready REST API built using Node.js, TypeScript, Express, and PostgreSQL. It provides essential features for a vehicle rental system, including:
- Vehicle inventory management
- Customer account and profile management
- Booking creation, cancellation & returns
- JWT-based authentication
- Role-based authentication and authorization (Admin and Customer roles)
| Category | Technology | Usage |
|---|---|---|
| Runtime | Node.js (TypeScript) | Backend runtime |
| Framework | Express.js | Web framework |
| Database | PostgreSQL | Database management |
| Query | ( pg) | Database querying |
| Security | bcrypt, JWT | Password hashing, authentication |
| Validation | Zod (Recommended) | Input validation |
| Dev Tools | ts-node-dev, eslint, prettier | Development tools |
| Deployment | Vercel | Deployment platform |
- User registration and login with JWT authentication
- Password hashing with bcrypt
- JWT-based authentication
- Role-based access control (Admin and Customer roles)
- CRUD operations for user accounts
- Profile management (view and update profile)
- All users have roles: Admin or Customer.
- All Customers List viewable by Admins.
- Unique email for each user account.
- Role-based access control for sensitive operations.
- Role Management: Assign and manage only Admin.
- Admins can manage all user accounts.
- Can not Delete if user has active bookings.
- CRUD operations for vehicle inventory
- Vehicle availability status tracking
- Vehicle Type: Car, Bike, Van, SUV.
- Real-time tracking of vehicle status (available, booked).
- Unique vehicle Registration Number for each vehicle.
- Admins can manage the vehicle inventory.
- Customers can view available vehicles.
- Bookings Create and automatic automatic price calculation based on vehicle rental duration.
- Vehicle Booking: Customers can book available vehicles.
- Booking Cancellation: Customers can cancel bookings before the rental start date.
- Automatic Vehicle availability Update.
- Mark vehicle as returned only by Admins or (Automatic after booking end date with vercel cron job every midnight).
- Role-based booking visibility (Admins can view all bookings, Customers can view their own bookings).
- Validate user inputs for all operations.
- Validate booking dates (start date must be before end date).
- Ensure vehicle availability before confirming bookings.
- Automatic price calculation based on rental duration and vehicle type.
- Prevent deletion of users with active bookings.
- API Response standardization with appropriate HTTP status codes and messages.
src/
│
├── app/
│ ├── modules/
│ │ ├── auth/
│ │ │ ├── auth.route.ts
│ │ │ ├── auth.controller.ts
│ │ │ ├── auth.service.ts
│ │ │ ├── auth.validation.ts
│ │ │ └── auth.interface.ts
│ │ │
│ │ ├── users/
│ │ │ ├── user.route.ts
│ │ │ ├── user.controller.ts
│ │ │ ├── user.service.ts
│ │ │ ├── user.validation.ts
│ │ │ └── user.interface.ts
│ │ │
│ │ ├── vehicles/
│ │ │ ├── vehicle.route.ts
│ │ │ ├── vehicle.controller.ts
│ │ │ ├── vehicle.service.ts
│ │ │ ├── vehicle.validation.ts
│ │ │ └── vehicle.interface.ts
│ │ │
│ │ ├── bookings/
│ │ │ ├── booking.route.ts
│ │ │ ├── booking.controller.ts
│ │ │ ├── booking.service.ts
│ │ │ ├── booking.validation.ts
│ │ │ └── booking.interface.ts
│ │ ├── routes
│ │ │ └── index.ts
│ │
│ │
│ ├── middlewares/
│ │ ├── auth.middleware.ts
│ │ ├── validateRequest.ts
│ │ └── globalErrorHandler.ts
│ │
│ ├── errors/
│ │ ├── ApiError.ts
│ │ └── handleZodError.ts
│ │
│ └── app.ts
│
├── config/
│ ├── index.ts
│ └── db.ts
│
├── shared/
│ ├── jwtHelpers.ts
│ └── bcryptHelpers.ts
│
├── utils/
│ ├── calculatePrice.ts
│ └── dateUtils.ts
│
├── server.ts
├── tsconfig.json
├── package.json
└── README.md
| Method | Endpoint | Access | Description |
|---|---|---|---|
| POST | /api/v1/auth/signup |
Public | Register a new user |
| POST | /api/v1/auth/signin |
Public | Login & receive JWT |
| Method | Endpoint | Access | Description |
|---|---|---|---|
| GET | /api/v1/users |
Admin | View all users |
| PUT | /api/v1/users/:userId |
Admin / Own | Admin update any user role and customer update their own profile |
| DELETE | /api/v1/users/:userId |
Admin | Delete user (only if no active bookings) |
| Method | Endpoint | Access | Description |
|---|---|---|---|
| POST | /api/v1/vehicles |
Admin | Add new vehicle |
| GET | /api/v1/vehicles |
Public | Get all vehicles |
| GET | /api/v1/vehicles/:vehicleId |
Public | Get vehicle |
| PUT | /api/v1/vehicles/:vehicleId |
Admin | Update vehicle |
| DELETE | /api/v1/vehicles/:vehicleId |
Admin | Delete vehicle |
| Method | Endpoint | Access | Description |
|---|---|---|---|
| POST | /api/v1/bookings |
Customer/Admin | Create booking |
| GET | /api/v1/bookings |
Customer/Admin | View bookings |
| PUT | /api/v1/bookings/:bookingId |
Customer/Admin | Cancel/Return |
- Clone the repository:
git clone https://github.com/monir6163/assaignment-2.git
- Navigate to the project directory:
cd assaignment-2 - Install dependencies:
npm install or yarn install
- Configure environment variables:
Create a
.envfile in the root directory and add the following variables:NODE_DEV=development PORT=5000 BCRYPT_SALT_ROUNDS=10 JWT_SECKRET_TOKEN=your_jwt_secret_key JWT_EXPIRE_IN=1d CRON_JOB_SECRET=your_cron_job_secret DATABASE_URL=your_postgresql_connection_string
- Run the development server:
npm run dev or yarn dev
- Access the API:
Open your browser or API client and navigate to
http://localhost:5000/api/v1/to access the API endpoints.
This project is licensed under the MIT License. See the LICENSE file for details.
For any inquiries or support, please contact Email.
** Monir Hossain** - Linkedin