A full-stack car rental management system built with FastAPI, SQLAlchemy, PostgreSQL, React, TypeScript, and Tailwind CSS.
- 30+ REST API endpoints with full CRUD operations
- JWT-based authentication with role-based access control (Customer, Admin, Clerk)
- SQLAlchemy ORM with complete database relationships
- Pydantic validation for all API requests
- Transactional payment processing with automatic reservation confirmation
- Business logic services for pricing, availability, and reservations
- OOP principles: Inheritance (User types), Polymorphism (Payment methods), Encapsulation (Reservation state), Abstraction (Service layer)
- Responsive UI with Tailwind CSS and shadcn/ui components
- Role-based dashboards for customers, admins, and clerks
- Vehicle browsing with date-based availability search
- Reservation workflow with real-time price calculation
- Payment processing integration
- Customer dashboard for managing reservations
- 8 entity tables with proper relationships and constraints
- Alembic migrations for version-controlled schema changes
- Foreign key constraints for data integrity
- Indexes for optimized queries
- Check constraints to prevent overlapping reservations
- Python seed script for test data
- FastAPI 0.115.5
- SQLAlchemy 2.0.36
- PostgreSQL 16 (via psycopg2)
- Alembic 1.14.0 (database migrations)
- Pydantic 2.10.3
- JWT (python-jose)
- Bcrypt (passlib)
- React 18.3.1
- TypeScript 5.6.3
- Tailwind CSS 3.4.15
- Vite 6.0.1
- React Router 6.28.0
- Axios 1.7.9
- shadcn/ui components
CarRentalManagementSystem/
├── backend/
│ ├── app/
│ │ ├── models/ # SQLAlchemy models
│ │ ├── schemas/ # Pydantic schemas
│ │ ├── routers/ # API endpoints
│ │ ├── services/ # Business logic
│ │ ├── auth.py # Authentication
│ │ ├── config.py # Configuration
│ │ ├── database.py # Database setup
│ │ └── main.py # FastAPI app
│ ├── schema.sql # Database schema
│ ├── seed_data.sql # Sample data
│ ├── requirements.txt # Python dependencies
│ └── .env.example # Environment variables template
├── frontend/
│ ├── src/
│ │ ├── api/ # API integration
│ │ ├── components/ # Reusable components
│ │ ├── context/ # React context
│ │ ├── pages/ # Page components
│ │ ├── types/ # TypeScript types
│ │ ├── App.tsx # Main app
│ │ └── main.tsx # Entry point
│ ├── package.json # Node dependencies
│ └── vite.config.ts # Vite configuration
└── README.md # This file
- Users (with inheritance: Customer, Admin, Clerk)
- Locations
- Vehicles
- RatePlans
- Reservations
- Payments
- Inspections
- DamageReports
- POST
/auth/register/customer- Register new customer - POST
/auth/register/admin- Register admin/clerk - POST
/auth/login- Login and get JWT token - GET
/auth/me- Get current user
- GET
/locations/- List all locations - GET
/locations/{id}- Get location by ID - POST
/locations/- Create location (admin) - PUT
/locations/{id}- Update location (admin) - DELETE
/locations/{id}- Delete location (admin)
- GET
/vehicles/- List vehicles with filters - GET
/vehicles/available- Get available vehicles by date range - GET
/vehicles/{id}- Get vehicle by ID - GET
/vehicles/{id}/availability- Check vehicle availability - POST
/vehicles/- Create vehicle (admin) - PUT
/vehicles/{id}- Update vehicle (admin) - DELETE
/vehicles/{id}- Delete vehicle (admin)
- GET
/rate-plans/- List all rate plans - GET
/rate-plans/{id}- Get rate plan by ID - POST
/rate-plans/- Create rate plan (admin) - PUT
/rate-plans/{id}- Update rate plan (admin) - DELETE
/rate-plans/{id}- Delete rate plan (admin)
- GET
/reservations/- List reservations (role-based) - GET
/reservations/my-reservations- Get current user's reservations - GET
/reservations/{id}- Get reservation by ID - POST
/reservations/calculate-price- Calculate reservation price - POST
/reservations/- Create reservation - PUT
/reservations/{id}- Update reservation - POST
/reservations/{id}/activate- Activate reservation (clerk) - POST
/reservations/{id}/complete- Complete reservation (clerk) - POST
/reservations/{id}/cancel- Cancel reservation - DELETE
/reservations/{id}- Delete reservation (admin/clerk)
- GET
/payments/- List payments (role-based) - GET
/payments/{id}- Get payment by ID - GET
/payments/reservation/{id}- Get payments by reservation - POST
/payments/- Create and process payment - POST
/payments/{id}/refund- Refund payment (admin)
- GET
/inspections/- List inspections (clerk/admin) - GET
/inspections/{id}- Get inspection by ID - GET
/inspections/reservation/{id}- Get inspections by reservation - GET
/inspections/vehicle/{id}- Get inspections by vehicle - POST
/inspections/- Create inspection (clerk/admin) - PUT
/inspections/{id}- Update inspection (clerk/admin) - DELETE
/inspections/{id}- Delete inspection (admin)
- GET
/damage-reports/- List damage reports (clerk/admin) - GET
/damage-reports/{id}- Get damage report by ID - GET
/damage-reports/reservation/{id}- Get reports by reservation - GET
/damage-reports/vehicle/{id}- Get reports by vehicle - POST
/damage-reports/- Create damage report (clerk/admin) - PUT
/damage-reports/{id}- Update damage report (clerk/admin) - DELETE
/damage-reports/{id}- Delete damage report (admin)
Total: 47 endpoints
- Python 3.9+
- Node.js 18+
- Docker & Docker Compose
- Start PostgreSQL database (from project root):
docker-compose up -d- Navigate to backend directory and set up environment:
cd backend
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt- Configure environment:
cp .env.example .env- Run database migrations:
alembic upgrade head- Seed database with test data:
python seed.py- Run the backend server:
uvicorn app.main:app --reloadServer runs at http://localhost:8000
- API Docs (Swagger): http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
- OpenAPI JSON: http://localhost:8000/openapi.json
- Navigate to frontend directory:
cd frontend- Install dependencies:
npm install- Add missing dependency for Tailwind animations:
npm install tailwindcss-animate- Run the development server:
npm run devFrontend will be available at http://localhost:5173
After loading seed data, you can login with:
Admin:
- Email: admin@carrental.com
- Password: password123
Clerk:
- Email: clerk@carrental.com
- Password: password123
Customers:
- Email: john.doe@email.com
- Password: password123
-
Reservation Constraints:
- Vehicles cannot have overlapping active reservations
- End date must be after start date
- Availability is checked before creating reservations
-
Pricing Logic:
- Base price = daily rate × rental days
- Discount applied based on rate plan
- One-way fee added if pickup ≠ dropoff location
- Insurance calculated per day if selected
-
Payment Processing:
- Payment must succeed before reservation is confirmed
- Transactional: payment and reservation confirmation happen atomically
- Vehicle status updated to "reserved" upon payment
-
Workflow:
- Reservation created → Payment processed → Reservation confirmed
- Clerk activates reservation → Vehicle status = "rented"
- Clerk completes reservation → Vehicle status = "available"
- Inspections created on pickup/return
- Damage reports optional on return
Userbase class →Customer,Admin,Clerksubclasses
Payment.process()method handles different payment methods (card, cash, PayPal)
Reservation.confirm(),activate(),complete(),cancel()methods encapsulate state changes
- Service layer (
PricingService,AvailabilityService,PaymentService,ReservationService) abstracts business logic from API routes
This is a demonstration project for educational purposes.