# walker65434/train_prediction architecture

> Architecture diagram of the GitHub repository walker65434/train_prediction, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/walker65434/train_prediction
- Repository: https://github.com/walker65434/train_prediction

## Overview

Train Prediction is a web application for starting train watches and viewing live train status, route details, and predicted delay. Users enter or upload train information, then follow a train on the tracking page. The API gateway manages watch sessions and results; RabbitMQ connects watch requests to the ML service, which fetches live data from RailRadar and produces predictions. The tree also shows a broader set of business analytics pipelines in the ML service. Their exact orchestration and several frontend/API links are not established by the sampled source, so those relationships are left out.

Main entry points: [`apps/api-gateway/src/app.js`](https://github.com/walker65434/train_prediction/blob/main/apps/api-gateway/src/app.js) (HTTP gateway), [`apps/frontend/src/App.jsx`](https://github.com/walker65434/train_prediction/blob/main/apps/frontend/src/App.jsx) (Web app), [`apps/frontend/src/pages/TrackPage.jsx`](https://github.com/walker65434/train_prediction/blob/main/apps/frontend/src/pages/TrackPage.jsx) (Tracking page), [`apps/api-gateway/src/modules/watch/watch.controller.js`](https://github.com/walker65434/train_prediction/blob/main/apps/api-gateway/src/modules/watch/watch.controller.js) (Watch sessions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["User interface"]
  node_app["Web app<br/>[App.jsx]"]
  node_home["Home page<br/>[HomePage.jsx]"]
  node_uploader["Ticket upload<br/>[TicketUploader.jsx]"]
  node_ocr["Ticket OCR<br/>[ocr.js]"]
  node_track["Tracking page<br/>[TrackPage.jsx]"]
  node_metrics["Live metrics"]
  node_timeline["Route timeline<br/>[RouteTimeline.jsx]"]
  node_api_client["API client<br/>[api.js]"]
  node_socket_client["Socket client<br/>[socket.js]"]
end

subgraph group_gateway["API gateway"]
  node_gateway_app["HTTP gateway<br/>[app.js]"]
  node_watch_controller["Watch sessions"]
  node_watch_store[("Watch records<br/>[watch.model.js]")]
  node_result_controller["Result endpoint"]
  node_result_store[("Prediction results<br/>[result.model.js]")]
end

subgraph group_messaging["Async messaging"]
  node_start_producer["Start producer<br/>[start.producer.js]"]
end

subgraph group_ml["Prediction service"]
  node_ml_worker["Queue consumers<br/>[consumers.py]"]
  node_prediction_service["ETA prediction"]
  node_model["Loaded model<br/>[model_loader.py]"]
  node_predict_route["Prediction route<br/>[predict.py]"]
  node_analytics["Business analytics pipelines"]
end

node_user(("Train user"))
node_broker["RabbitMQ"]
node_railradar["RailRadar live API"]

node_user -->|"uses"| node_app
node_app -->|"routes"| node_home
node_app -->|"routes"| node_track
node_home -->|"offers upload"| node_uploader
node_uploader -->|"extracts text"| node_ocr
node_track -->|"displays"| node_metrics
node_track -->|"displays"| node_timeline
node_api_client -->|"HTTP requests"| node_gateway_app
node_socket_client -.->|"socket connection"| node_gateway_app
node_gateway_app -->|"routes watch requests"| node_watch_controller
node_gateway_app -->|"routes result requests"| node_result_controller
node_watch_controller -->|"creates and counts"| node_watch_store
node_watch_controller -->|"publishes start"| node_start_producer
node_start_producer -->|"sends message"| node_broker
node_ml_worker -->|"consumes messages"| node_broker
node_ml_worker -->|"invokes"| node_prediction_service
node_prediction_service -.->|"fetches live data"| node_railradar
node_prediction_service -->|"loads for inference"| node_model
node_gateway_app -->|"connects"| node_broker
node_gateway_app -->|"connects database"| node_result_store
node_result_controller -->|"reads result"| node_result_store

click node_app "https://github.com/walker65434/train_prediction/blob/main/apps/frontend/src/App.jsx"
click node_home "https://github.com/walker65434/train_prediction/blob/main/apps/frontend/src/pages/HomePage.jsx"
click node_uploader "https://github.com/walker65434/train_prediction/blob/main/apps/frontend/src/components/TicketUploader.jsx"
click node_ocr "https://github.com/walker65434/train_prediction/blob/main/apps/frontend/src/lib/ocr.js"
click node_track "https://github.com/walker65434/train_prediction/blob/main/apps/frontend/src/pages/TrackPage.jsx"
click node_metrics "https://github.com/walker65434/train_prediction/blob/main/apps/frontend/src/components/LiveMetricsGrid.jsx"
click node_timeline "https://github.com/walker65434/train_prediction/blob/main/apps/frontend/src/components/RouteTimeline.jsx"
click node_api_client "https://github.com/walker65434/train_prediction/blob/main/apps/frontend/src/lib/api.js"
click node_socket_client "https://github.com/walker65434/train_prediction/blob/main/apps/frontend/src/lib/socket.js"
click node_gateway_app "https://github.com/walker65434/train_prediction/blob/main/apps/api-gateway/src/app.js"
click node_watch_controller "https://github.com/walker65434/train_prediction/blob/main/apps/api-gateway/src/modules/watch/watch.controller.js"
click node_watch_store "https://github.com/walker65434/train_prediction/blob/main/apps/api-gateway/src/modules/watch/watch.model.js"
click node_result_controller "https://github.com/walker65434/train_prediction/blob/main/apps/api-gateway/src/modules/result/result.controller.js"
click node_result_store "https://github.com/walker65434/train_prediction/blob/main/apps/api-gateway/src/modules/result/result.model.js"
click node_start_producer "https://github.com/walker65434/train_prediction/blob/main/apps/api-gateway/src/queues/start.producer.js"
click node_ml_worker "https://github.com/walker65434/train_prediction/blob/main/apps/ml-service/app/workers/consumers.py"
click node_prediction_service "https://github.com/walker65434/train_prediction/blob/main/apps/ml-service/app/services/prediction_service.py"
click node_model "https://github.com/walker65434/train_prediction/blob/main/apps/ml-service/app/core/model_loader.py"
click node_predict_route "https://github.com/walker65434/train_prediction/blob/main/apps/ml-service/app/api/routes/predict.py"
click node_analytics "https://github.com/walker65434/train_prediction/tree/main/apps/ml-service/app/pipelines"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_home,node_uploader,node_ocr,node_track,node_metrics,node_timeline,node_api_client,node_socket_client,node_user toneBlue
class node_gateway_app,node_watch_controller,node_watch_store,node_result_controller,node_result_store toneAmber
class node_start_producer,node_railradar toneMint
class node_ml_worker,node_prediction_service,node_model,node_predict_route,node_analytics toneRose
class node_broker toneIndigo
```

## Components

### User interface

- [Web app](https://github.com/walker65434/train_prediction/blob/main/apps/frontend/src/App.jsx): `apps/frontend/src/App.jsx`
- [Home page](https://github.com/walker65434/train_prediction/blob/main/apps/frontend/src/pages/HomePage.jsx): `apps/frontend/src/pages/HomePage.jsx`
- [Ticket upload](https://github.com/walker65434/train_prediction/blob/main/apps/frontend/src/components/TicketUploader.jsx): `apps/frontend/src/components/TicketUploader.jsx`
- [Ticket OCR](https://github.com/walker65434/train_prediction/blob/main/apps/frontend/src/lib/ocr.js): `apps/frontend/src/lib/ocr.js`
- [Tracking page](https://github.com/walker65434/train_prediction/blob/main/apps/frontend/src/pages/TrackPage.jsx): `apps/frontend/src/pages/TrackPage.jsx`
- [Live metrics](https://github.com/walker65434/train_prediction/blob/main/apps/frontend/src/components/LiveMetricsGrid.jsx): `apps/frontend/src/components/LiveMetricsGrid.jsx`
- [Route timeline](https://github.com/walker65434/train_prediction/blob/main/apps/frontend/src/components/RouteTimeline.jsx): `apps/frontend/src/components/RouteTimeline.jsx`
- [API client](https://github.com/walker65434/train_prediction/blob/main/apps/frontend/src/lib/api.js): `apps/frontend/src/lib/api.js`
- [Socket client](https://github.com/walker65434/train_prediction/blob/main/apps/frontend/src/lib/socket.js): `apps/frontend/src/lib/socket.js`

### API gateway

- [HTTP gateway](https://github.com/walker65434/train_prediction/blob/main/apps/api-gateway/src/app.js): `apps/api-gateway/src/app.js`
- [Watch sessions](https://github.com/walker65434/train_prediction/blob/main/apps/api-gateway/src/modules/watch/watch.controller.js): `apps/api-gateway/src/modules/watch/watch.controller.js`
- [Watch records](https://github.com/walker65434/train_prediction/blob/main/apps/api-gateway/src/modules/watch/watch.model.js): `apps/api-gateway/src/modules/watch/watch.model.js`
- [Result endpoint](https://github.com/walker65434/train_prediction/blob/main/apps/api-gateway/src/modules/result/result.controller.js): `apps/api-gateway/src/modules/result/result.controller.js`
- [Prediction results](https://github.com/walker65434/train_prediction/blob/main/apps/api-gateway/src/modules/result/result.model.js): `apps/api-gateway/src/modules/result/result.model.js`

### Async messaging

- [Start producer](https://github.com/walker65434/train_prediction/blob/main/apps/api-gateway/src/queues/start.producer.js): `apps/api-gateway/src/queues/start.producer.js`

### Prediction service

- [Queue consumers](https://github.com/walker65434/train_prediction/blob/main/apps/ml-service/app/workers/consumers.py): `apps/ml-service/app/workers/consumers.py`
- [ETA prediction](https://github.com/walker65434/train_prediction/blob/main/apps/ml-service/app/services/prediction_service.py): `apps/ml-service/app/services/prediction_service.py`
- [Loaded model](https://github.com/walker65434/train_prediction/blob/main/apps/ml-service/app/core/model_loader.py): `apps/ml-service/app/core/model_loader.py`
- [Prediction route](https://github.com/walker65434/train_prediction/blob/main/apps/ml-service/app/api/routes/predict.py): `apps/ml-service/app/api/routes/predict.py`
- [Business analytics pipelines](https://github.com/walker65434/train_prediction/tree/main/apps/ml-service/app/pipelines): `apps/ml-service/app/pipelines`

### Other components

- **Train user**
- **RabbitMQ**
- **RailRadar live API**

## Connections

- Train user → Web app: uses
- Web app → Home page: routes
- Web app → Tracking page: routes
- Home page → Ticket upload: offers upload
- Ticket upload → Ticket OCR: extracts text
- Tracking page → Live metrics: displays
- Tracking page → Route timeline: displays
- API client → HTTP gateway: HTTP requests
- Socket client → HTTP gateway: socket connection
- HTTP gateway → Watch sessions: routes watch requests
- HTTP gateway → Result endpoint: routes result requests
- Watch sessions → Watch records: creates and counts
- Watch sessions → Start producer: publishes start
- Start producer → RabbitMQ: sends message
- Queue consumers → RabbitMQ: consumes messages
- Queue consumers → ETA prediction: invokes
- ETA prediction → RailRadar live API: fetches live data
- ETA prediction → Loaded model: loads for inference
- HTTP gateway → RabbitMQ: connects
- HTTP gateway → Prediction results: connects database
- Result endpoint → Prediction results: reads result
