AI-powered railway traffic decision support system for Indian Railways section controllers. Built with OR-Tools CP-SAT, FastAPI, and Next.js.
AI-powered railway traffic decision support system for Indian Railways section controllers. Built with OR-Tools CP-SAT, FastAPI, and Next.js.
Role-based login with Google OAuth
Live controller dashboard with real-time train map
OR-Tools CP-SAT conflict resolution results
Performance analytics dashboard
| Patch | Change |
|---|---|
| P1 | Fixed 401 auth gate on /simulate and /analytics — isAuthReady guard prevents API calls before JWT hydration |
| P2 | WebSocket telemetry upgraded from mock random data → real IRCTC RapidAPI live positions with per-train 60s cache |
| P3 | Dashboard sidebar shows live delay, current station and colored status dot inline after Fetch |
| P4 | Simulate page: dynamic location + train dropdowns from DB, fixed POST payload schema, OR-Tools results panel |
| P5 | Analytics page: functional period/section dropdowns, KPI deltas computed from sparklines, flat-data notice |
| P6 | Real-time conflict detection: RUNNING train pairs auto-detected → ephemeral RT- conflicts merged with DB conflicts |
| P7 | AI Assistant grounded in live context: active conflicts, running trains, recent decisions injected every message |
| P8 | UI/UX polish: mobile sidebar toggle, loading skeletons, error boundaries, chart warnings fixed, reset clears results |
| P9 | Admin page: System Health with colored dots + refresh, Invite User modal, Edit user form, status toggle |
| P10 | Performance: RapidAPI exponential backoff + circuit breaker, WebSocket reconnect with amber state, React Query staleTime, DB connection pooling |
| 🚆 Real-time train tracking on NR-42 corridor | 🤖 AI conflict detection & resolution | ⚡ Google OR-Tools CP-SAT v9.x precedence optimization |
| 📊 Performance analytics & KPI dashboards | 👥 Role-based access (Admin/Controller/Supervisor/Logistics) | 🔐 JWT auth + Google OAuth |
| 📧 Email invite system (Resend API) | 🏥 Real-time system health monitoring | 🔌 IRCTC live train data integration |
| 📡 WebSocket live telemetry | 🚫 403 guard for non-admin routes | 🌐 Production deployed (Vercel + Railway) |
Browser (Next.js) ──── REST + WebSocket ────► FastAPI (Python 3.11)
│ │ │
PostgreSQL OR-Tools Groq
(Railway) CP-SAT Llama 3
│
IRCTC RapidAPI
Resend Email API
Note: Test the live application at https://railtrack-ai-ntlv.vercel.app. Use the credentials below to explore different dashboards.
Role Password Access Description Admin admin@demo.rail demo1234 Full system configuration and user management. Controller controller@demo.rail demo1234 Traffic monitoring and AI conflict resolution. Supervisor supervisor@demo.rail demo1234 System analytics and high-level reports. Logistics logistics@demo.rail demo1234 Freight scheduling and delayed train tracking. Guest guest@demo.rail demo1234 Read-only access to select dashboards.
Click to expand local setup instructions
- Node.js (for TypeScript, TailwindCSS, TanStack Query, NextAuth.js v4 frontend)
- Python 3.11 (for backend)
- PostgreSQL database
cd backend
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install requirements including SQLAlchemy async and asyncpg
pip install -r requirements.txt
cp .env.example .env
# Run database migrations
alembic upgrade head
# Start FastAPI server
uvicorn app.main:app --reloadcd railtrack-ai
npm install
cp .env.example .env.local
# Start Next.js development server
npm run devAPI Documentation: https://railtrack-ai-production.up.railway.app/docs
| Method | Path | Auth Required | Description |
|---|---|---|---|
POST |
/api/auth/login |
No | Authenticate user and issue bcrypt-hashed JWT |
GET |
/api/trains/live |
Yes | Retrieve real-time train positions from IRCTC |
POST |
/api/solver/run |
Yes (Controller) | Execute Google OR-Tools CP-SAT resolution |
GET |
/api/analytics/kpi |
Yes (Admin/Supervisor) | Fetch performance analytics data |
GET |
/ws/telemetry |
Token in query | WebSocket endpoint for live map updates |
- Vercel (Frontend): https://railtrack-ai-ntlv.vercel.app
- Railway (Backend API + DB): https://railtrack-ai-production.up.railway.app/docs
- Complex CP-SAT Solver Integration: Modeling railway preemption and scheduling using a strict constraint-programming approach is mathematically rigorous and non-trivial compared to standard CRUD applications.
- Asynchronous FastAPI + PostgreSQL: Fully async Python backend utilizing
asyncpgcombined with SQLAlchemy async ensures high concurrency when processing real-time WebSocket telemetry and computationally heavy solver results. - Three-Layer Role-Based Auth: A robust security model that seamlessly mixes standard NextAuth.js on the edge, custom JWT validation in FastAPI middlewares, and granular row-level and route-level authorization restrictions.
- Live AI Assistant with Real-Time Context: Unlike static chatbots, the AI assistant receives a fresh system prompt on every message containing actual conflict IDs, running train names, delays, and recent controller decisions — making it genuinely context-aware rather than hallucinating.
- Real-Time Conflict Engine: Auto-detects crossing conflicts by grouping RUNNING trains by section and generating ephemeral RT- conflict pairs — no manual seeding required. Severity is inferred from train priority (EXPRESS pair = HIGH).
Built solo by Anudeep GRS as Team Lead for SIH 2024
MIT