# shashwat-19/real-time-traffic-analysis architecture

> Architecture diagram of the GitHub repository shashwat-19/real-time-traffic-analysis, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shashwat-19/real-time-traffic-analysis
- Repository: https://github.com/shashwat-19/real-time-traffic-analysis

## Overview

This platform collects TomTom traffic observations, persists them as CSV, derives congestion features, and serves analytics and predictions through an API and Streamlit dashboard. Its ML workflow trains and compares classifiers, saves the best model, and uses that artifact for inference. The README documents the scheduler and product capabilities; source excerpts show the collection, API, dashboard, feature, storage, and prediction calls. Training and evaluation modules are indexed, but evaluation internals were not sampled.

Main entry points: [`src/train.py`](https://github.com/shashwat-19/real-time-traffic-analysis/blob/main/src/train.py) (Model training), [`src/predict.py`](https://github.com/shashwat-19/real-time-traffic-analysis/blob/main/src/predict.py) (Congestion predictor), [`src/feature_engineering.py`](https://github.com/shashwat-19/real-time-traffic-analysis/blob/main/src/feature_engineering.py) (Traffic features), [`src/app.py`](https://github.com/shashwat-19/real-time-traffic-analysis/blob/main/src/app.py) (Streamlit dashboard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_collection["Traffic collection"]
  node_scheduler["Collection scheduler<br/>[main.py]"]
  node_fetcher["TomTom fetcher<br/>[data_fetcher.py]"]
end

subgraph group_data["Traffic data"]
  node_config["Runtime settings<br/>[config.py]"]
  node_repository[("CSV repository<br/>[data_storage.py]")]
  node_features["Traffic features"]
end

subgraph group_ml["Modeling and inference"]
  node_trainer["Model training<br/>[train.py]"]
  node_evaluation["Model evaluation<br/>[evaluate.py]"]
  node_preprocessing["Feature preprocessing<br/>[preprocessing.py]"]
  node_predictor["Congestion predictor<br/>[predict.py]"]
  node_model[("Persisted model")]
  node_metrics["Model metrics"]
end

subgraph group_products["User products"]
  node_api["FastAPI service<br/>[main.py]"]
  node_dashboard["Streamlit dashboard<br/>[app.py]"]
  node_map["Congestion map<br/>[map_generator.py]"]
end

node_tomtom(("TomTom Traffic API"))

node_scheduler -->|"loads settings"| node_config
node_scheduler -->|"fetches records"| node_fetcher
node_fetcher -->|"requests traffic"| node_tomtom
node_scheduler -->|"appends records"| node_repository
node_api -->|"reads records"| node_repository
node_api -->|"enriches records"| node_features
node_api -->|"requests prediction"| node_predictor
node_dashboard -->|"reads records"| node_repository
node_dashboard -->|"enriches records"| node_features
node_dashboard -->|"renders map"| node_map
node_dashboard -->|"requests prediction"| node_predictor
node_trainer -->|"loads settings"| node_config
node_trainer -->|"generates features"| node_features
node_trainer -->|"builds transformer"| node_preprocessing
node_trainer -->|"saves best model"| node_model
node_trainer -->|"writes metrics"| node_metrics
node_predictor -->|"generates features"| node_features
node_predictor -->|"uses feature columns"| node_preprocessing
node_predictor -->|"loads model"| node_model
node_evaluation -->|"uses feature engineering"| node_features
node_evaluation -->|"uses preprocessing"| node_preprocessing

click node_scheduler "https://github.com/shashwat-19/real-time-traffic-analysis/blob/main/main.py"
click node_fetcher "https://github.com/shashwat-19/real-time-traffic-analysis/blob/main/src/data_fetcher.py"
click node_config "https://github.com/shashwat-19/real-time-traffic-analysis/blob/main/src/config.py"
click node_repository "https://github.com/shashwat-19/real-time-traffic-analysis/blob/main/src/data_storage.py"
click node_features "https://github.com/shashwat-19/real-time-traffic-analysis/blob/main/src/feature_engineering.py"
click node_trainer "https://github.com/shashwat-19/real-time-traffic-analysis/blob/main/src/train.py"
click node_evaluation "https://github.com/shashwat-19/real-time-traffic-analysis/blob/main/src/evaluate.py"
click node_preprocessing "https://github.com/shashwat-19/real-time-traffic-analysis/blob/main/src/preprocessing.py"
click node_predictor "https://github.com/shashwat-19/real-time-traffic-analysis/blob/main/src/predict.py"
click node_metrics "https://github.com/shashwat-19/real-time-traffic-analysis/tree/main/outputs/metrics"
click node_api "https://github.com/shashwat-19/real-time-traffic-analysis/blob/main/api/main.py"
click node_dashboard "https://github.com/shashwat-19/real-time-traffic-analysis/blob/main/src/app.py"
click node_map "https://github.com/shashwat-19/real-time-traffic-analysis/blob/main/src/map_generator.py"

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_scheduler,node_fetcher toneBlue
class node_config,node_repository,node_features toneAmber
class node_trainer,node_evaluation,node_preprocessing,node_predictor,node_model,node_metrics,node_tomtom toneMint
class node_api,node_dashboard,node_map toneRose
```

## Components

### Traffic collection

- [Collection scheduler](https://github.com/shashwat-19/real-time-traffic-analysis/blob/main/main.py): `main.py`
- [TomTom fetcher](https://github.com/shashwat-19/real-time-traffic-analysis/blob/main/src/data_fetcher.py): `src/data_fetcher.py`

### Traffic data

- [Runtime settings](https://github.com/shashwat-19/real-time-traffic-analysis/blob/main/src/config.py): `src/config.py`
- [CSV repository](https://github.com/shashwat-19/real-time-traffic-analysis/blob/main/src/data_storage.py): `src/data_storage.py`
- [Traffic features](https://github.com/shashwat-19/real-time-traffic-analysis/blob/main/src/feature_engineering.py): `src/feature_engineering.py`

### Modeling and inference

- [Model training](https://github.com/shashwat-19/real-time-traffic-analysis/blob/main/src/train.py): `src/train.py`
- [Model evaluation](https://github.com/shashwat-19/real-time-traffic-analysis/blob/main/src/evaluate.py): `src/evaluate.py`
- [Feature preprocessing](https://github.com/shashwat-19/real-time-traffic-analysis/blob/main/src/preprocessing.py): `src/preprocessing.py`
- [Congestion predictor](https://github.com/shashwat-19/real-time-traffic-analysis/blob/main/src/predict.py): `src/predict.py`
- **Persisted model**
- [Model metrics](https://github.com/shashwat-19/real-time-traffic-analysis/tree/main/outputs/metrics): `outputs/metrics`

### User products

- [FastAPI service](https://github.com/shashwat-19/real-time-traffic-analysis/blob/main/api/main.py): `api/main.py`
- [Streamlit dashboard](https://github.com/shashwat-19/real-time-traffic-analysis/blob/main/src/app.py): `src/app.py`
- [Congestion map](https://github.com/shashwat-19/real-time-traffic-analysis/blob/main/src/map_generator.py): `src/map_generator.py`

### Other components

- **TomTom Traffic API**

## Connections

- Collection scheduler → Runtime settings: loads settings (evidence: `main.py`)
- Collection scheduler → TomTom fetcher: fetches records (evidence: `main.py`)
- TomTom fetcher → TomTom Traffic API: requests traffic (evidence: `src/data_fetcher.py`)
- Collection scheduler → CSV repository: appends records (evidence: `main.py`)
- FastAPI service → CSV repository: reads records (evidence: `api/main.py`)
- FastAPI service → Traffic features: enriches records (evidence: `api/main.py`)
- FastAPI service → Congestion predictor: requests prediction (evidence: `api/main.py`)
- Streamlit dashboard → CSV repository: reads records (evidence: `src/app.py`)
- Streamlit dashboard → Traffic features: enriches records (evidence: `src/app.py`)
- Streamlit dashboard → Congestion map: renders map (evidence: `src/app.py`)
- Streamlit dashboard → Congestion predictor: requests prediction (evidence: `src/app.py`)
- Model training → Runtime settings: loads settings (evidence: `src/train.py`)
- Model training → Traffic features: generates features (evidence: `src/train.py`)
- Model training → Feature preprocessing: builds transformer (evidence: `src/train.py`)
- Model training → Persisted model: saves best model (evidence: `src/train.py`)
- Model training → Model metrics: writes metrics (evidence: `src/train.py`)
- Congestion predictor → Traffic features: generates features (evidence: `src/predict.py`)
- Congestion predictor → Feature preprocessing: uses feature columns (evidence: `src/predict.py`)
- Congestion predictor → Persisted model: loads model (evidence: `src/predict.py`)
- Model evaluation → Traffic features: uses feature engineering (evidence: `src/evaluate.py`)
- Model evaluation → Feature preprocessing: uses preprocessing (evidence: `src/evaluate.py`)
