Skip to content

IRCTC-style Train Booking Backend

A train ticket booking API built with FastAPI, structured as a clean router / service / DAO layering.

  • Python
  • FastAPI
  • PostgreSQL
  • SQLAlchemy
  • Docker

Problem

Placeholder: describe the problem this project solves. For example, how the real IRCTC style booking flow works, what makes it hard (seat availability, concurrent bookings, cancellation and refunds) and why I built it.

Architecture

Placeholder: describe the layers. The router handles HTTP concerns, the service layer owns the business rules, and the DAO is the only place that talks to the database. Mention the request flow and where transactions are managed.

# Example: a thin router that delegates to the service layer.
from fastapi import APIRouter, Depends
 
router = APIRouter(prefix="/trains", tags=["trains"])
 
@router.get("/{train_id}/availability")
def get_availability(train_id: int, service: BookingService = Depends()):
    return service.get_availability(train_id)

Key decisions

Placeholder: list the decisions you made and why. For example, why a service layer instead of putting logic in the router, how you handle seat locking, and how you keep the DAO interchangeable.

What I learned

Placeholder: the lessons. For example, how to keep business logic testable, how to design around concurrent seat booking, and what you would change now.