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.
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.
| Feature | Description |
|---|---|
| Stations API | List all available railway stations |
| Route Finder | Find cheapest route between two stations using Dijkstra |
| Trips API | View upcoming train trips |
| Bookings API | Create and list ticket bookings |
| Clean Architecture | Clear separation of API, services, data, and models |
| Swagger UI | Interactive API documentation |
| Testing | Basic automated tests using pytest |
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.
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
| Technology | Purpose |
|---|---|
| Python 3.10+ | Programming language |
| FastAPI | Web framework |
| Pydantic | Data validation and schemas |
| Uvicorn | ASGI server |
| Pytest | Testing framework |
git clone https://github.com/gupta-8/Railway.git cd Railway
bash run.sh
This script:
- Creates a virtual environment
- Installs dependencies
- Starts the FastAPI server
http://127.0.0.1:8000/docs
GET /stations
GET /route?from_station=NDLS&to_station=BPL
GET /trips
POST /bookings
Content-Type: application/json
{
"passenger_name": "Harsh",
"trip_id": "T1002",
"seats": 2
}
GET /bookings
| Method | Endpoint | Description |
|---|---|---|
| GET | /health | Service health check |
| GET | /stations | List all stations |
| GET | /route | Find cheapest route |
| GET | /trips | List upcoming trips |
| POST | /bookings | Create a booking |
| GET | /bookings | List all bookings |
Configuration is defined in:
app/core/config.py
Example:
fare_per_km = 2
This can be extended for dynamic pricing or multiple travel classes.
Run tests using:
source .venv/bin/activate pytest -q
Current tests validate:
- Route calculation correctness
- Invalid station handling
- 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