Skip to content

Repository files navigation

πŸš— Car Rental System

A Django + DRF based car rental platform for customers, sellers, bookings, payments, offers, notifications, and dynamic content pages.

Car Rental System is a full-stack rental marketplace where customers can browse vehicles, check availability, book rentals, pay through Razorpay, manage booking history, and submit feedback. Sellers can manage their shop profile, vehicles, bookings, service status, offers, reviews, activity logs, and notifications.


✨ What This Project Does

This project provides both a web dashboard and REST APIs for a vehicle rental business.

πŸ‘€ Customer Side

  • Browse available vehicles from the customer home page.
  • Search and filter vehicles by city, brand, category, fuel type, transmission, and other vehicle data.
  • View vehicle details, images, pricing, reviews, seller location, and related vehicles.
  • Add or remove vehicles from favorites.
  • Check booking availability before payment.
  • Apply eligible offers or coupon codes.
  • Create a Razorpay payment order.
  • Confirm booking after successful payment verification.
  • Track booking history and booking details.
  • Cancel eligible bookings.
  • Mark feedback and ratings after booking.
  • View notifications and activity logs.
  • Access dynamic pages like About Us, Privacy Policy, Refund Policy, Cancellation Policy, and Safety Guidelines.

πŸͺ Seller Side

  • Access a protected seller dashboard.
  • Manage seller shop profile and shop images.
  • Add, edit, preview, and delete vehicles.
  • Manage vehicle images, pricing, category, fuel type, transmission, color, registration, and location details.
  • View seller dashboard counts for vehicles, bookings, payments, and reviews.
  • View booking analytics and distribution analytics.
  • Track booking requests and booking details.
  • Mark vehicle as taken by customer.
  • Mark vehicle as returned.
  • Cancel bookings when required.
  • Manage vehicle service records and service availability.
  • View reviews for seller vehicles.
  • View seller notifications and activity logs.
  • Maintain Razorpay route/onboarding related seller payment details.

🧠 How It Works

The application is split into multiple Django apps:

App Purpose
core Shared models, seller dashboard pages, auth pages, vehicle data, booking records, seller activity, OTP tracking
customer_portal Public/customer pages, dynamic templates, customer offers, favorites, contact form, notifications, customer activity
drf_api Main REST API layer, serializers, viewsets, auth APIs, booking APIs, vehicle APIs, seller APIs
payments Invoice, refund, commission, settlement, Razorpay utility logic, scheduled payment tasks
datastorage Seller dashboard analytics APIs
utils OTP, email, notification, pagination, and activity logging helpers

πŸ” Authentication Flow

  1. User signs up from /signup/ or through /api/signup/.
  2. OTP is sent and verified through the email OTP APIs.
  3. User completes profile using /complete-profile/ or /api/complete-profile/.
  4. User type decides the experience:
    • Customer users continue to the customer portal.
    • Seller users are redirected to the seller dashboard.
  5. Login uses JWT tokens for APIs and Django-rendered pages for web screens.
  6. Logout blacklists refresh tokens when used through the API.

🚘 Customer Booking Flow

  1. Customer opens the home page /.
  2. Vehicles are loaded from active seller listings.
  3. Customer searches or filters vehicles from /search/.
  4. Customer opens a vehicle detail page using /vehicles/<vehicle_ref>/.
  5. The system decodes the signed vehicle reference and loads the vehicle safely.
  6. Customer selects booking dates and checks availability.
  7. Availability checks consider:
    • Existing active bookings
    • Vehicle service windows
    • Minimum booking days
    • Maximum booking days
    • Vehicle active/deleted status
    • Seller active/deleted status
  8. Customer can apply an offer or coupon if eligible.
  9. Customer creates a Razorpay order through /api/vehicle-bookings/payment-order/.
  10. After payment, customer confirms the booking through /api/vehicle-bookings/.
  11. Payment signature is verified before the booking is created.
  12. Booking, invoice, activity logs, notifications, and emails are created.
  13. Customer can view booking history from /booking-history/.
  14. Customer can cancel eligible bookings and submit feedback after completion.

πŸͺ Seller Booking Flow

  1. Seller logs in and opens /seller-dashboard/.
  2. Seller dashboard shows vehicle, booking, payment, review, analytics, and highlight data from APIs.
  3. Seller manages vehicles from /seller-dashboard/vehicles/.
  4. Seller views bookings from /seller-dashboard/bookings/.
  5. For each booking, seller can:
    • View details
    • Mark vehicle as taken
    • Mark vehicle as returned
    • Cancel booking if allowed
  6. Vehicle handover updates notify the customer and update activity logs.
  7. Seller can manage service status so vehicles are blocked during maintenance.

🧩 Dynamic Templates

Dynamic templates are stored in the database using the DynamicTemplate model in customer_portal.

πŸ“„ Page Templates

Seeded dynamic pages include:

  • about-us
  • our-story
  • why-choose-us
  • booking-support
  • privacy-policy
  • terms-and-conditions
  • refund-policy
  • cancellation-policy
  • safety-guidelines

These pages are created by migrations and rendered through:

/pages/<slug>/

Example:

/pages/privacy-policy/

The footer links point to these dynamic page routes. When a user clicks a footer page link, Django calls DynamicTemplatePageView, loads the active template by slug, chooses the correct base layout, and renders templates/dynamic_templates/dynamic_page.html.

🎨 Layout Selection

The dynamic page layout changes based on context:

  • ?layout=auth uses auth_base.html
  • Seller users use base.html
  • Customers and public users use customer/base.html

⚑ Cache Behavior

Dynamic template content is cached by slug. When a template is updated, deleted, or soft-deleted, its cache key is invalidated so users see fresh content.

πŸ“§ Mail Templates

The same dynamic template system is also used for mail content such as:

  • Email verification OTP
  • Reset password OTP
  • Booking confirmation
  • Booking cancellation
  • Refund notification
  • Vehicle taken
  • Vehicle returned
  • Vehicle return overdue

This allows email content to be managed from database records instead of hardcoding every email body in the view layer.


πŸ’³ Payments, Refunds, and Settlements

Payments are integrated with Razorpay.

Main payment flow:

  1. Customer checks vehicle availability.
  2. Customer creates a Razorpay order.
  3. Razorpay returns order details and key ID.
  4. Customer completes payment on the frontend.
  5. Backend verifies razorpay_order_id, razorpay_payment_id, and razorpay_signature.
  6. Booking and invoice records are created only after payment verification.

Refund and settlement logic is handled through the payments app. The project includes models for:

  • Commission settings
  • Settlement grace periods
  • Invoices
  • Refund transactions
  • Seller settlements

Celery tasks are used for background payment and refund related processing.


πŸ”” Notifications and Activity Logs

The system keeps separate activity and notification flows for customers and sellers.

Customer

  • Booking created
  • Booking cancelled
  • Payment updates
  • Vehicle handover updates
  • Refund updates
  • Favorite and feedback related activity

Seller

  • New booking
  • Booking cancellation
  • Vehicle taken/returned
  • Payment and settlement related updates
  • Vehicle/service activity

Notification count APIs use Redis caching for faster dashboard updates.


πŸ› οΈ Tech Stack

  • Backend: Django, Django REST Framework
  • Auth: JWT with djangorestframework-simplejwt, Django sessions, django-allauth
  • Database: PostgreSQL
  • Cache / Broker: Redis
  • Background Jobs: Celery, Celery Beat, django-celery-beat
  • Payments: Razorpay
  • Rich Text: CKEditor
  • Filtering: django-filter
  • Media: Django media uploads
  • Containerization: Docker and Docker Compose

πŸ“ Project Structure

Car-Rental-System/
β”œβ”€β”€ Car_Rental_System/          # Django project settings, URLs, Celery config
β”œβ”€β”€ core/                       # Core models, seller pages, auth pages
β”œβ”€β”€ customer_portal/            # Customer pages, dynamic templates, favorites, offers
β”œβ”€β”€ datastorage/                # Seller analytics APIs
β”œβ”€β”€ drf_api/                    # REST APIs, serializers, filters, viewsets
β”œβ”€β”€ payments/                   # Payment, invoice, refund, settlement logic
β”œβ”€β”€ templates/                  # Django HTML templates
β”œβ”€β”€ static/                     # Static assets
β”œβ”€β”€ media/                      # Uploaded media files
β”œβ”€β”€ utils/                      # Shared helper utilities
β”œβ”€β”€ Postman_API_collection/     # Postman collection and API docs
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ .env.example
└── README.md

βš™οΈ Environment Setup

This repository contains a real .env file, but it includes local secrets and should not be shared publicly. A safe sample file is provided:

.env.example

Create your local environment file:

cp .env.example .env

Then update values like database credentials, email credentials, Redis URLs, and Razorpay keys.

Important environment variables:

Variable Description
SECRET_KEY Django secret key
DEBUG True for development, False for production
ALLOWED_HOSTS Comma-separated allowed hosts
DB_NAME PostgreSQL database name
DB_USER PostgreSQL user
DB_PASSWORD PostgreSQL password
DB_HOST PostgreSQL host
DB_PORT PostgreSQL port
EMAIL_HOST_USER Gmail/SMTP email username
EMAIL_HOST_PASSWORD SMTP app password
CELERY_BROKER_URL Redis broker URL
CELERY_RESULT_BACKEND Redis result backend URL
REDIS_CACHE_URL Redis cache URL
RAZORPAY_SERVER_ENV local, test, or live environment value
RAZORPAY_TEST_API_KEY Razorpay test key ID
RAZORPAY_TEST_API_SECRET_KEY Razorpay test secret
RAZORPAY_LIVE_API_KEY Razorpay live key ID
RAZORPAY_LIVE_API_SECRET_KEY Razorpay live secret

πŸš€ Run With Docker

Docker is the easiest way to run the full stack because it starts Django, PostgreSQL, Redis, Celery, and Celery Beat together.

docker compose up --build

Open:

http://localhost:8000/

Django admin:

http://localhost:8000/admin/

Run in background:

docker compose up --build -d

Create admin user:

docker compose exec web python manage.py createsuperuser

Run migrations manually: README.md

docker compose exec web python manage.py migrate

Run tests:

docker compose exec web python manage.py test

Stop containers:

docker compose down

Remove containers and volumes:

docker compose down -v

πŸ’» Run Locally Without Docker

Requirements:

  • Python 3.12 recommended
  • PostgreSQL
  • Redis

Create virtual environment:

python -m venv venv

Activate it on Windows:

venv\Scripts\activate

Install dependencies:

pip install -r requirements.txt

Create .env from .env.example and update values.

Run migrations:

python manage.py migrate

Create admin user:

python manage.py createsuperuser

Start Django:

python manage.py runserver

Start Celery worker:

celery -A Car_Rental_System worker -l info

Start Celery Beat:

celery -A Car_Rental_System beat -l info --scheduler django_celery_beat.schedulers:DatabaseScheduler

🌐 Main Web Routes

Route Purpose
/ Customer home
/search/ Customer vehicle search
/vehicles/<vehicle_ref>/ Customer vehicle detail
/booking-checkout/ Customer booking checkout
/booking-history/ Customer booking history
/favorites/ Customer favorites
/offers/ Customer offers
/contact-us/ Contact/support page
/pages/<slug>/ Dynamic template pages
/login/ Login page
/signup/ Signup page
/complete-profile/ Complete profile page
/profile/ User profile
/seller-dashboard/ Seller dashboard
/seller-dashboard/vehicles/ Seller vehicles
/seller-dashboard/bookings/ Seller bookings
/seller-dashboard/my-activity/ Seller activity

πŸ”Œ API Overview

The REST APIs are mounted mainly under:

/api/

There are also customer helper APIs under:

/customer/api/

Main API groups:

  • Authentication and OTP
  • Profile and license
  • Vehicle master data
  • Seller profile
  • Vehicle CRUD
  • Available vehicles
  • Booking availability
  • Booking payment order
  • Booking creation
  • Booking history and cancellation
  • Vehicle handover and return
  • Offers and coupons
  • Feedback and reviews
  • Customer favorites
  • Notifications
  • Activity logs
  • Seller analytics
  • Dynamic templates

The Postman collection is available in:

Postman_API_collection/Car_rental_system.postman_collection.json

See Postman_API_collection/README.md for collection usage notes.


πŸ§ͺ Postman Collection

The included Postman collection contains grouped requests for:

  • Auth
  • Customer user flow
  • Seller user flow
  • Dynamic templates
  • Razorpay route testing

Set this collection variable before testing:

car_rental_base_url = http://localhost:8000/

For protected APIs, use:

Authorization: Bearer <access_token>

πŸ“ Notes for Developers

  • The app uses soft-delete fields through shared CommonFields.
  • Vehicle references in public URLs are signed instead of exposing raw IDs directly.
  • Customer and seller dashboards are protected by role-aware mixins.
  • Redis is used for cache-backed content like dynamic templates, offers, notifications, and customer home sections.
  • Celery Beat schedules recurring cleanup, notification, refund, service reminder, and overdue tasks through migrations.
  • Media files are stored under media/.
  • Static collection output goes to staticfiles/.

βœ… Current Env Sample Status

No sample env file existed before this documentation update. A proper .env.example has been added with safe placeholder values and all environment keys used by the current settings and Docker Compose configuration.

⚠️ Do not commit real .env secrets to a public repository.

About

Car Rental System REST API built with Django & Django REST Framework featuring authentication, vehicle management, booking system, soft delete, role-based permissions, and admin/customer functionalities.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages