Skip to content

A modular FastAPI project demonstrating clean architecture, graph-based route optimization, and REST APIs for railway trips and bookings.

Notifications You must be signed in to change notification settings

gupta-8/Railway

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Railway Quest

Railway Quest is a structured FastAPI backend project that simulates a mini railway system. It demonstrates clean backend architecture, graph algorithms, and REST API design.

The project includes station discovery, cheapest-route calculation, trip scheduling, and ticket booking functionality. It is suitable for learning, interviews, and portfolio use.


Project Overview

Railway Quest models a railway network as a weighted graph. Stations are nodes, tracks are edges, and routing is computed using Dijkstra’s algorithm.

The system is intentionally kept modular so that in-memory data can later be replaced with a real database, authentication, or external services.


Features

FeatureDescription
Stations APIList all available railway stations
Route FinderFind cheapest route between two stations using Dijkstra
Trips APIView upcoming train trips
Bookings APICreate and list ticket bookings
Clean ArchitectureClear separation of API, services, data, and models
Swagger UIInteractive API documentation
TestingBasic automated tests using pytest

Architecture

The application follows a layered architecture:

API Layer        -> HTTP endpoints (FastAPI routers)
Service Layer    -> Business logic (routing, booking)
Data Layer       -> Graph + seed data
Model Layer      -> Pydantic schemas

This design improves testability, readability, and extensibility.


Project Structure

Railway/
├── requirements.txt
├── run.sh
├── README.md
├── app/
│   ├── main.py
│   ├── api/
│   │   └── routes/
│   │       ├── health.py
│   │       ├── stations.py
│   │       ├── routing.py
│   │       ├── trips.py
│   │       └── bookings.py
│   ├── core/
│   │   └── config.py
│   ├── data/
│   │   ├── network.py
│   │   └── seed.py
│   ├── models/
│   │   └── schemas.py
│   └── services/
│       ├── routing_service.py
│       └── booking_service.py
└── tests/
    └── test_routing.py

Tech Stack

TechnologyPurpose
Python 3.10+Programming language
FastAPIWeb framework
PydanticData validation and schemas
UvicornASGI server
PytestTesting framework

Installation & Setup

1. Clone the Repository

git clone https://github.com/gupta-8/Railway.git
cd Railway

2. Run the Application

bash run.sh

This script:

  • Creates a virtual environment
  • Installs dependencies
  • Starts the FastAPI server

3. Open API Documentation

http://127.0.0.1:8000/docs

How to Use

List Stations

GET /stations

Find Cheapest Route

GET /route?from_station=NDLS&to_station=BPL

List Trips

GET /trips

Create Booking

POST /bookings
Content-Type: application/json

{
  "passenger_name": "Harsh",
  "trip_id": "T1002",
  "seats": 2
}

List Bookings

GET /bookings

API Reference

MethodEndpointDescription
GET/healthService health check
GET/stationsList all stations
GET/routeFind cheapest route
GET/tripsList upcoming trips
POST/bookingsCreate a booking
GET/bookingsList all bookings

Configuration

Configuration is defined in:

app/core/config.py

Example:

fare_per_km = 2

This can be extended for dynamic pricing or multiple travel classes.


Testing

Run tests using:

source .venv/bin/activate
pytest -q

Current tests validate:

  • Route calculation correctness
  • Invalid station handling

Future Improvements

  • Persistent database (SQLite / PostgreSQL)
  • Authentication and authorization
  • Seat availability management
  • Payment gateway simulation
  • Admin dashboard
  • Frontend UI (React or Next.js)
  • Docker and CI/CD support

About

A modular FastAPI project demonstrating clean architecture, graph-based route optimization, and REST APIs for railway trips and bookings.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published