Live Production App: https://railpulse-01i.pages.dev
Backend API & Swagger Docs: https://railpulse-backend-fv1m.onrender.com/docs
A production-oriented Indian Railway tracking platform built with Next.js 15+, FastAPI, PostgreSQL (Neon), Redis (Upstash), MapLibre GL + OpenStreetMap, WebSockets, and a grounded LangGraph AI travel assistant powered by the xKiro API.
⭐ If you find this live railway tracking platform helpful, please consider starring the repository!
┌──────────────────────────────────────────────┐
│ Frontend: Next.js 15+ (App Router) │
│ - MapLibre GL + OpenStreetMap Free Tiles │
│ - WebSocket Live Telemetry Age Counter │
│ - Coach Rake Visualizer (Loco to SLR) │
│ - LangGraph AI Travel Assistant Drawer │
└──────────────────────┬───────────────────────┘
│ HTTPS REST / WebSockets
▼
┌──────────────────────────────────────────────┐
│ Backend Gateway: FastAPI │
│ - WebSocket Hub (/ws/live-tracking) │
│ - Capability-Aware Provider Registry │
│ - Circuit Breakers (Closed/Open/Half-Open)│
│ - Telescopic Distance Fare Engine │
└───────┬──────────────┬──────────────┬────────┘
│ │ │
┌──────────────┴─┐ ┌──────┴──────┐ ┌─────┴──────────┐
▼ ▼ ▼ ▼ ▼ ▼
┌──────────────┐ ┌──────────┐ ┌────────────┐ ┌────────┐ ┌─────────────┐
│Railway Engine│ │RailRadar │ │NTES Stub │ │Postgres│ │Redis Pub/Sub│
│(60 req/min) │ │(Developer│ │(CRIS Ref) │ │(Async) │ │+ Memory TTL │
└──────────────┘ └──────────┘ └────────────┘ └────────┘ └─────────────┘
- Zero-Fake Telemetry Guarantee:
- The data provider reports stations, not coordinates. Between stations the position is an estimate and is labelled as one, and passenger GPS replaces it when available. Unknown positions remain
null. - Location types are strictly categorized:
GPS_OBSERVED,STATION_OBSERVED,PROVIDER_ESTIMATED,APPLICATION_ESTIMATED,SIMULATED. - The offline simulator is for local demos and never runs in production.
- The data provider reports stations, not coordinates. Between stations the position is an estimate and is labelled as one, and passenger GPS replaces it when available. Unknown positions remain
- Honest WebSocket Freshness:
- Upstream data ingestion is decoupled from the 5-second WebSocket transport heartbeat.
- The UI shows the exact observation timestamp in Indian Standard Time (IST) and a real-time counter of elapsed seconds since the physical event occurred.
- Capability-Aware Fallback & Circuit Breakers:
- Primary: Railway Engine (60 req/min). Yesterday's and today's journeys are both checked, because a train that started yesterday can still be running.
- Secondary: RailRadar (Developer API).
- Reference: NTES (Official reference stub without brittle unauthorized scraping).
- Each provider has a circuit breaker with failure thresholds, recovery timeouts, and exponential backoff.
- Telescopic Distance Fare Calculation:
- Computes official Railway Board distance tariffs (Base Fare, Reservation Fee, Superfast Surcharge, GST, Tatkal caps) across 1A, 2A, 3A, 3E, CC, SL, 2S.
- Grounded LangGraph AI Assistant with xKiro API:
- Integrated with
https://api.xkiro.com/v1via OpenAI/Anthropic format. - Uses verified railway tools for train location, delays, ETAs, fares, and coach compositions.
- Natural query example:
"Where is train 12101 currently? How late is it, and when will it reach Pune?"
- Integrated with
| Feature | Method | Path | Description |
|---|---|---|---|
| Live Status | GET |
/api/v1/trains/{train_number}/status |
Real-time delay, current/next station, speed, GPS lat/lng, halts |
| Schedule | GET |
/api/v1/trains/{train_number}/schedule |
Official timetable, halts list, days of run |
| Route | GET |
/api/v1/trains/{train_number}/route |
GeoJSON route geometry coordinates for MapLibre |
| Train Search | GET |
/api/v1/trains/search?q={query} |
Search trains by partial name or 5-digit number |
| Station Search | GET |
/api/v1/stations/search?q={query} |
Search stations by city name or code |
| Station Details | GET |
/api/v1/stations/{station_code} |
Station coordinates, state, zone, division |
| Station Live Board | GET |
/api/v1/stations/{code}/live?hours=4 |
Arrivals and departures within 2, 4, or 8 hours |
| Coach Composition | GET |
/api/v1/trains/{number}/coaches |
Physical rake sequence (Locomotive to SLR) |
| Platform Numbers | GET |
/api/v1/trains/{number}/platforms |
Platform numbers across all scheduled halts |
| Fare Enquiry | GET |
/api/v1/trains/{number}/fare |
Telescopic fare breakdown across all classes & quotas |
| PNR Status | GET |
/api/v1/pnr/{pnr} |
10-digit PNR enquiry with privacy guarantee |
| AI Assistant | POST |
/api/v1/ai/chat |
Conversational LangGraph AI travel assistant |
| Live WebSockets | WS |
/ws/live-tracking/{train_number} |
Real-time telemetry broadcast with heartbeat |
| Provider Health | GET |
/providers/status |
Live circuit breaker states, latencies, failure counts |
- Python 3.11+
- Node.js 18+ & npm
- (Optional) Docker & Docker Compose
cd backend
python -m venv venv
# Windows:
venv\Scripts\activate
# Linux/macOS:
source venv/bin/activate
pip install -r requirements.txt
python -m uvicorn app.main:app --reload --port 8000Backend API will be available at: http://localhost:8000
Interactive OpenAPI Documentation at: http://localhost:8000/docs
cd backend
pytest tests/ -vcd frontend
npm install
npm run devFrontend UI will be live at: http://localhost:3000
To launch the complete stack (PostgreSQL + Redis + FastAPI Backend) using Docker Compose:
cd backend
docker-compose up --build -d- Push this repository to GitHub:
https://github.com/Aniketchavan7/Railway-App - Connect your GitHub repository to Cloudflare Pages.
- Set build settings:
- Framework preset: Next.js
- Build command:
npm run build - Build output directory:
.next(oroutif using static export) - Environment variables:
NEXT_PUBLIC_API_URL: Your deployed backend URL (e.g.https://railpulse-backend.onrender.com/api/v1)NEXT_PUBLIC_WS_URL: Your deployed WebSocket URL (e.g.wss://railpulse-backend.onrender.com/ws/live-tracking)
- Deploy
backend/using the includedrender.yamlorDockerfile. - Configure environment variables in the Render/Railway dashboard:
DATABASE_URL: Managed PostgreSQL connection string (or leave default for local SQLite).REDIS_URL: Managed Redis URL (e.g. Upstash Redis).RAILWAY_ENGINE_API_KEY: Your key fromrailengine.vercel.app.RAILRADAR_API_KEY: Your key fromrailradar.in.XKIRO_API_KEY: Your xKiro key fromapi.xkiro.com.XKIRO_BASE_URL:https://api.xkiro.com/v1.XKIRO_MODEL: Your model ID (e.g.google/gemini-2.5-flash).
Station coordinates in backend/app/data/stations.json are derived from DataMeet's Indian Railways data (CC0).
This project is licensed under the MIT License - see the LICENSE file for details.