How karthikrv1107/ai-driven-train-induction-planning-scheduling-for-kochi-metro-rail-limited-kmrl- works
Purpose and Entry Points
KMRL NexusAI is a nightly train-induction planning and scheduling platform for Kochi Metro. It combines operational dashboards, optimization, ML/RL decision support, simulation, and governed rollout controls. The user entry point is the Next.js application rooted at frontend/src/app/page.tsx; the backend service entry point is backend/app/main.py. API documentation is expected through FastAPI, while deployment begins with Docker Compose or Kubernetes.
Operator Web Application
The Next.js 15 frontend provides role-oriented operational views for dashboard, fleet, depot, maintenance, scheduler, alerts, analytics, and executive reporting. Shared application framing and API access are centralized in:
• frontend/src/app/layout.tsx
• frontend/src/components/layout/AppChrome.tsx
• frontend/src/lib/api.ts
Planning recommendations are rendered as UI components, including frontend/src/components/ai/AIRecommendationCard.tsx, rather than exposing optimization internals directly to browser code.
Backend Orchestration and Persistence
FastAPI coordinates platform capabilities and configuration. SQLAlchemy models and Alembic/schema assets define the durable operational data boundary, backed by PostgreSQL. Key paths:
• backend/app/main.py
• backend/app/models/models.py
• backend/app/db/migrations/001_initial_schema.py
Runtime configuration is supplied through backend/app/core/config.py. PostgreSQL is the system of record; Redis supports caching and task-queue use.
Planning Intelligence Pipeline
The core decision path combines feature preparation, predictive/ML processing, operations-research scheduling, RL behavior, and scenario validation:
• backend/app/ml/feature_store.py
• backend/app/ml/pipeline.py
• backend/app/optimization/engine.py
• backend/app/rl/agent.py
• backend/app/simulation/engine.py
The optimization engine uses OR-Tools to generate induction plans under fleet, depot, maintenance, and planning-window constraints. ML tooling (XGBoost, PyTorch, scikit-learn, SHAP) supplies predictive inputs/explanations; RL can refine choices. Simulation is a validation boundary before operational use.
Events, Async Work, and External Integration
Kafka is the event backbone for operational ingestion and downstream reactions, with consumer behavior in backend/app/kafka_consumer.py. Celery workers execute asynchronous processing via backend/app/workers.py. The Maximo adapter provides the enterprise maintenance-system boundary:
• backend/app/integrations/maximo.py
• backend/app/kafka_consumer.py
• backend/app/workers.py
MinIO is the designated object/file-storage service. Kafka UI and Flower are operational support services in the Docker environment.
Governance, Safety, and Reporting
Recommendations are not assumed to be immediately autonomous. Shadow-mode control permits observation or constrained rollout; governance modules track change management and produce executive-level outputs:
• backend/app/shadow_mode/controller.py
• backend/app/governance/change_management.py
• backend/app/governance/executive_reporting.py
• backend/app/reports/generator.py
Security boundaries include SSO/MFA, secret management through Vault, and a WAF layer:
• backend/app/security/sso_mfa.py
• backend/app/security/vault.py
• backend/app/security/waf.py
Operations and Deployment
Container deployment packages the API and frontend separately, with local/prod composition. Kubernetes/Helm support scalable deployment, including multi-region topology. Prometheus, Grafana, Jaeger/OpenTelemetry, and application telemetry provide observability:
• infra/docker/docker-compose.yml
• infra/k8s/base/deployment.yaml
• infra/helm/kmrl/values.yaml
• backend/app/observability/telemetry.py
• infra/k8s/base/jaeger-otel.yaml
Main entry points: main.py FastAPI orchestration · docker-compose.yml Container and Kubernetes deployment · workers.py Celery async workers · controller.py Shadow-mode controller
Components 22
Operator Web App
- Metro operators
- Next.js operational views · Role-oriented dashboards and planning views.
frontend/src/app/page.tsx - App shell and API client
frontend/src/components/layout/AppChrome.tsx - Recommendation cards
frontend/src/components/ai/AIRecommendationCard.tsx
Backend Platform
- FastAPI orchestration · Coordinates operational data, planning, and governed recommendations.
backend/app/main.py - PostgreSQL system of record
backend/app/models/models.py - Redis cache and broker
- Kafka event backbone
backend/app/kafka_consumer.py - Celery async workers
backend/app/workers.py - Maximo adapter
backend/app/integrations/maximo.py - MinIO object storage
Planning Intelligence
- Feature preparation
backend/app/ml/feature_store.py - Predictive ML pipeline
backend/app/ml/pipeline.py - Induction plan optimizer · Builds plans under fleet, depot, maintenance, and time-window constraints.
backend/app/optimization/engine.py - RL refinement
backend/app/rl/agent.py - Scenario simulation · Validates candidate plans before operational use.
backend/app/simulation/engine.py
Governance & Safety
- Shadow-mode controller · Observes or constrains recommendation rollout.
backend/app/shadow_mode/controller.py - Change management
backend/app/governance/change_management.py - Executive reporting
backend/app/governance/executive_reporting.py - SSO/MFA, Vault, and WAF
backend/app/security/sso_mfa.py
Runtime & Operations
- Container and Kubernetes deployment
infra/docker/docker-compose.yml - Telemetry and tracing · Feeds Prometheus, Grafana, and Jaeger tooling.
backend/app/observability/telemetry.py
Connections 26
- Metro operators → Next.js operational views: uses
- Next.js operational views → App shell and API client: framed by
- App shell and API client → FastAPI orchestration: API requests
- FastAPI orchestration → SSO/MFA, Vault, and WAF: protected by
- FastAPI orchestration → PostgreSQL system of record: reads and writes
- FastAPI orchestration → Redis cache and broker: caches and queues
- FastAPI orchestration → Kafka event backbone: publishes events
- Kafka event backbone → Celery async workers: triggers async work
- Celery async workers → Maximo adapter: syncs maintenance data
- Celery async workers → Feature preparation: prepares features
- Maximo adapter → Kafka event backbone: maintenance events
- PostgreSQL system of record → Feature preparation: operational inputs
- Feature preparation → Predictive ML pipeline: features
- Predictive ML pipeline → Induction plan optimizer: predictions and explanations
- Induction plan optimizer → RL refinement: candidate plans
- RL refinement → Scenario simulation: refined plans
- Scenario simulation → Shadow-mode controller: validated plans
- Shadow-mode controller → FastAPI orchestration: governed recommendations
- FastAPI orchestration → Recommendation cards: serves recommendations
- Shadow-mode controller → Change management: rollout records
- Change management → Executive reporting: governance inputs
- FastAPI orchestration → MinIO object storage: stores files
- FastAPI orchestration → Telemetry and tracing: emits telemetry
- Container and Kubernetes deployment → Next.js operational views: deploys
- Container and Kubernetes deployment → FastAPI orchestration: deploys
- Container and Kubernetes deployment → Telemetry and tracing: provisions