A modern full-stack car rental and sale marketplace platform built with React and NestJS.
- Framework: React with TypeScript
- Build Tool: Vite
- Styling: CSS with modern design
- State Management: React Context API
- Framework: NestJS with TypeScript
- Database: PostgreSQL with Prisma ORM
- Authentication: JWT-based auth system
- API Documentation: Swagger/OpenAPI
- Validation: Class-validator with DTOs
- User: Customers, Owners/Dealers, Admins
- Car: Hybrid rental/sale vehicles with dual availability flags
- Booking: Rental transactions
- SaleTransaction: Purchase transactions
- Payment: Payment tracking for both rentals and sales
- Hybrid Cars: Single car can be available for both rental AND sale
- Flexible Pricing: Separate rental (daily) and sale prices
- Role-based Access: Customer, Owner, Admin roles
- Rich Car Data: JSON features, multiple images, detailed specs
git clone <repository-url>
cd FleetHubcd Backend
npm installCopy the environment file and configure your database:
cp config.env.example .envUpdate .env with your database credentials:
DATABASE_URL="postgresql://username:password@localhost:5432/car_marketplace?schema=public"
JWT_SECRET=your-super-secret-jwt-key-here# Generate Prisma client
npm run db:generate
# Push schema to database (development)
npm run db:push
# Or run migrations (production)
npm run db:migrate
# Open Prisma Studio (optional)
npm run db:studionpm run start:devcd ../frontend
npm installnpm run devThe application will be available at:
- Frontend: http://localhost:5173
- Backend API: http://localhost:3001
- API Documentation: http://localhost:3001/api
enum UserRole {
CUSTOMER // Can rent/buy cars
OWNER // Can post cars for rent/sale
ADMIN // Platform management
}// Hybrid availability
availableForRental: boolean // Can be rented
availableForSale: boolean // Can be purchased
rentalPricePerDay: Decimal // Daily rental rate
salePrice: Decimal // Purchase priceenum BookingStatus {
PENDING // Awaiting confirmation
CONFIRMED // Rental confirmed
CANCELLED // Cancelled by user
}// Tracks car purchases
buyerId: string // Customer buying
sellerId: string // Owner selling
price: Decimal // Sale amountnpm run start:dev- Development server with hot reloadnpm run build- Build for productionnpm run db:generate- Generate Prisma clientnpm run db:push- Push schema changes to databasenpm run db:migrate- Run database migrationsnpm run db:studio- Open Prisma Studio (database GUI)
npm run dev- Start development servernpm run build- Build for productionnpm run preview- Preview production buildnpm run lint- Run ESLint
POST /auth/register- User registrationPOST /auth/login- User loginPOST /auth/refresh- Refresh JWT token
GET /users/profile- Get user profilePUT /users/profile- Update profileGET /users/:id- Get user by ID
GET /cars- List all cars (with filters)POST /cars- Post new car (owners only)GET /cars/:id- Get car detailsPUT /cars/:id- Update car (owner only)DELETE /cars/:id- Delete car (owner only)
GET /bookings- User's bookingsPOST /bookings- Create rental bookingPUT /bookings/:id- Update booking statusDELETE /bookings/:id- Cancel booking
GET /sales- Sales transactionsPOST /sales- Create sale transactionGET /sales/:id- Get sale details
GET /payments- Payment historyPOST /payments- Process paymentPUT /payments/:id- Update payment status
- JWT-based authentication
- Role-based access control
- Protected routes for owners/admins
- Secure password hashing with bcrypt
| Variable | Description | Default |
|---|---|---|
DATABASE_URL |
PostgreSQL connection string | Required |
JWT_SECRET |
JWT signing secret | Required |
JWT_EXPIRES_IN |
JWT expiration time | 7d |
PORT |
Server port | 3001 |
NODE_ENV |
Environment | development |
For optimal performance, the following indexes are recommended:
-- Fast car searches
CREATE INDEX idx_cars_brand ON cars(brand);
CREATE INDEX idx_cars_category ON cars(category);
CREATE INDEX idx_cars_rental ON cars(availableForRental);
CREATE INDEX idx_cars_sale ON cars(availableForSale);
-- Fast user lookups
CREATE INDEX idx_users_email ON users(email);
CREATE INDEX idx_users_role ON users(role);
-- Fast booking queries
CREATE INDEX idx_bookings_user ON bookings(userId);
CREATE INDEX idx_bookings_car ON bookings(carId);
CREATE INDEX idx_bookings_dates ON bookings(startDate, endDate);- Set
NODE_ENV=production - Use strong
JWT_SECRET - Configure production database
- Set up proper CORS origins
- Enable rate limiting
- Set up monitoring and logging
- User Registration & Authentication: Secure JWT-based auth
- Car Browsing: Search and filter available cars
- Car Details: View comprehensive car information with images
- Rental Bookings: Book cars for specific date ranges
- Purchase Cars: Buy cars directly from the platform
- User Dashboard: Manage bookings and profile
- Car Management: Add, edit, and delete car listings
- Dual Availability: Set cars for both rental and sale
- Image Upload: Multiple car images with proper storage
- Booking Management: View and manage rental bookings
- Sales Tracking: Monitor car sales and transactions
- Platform Management: Oversee all users and transactions
- Content Moderation: Manage car listings and user accounts
This is a portfolio project for Upwork/Turing. The code is structured for:
- Clean Architecture: Separation of concerns
- Type Safety: Full TypeScript coverage
- Scalability: Modular design
- Maintainability: Clear naming conventions
Portfolio project - not for commercial use.