Skip to content

OOP course teamwork project: Car Rental Management System

Notifications You must be signed in to change notification settings

M4sayev/car-rental-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš— Car Rental Management System

Python PostgreSQL React FastAPI TypeScript Docker License

A full-stack car rental management system with intelligent cost calculation, modern UI, and comprehensive API, and persistence in data. Built as an OOP course project implementing design patterns, monolith architecture, and best practices.


🎯 Overview

Backend: FastAPI REST API with modular monolith and service layer pettern, Strategy/Decorator patterns for rental cost calculation, PostgreSQL-based repository pattern, ORM for data manipulation, and CLI interface.

Frontend: React + TypeScript SPA with shadcn/ui components, React Query for data fetching, Zod validation, and comprehensive testing.

Key Features:

  • πŸš™ Complete car inventory management with image uploads
  • πŸ‘₯ Client management system
  • πŸ“ Rental creation and tracking
  • πŸ’° Smart cost calculation (SUV premium, long-term discounts, holiday deals)
  • πŸ“Š Dashboard with real-time statistics
  • πŸ—‘οΈ Soft delete with recovery archives
  • ⚑ Optimized queries with bulk fetching to prevent N+1 problems
  • 🐳 Docker containerization for easy deployment
  • πŸ–₯️ CLI for system management
  • πŸ§ͺ Full test coverage (Pytest + Vitest)
  • πŸ”’ JWT-based authentication

πŸ“Έ App Preview

πŸ“± Mobile Flow πŸ–₯️ Desktop Flow
πŸ“± Rental Workflow (Logic) πŸ–₯️ Car Creation (UX/Validation)
Car Rental Process GIF Car Creation Process GIF
Stage-based selection:
Car search β†’ Client lookup β†’ Confirmation
Inventory Flow:
Zod validation & Drag-and-drop upload

🎬 Interactive Demo

Experience the system in action without installing anything!

Product Tour

Product Tour


πŸš€ Quick Start

Option 1: Docker Deployment (Recommended)

Prerequisites:

  • Docker 21+
  • Docker Compose
# Clone repository
git clone https://github.com/M4sayev/car-rental-system.git
cd car-rental-system

# Configure environment
cp .env.example .env
# Edit .env with your database credentials

# Start all services
docker-compose up --build

# View logs
docker-compose logs -f

Access the application:

🌐 Frontend: http://localhost πŸ“š API Docs: http://localhost:8000/docs πŸ”§ Direct Backend: http://localhost:8000

Option 2: Local Development

Prerequisites

  • Python 3.9+
  • Node.js 22+
  • PostgreSQL 18+
  • pip & npm

1. Clone Repository

git clone https://github.com/M4sayev/car-rental-system.git
cd car-rental-system

2. Backend Setup (navigate to api folder for a more feature specific readme)

# Install Python dependencies
pip install -r requirements.txt

# Configure database connection in .env or environment variables
(follow .env.example ensure the DB_NAME is localhost)

# Start API server
python run_api.py

API runs at: http://localhost:8000
Docs: http://localhost:8000/docs

3. Frontend Setup (navigate to frontend folder for a more feature specific readme)

cd frontend

# Install dependencies
npm install

# Start dev server
npm run dev

App runs at: http://localhost:5173


πŸ“ Project Structure

car-rental-system/
β”‚
β”œβ”€β”€ api/                          # FastAPI application
β”‚   β”œβ”€β”€ main.py                   # App entry with CORS & static files
β”‚   β”œβ”€β”€ routes/                   # API endpoints (cars, clients, rentals, dashboard)
β”‚   β”œβ”€β”€ schemas/                  # Pydantic validation models
β”‚   β”œβ”€β”€ utils/                    # utility and helper functions (deserialize(), save_image(),...)
β”‚   ...
β”‚   └── collections/              # Postman test collections (4 collections)
β”‚
β”œβ”€β”€ src/                          # Core business logic
β”‚   β”œβ”€β”€ models/                   # Domain models
β”‚   β”‚   β”œβ”€β”€ car.py
β”‚   β”‚   β”œβ”€β”€ client.py
β”‚   β”‚   β”œβ”€β”€ rental.py
β”‚   β”‚   └── strategies/           # Cost calculation (Strategy + Decorator patterns)
β”‚   β”œβ”€β”€ repositories/             # Data access layer (Postgresql storage)
β”‚   β”œβ”€β”€ db/                       # Seed DB, connection to DB, table creation
β”‚   β”œβ”€β”€ types/                    # Reusable types for type aliasing
β”‚   └── services/                 # Business logic (car, client, rental services)
β”‚
β”œβ”€β”€ frontend/                     # React + TypeScript SPA
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/           # UI components (shadcn/ui + custom + test for each scoped component folder)
β”‚   β”‚   β”œβ”€β”€ pages/                # Pages (dashboard, cars, clients, rentals)
β”‚   β”‚   β”œβ”€β”€ hooks/                # React Query hooks
β”‚   β”‚   ...
β”‚   β”‚   β”œβ”€β”€ constants/            # Model templates, Zod validation schemas, and reusable constants
β”‚   β”‚   └── utils/                # Utilities formatStringToISO, getStatusColor,... 
β”‚   └── test/                     # Mock values for testing (MockClient, MockCar,...)
β”‚
β”œβ”€β”€ data/                         # JSON data for seeding database
β”‚   β”œβ”€β”€ cars.json
β”‚   β”œβ”€β”€ clients.json
β”‚   └── rentals.json
β”‚
β”œβ”€β”€ deleted_data/                 # Soft-deleted records archive for seeding database
β”‚
β”œβ”€β”€ media/                        # Uploaded car images
β”‚   └── cars/
β”œβ”€β”€ nginx/                        # Nginx configuration file 
β”‚   └── nginx.conf
β”œβ”€β”€ docs/                         # Documentation
β”‚   β”œβ”€β”€ UML.png
β”‚   β”œβ”€β”€ ER (for db).png
β”‚   β”œβ”€β”€ technical_documentation.md
β”‚   ...
β”‚   └── user_guide.md
β”‚
β”œβ”€β”€ tests/                        # Backend tests (Pytest)
β”‚
β”œβ”€β”€ cli.py                        # Command-line interface
β”œβ”€β”€ run_api.py                    # API launcher
β”œβ”€β”€ run.py                        # CLI launcher
β”œβ”€β”€ docker-compose.yml            # Docker orchestration configuration
β”œβ”€β”€ .env.example                  # Environment variables template
β”œβ”€β”€ .dockerignore                 # Docker ignore patterns
└── requirements.txt              # Python dependencies

πŸ’» Usage

Web Interface

Navigate to http://localhost:5173 for the full UI:

  • Dashboard with statistics
  • Manage cars (CRUD + image upload)
  • Manage clients (CRUD + validation)
  • Manage Rentals (CRUD + search option + validation)
  • handle login form authentication

API

Access http://localhost:8000/docs for interactive API documentation with:

  • 8 car endpoints (including cost calculator)
  • 6 client endpoints
  • 5 rental endpoints
  • 2 dashboard endpoints
  • 2 authentication endpoints (login and signup)

Command Line

Quick operations via CLI:

# List cars (list-available / list-deleted for available / deleted respectively)
python cli.py car list

# Add a car interactively
python cli.py car add

# Delete a car (select from list)
python cli.py car delete

# List all clients (list-deleted for deleted clients)
python cli.py client list

# Add a client
python cli.py client add

# Create a rental
python cli.py rental create C001 CL001

# Complete a rental
python cli.py rental complete R001

# List active rentals
python cli.py rental list

🎨 Design Patterns

Strategy Pattern

Different cost strategies based on car type:

StandardCarCost      # Base daily rate
SUVRentalCost        # 20% premium for SUVs

Decorator Pattern

Stackable discounts:

LongTermRentalCost   # 15% off for 7+ days
HolidayDiscount      # 10% off on Azerbaijan holidays

Example: SUV rented for 10 days on a holiday = base Γ— 1.2 Γ— 0.85 Γ— 0.9


⚑ Performance Optimizations

N+1 Query Prevention

The repository layer implements bulk fetching to avoid N+1 query problems:

  • Rentals are hydrated using bulk get_by_ids() operations
  • Cars and clients are fetched in batches and mapped using hashmaps
  • Result: Single query per entity type instead of N queries per rental

Example: Loading 100 rentals requires only 3 queries (rentals, cars, clients) instead of 201.


πŸ§ͺ Testing

Backend Tests

pytest                    # Run all tests
pytest --cov=src          # With coverage

Frontend Tests

cd frontend
npm run test              # Run all tests
npm run test:coverage     # With coverage

πŸ“š Documentation

Detailed documentation available:


πŸ›£οΈ Roadmap

Current Status βœ…

  • Backend API with microservices
  • Intelligent cost calculation
  • Cars & Clients & Rentals full CRUD
  • Create rental step-by-step selection stage
  • Dashboard with statistics
  • Frontend UI with React + TypeScript
  • Form validation (Zod)
  • Image uploads
  • Soft delete with archives
  • CLI interface
  • Comprehensive testing
  • Database migration (PostgreSQL)
  • Dockerization
  • Authentication (JWT)

Planned 🎯

  • Dashboard analytics charts
  • AI integration

πŸ”§ Tech Stack

Backend:

  • FastAPI - High-performance async API framework
  • Python 3.9+ - Core language
  • Pydantic - Data validation
  • Pytest - Testing framework
  • Click - CLI framework
  • Docker 29+ - containeraziation

Frontend:

  • React 18 - UI library
  • TypeScript - Type safety
  • Vite - Build tool
  • TailwindCSS - Styling
  • shadcn/ui - Component library
  • React Query - Data fetching
  • React Hook Form + Zod - Form validation
  • Vitest - Testing framework

Data Storage:

  • PostgreSQL - database
  • psycopg2 ORM - data manipulation
  • Bulk select operations preventing N+1 query issues
  • Configurable history tracking for deleted items
  • Media storage for uploaded images

🀝 Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Ensure all tests pass before submitting:

# Backend
pytest

# Frontend
cd frontend && npm run test && npm run lint

πŸ“„ License

This project is licensed under the MIT License.


πŸ‘₯ Authors


πŸ™ Acknowledgments

Built as part of an OOP course project, demonstrating:

  • Object-oriented programming principles
  • Design patterns (Strategy, Decorator, Repository)
  • Microservices architecture
  • Modern web development practices
  • Test-driven development
  • Persisting data in the database