Django · Next.js · PostgreSQL

Bus Management System

Full Stack Development Case Study

Bus Management System UI

The context

Project Overview.

The client, a regional transport operator in Nepal, was managing a fleet of over 50 buses entirely on paper. Route assignments, ticket sales, driver rosters, and maintenance schedules were recorded in physical ledgers. This manual process led to frequent double-bookings, lost revenue through unaccounted ticket sales, and zero real-time visibility into fleet operations for management.

They required a complete digital transformation: a centralised system to manage the entire lifecycle of a bus trip, from assigning a driver and conductor to selling seats and tracking daily revenue. The system needed a robust backend to handle complex relational data (routes, schedules, seats, staff) and a fast, intuitive frontend that counter staff could use rapidly during peak booking hours.

Architecture & Stack

The Solution.

I architected a full-stack solution decoupling the frontend and backend to allow for future mobile app integration.

The Backend: Built with Django and Django REST Framework. Django's ORM was perfect for modeling the complex relationships between vehicles, routes (with multiple stops and varying pricing), schedules, and staff. PostgreSQL was chosen for data integrity, ensuring transactional safety during concurrent ticket bookings to prevent double-selling a seat.

The Frontend: Built with Next.js (React) and Tailwind CSS. The requirement for a highly responsive UI for counter staff dictated a single-page application feel, while Next.js provided the routing and structure needed for a large administrative dashboard.

Tech Stack

  • Backend FrameworkDjango 4.x
  • API LayerDjango REST Framework
  • FrontendNext.js 13+ (React)
  • DatabasePostgreSQL
  • StylingTailwind CSS
  • AuthenticationJWT (SimpleJWT)

Technical hurdles

Key Challenges & Solutions.

Challenge: Concurrency in Bookings

During festival seasons (Dashain/Tihar), multiple counter staff would attempt to book the same seat on the same bus simultaneously. Standard ORM saves would result in race conditions and double-booked seats.

Solution

Implemented PostgreSQL transaction blocks with `select_for_update()` in Django. This locked the specific seat row during the transaction, forcing concurrent requests to wait and subsequently fail gracefully if the seat was taken, guaranteeing data integrity.

Challenge: Dynamic Route Pricing

A single bus route (e.g., Kathmandu to Pokhara) might have 10 intermediate stops. Pricing isn't just A to B; it's A to C, B to C, etc., creating a matrix of prices that needed to be easily manageable by admins.

Solution

Designed a graph-based schema for routes. Instead of hardcoding all permutations, the system stored base fares between adjacent stops. The backend dynamically calculated fares between any two points on the route using graph traversal, significantly simplifying data entry.

Business results

The Outcome.

The deployment of the Bus Management System completely transformed the client's operations within the first month. Paper ledgers were entirely phased out. Management gained access to a real-time dashboard showing daily revenue, seat occupancy rates, and vehicle utilisation.

60%

Reduction in Booking Errors

100%

Digitised Ledger

Zero

Double-Booked Seats