# medbensaad26-cell/tunisia_ai_traffic_map architecture

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

- Interactive diagram: https://gitdiagram.com/medbensaad26-cell/tunisia_ai_traffic_map
- Repository: https://github.com/medbensaad26-cell/tunisia_ai_traffic_map

## Overview

Tunisia AI Traffic Map lets users choose Tunisian locations, compare candidate routes, and receive congestion predictions and a recommended route. The runtime path is visible across the frontend and FastAPI server: the frontend obtains routes, derives route and time features, calls the prediction endpoint, and displays the response. The README also describes OSM-based road-data preparation, synthetic traffic generation, feature engineering, and model training, but the repository tree exposes these only as documentation PDFs, so they are represented as documented capabilities rather than inferred runtime modules.

Main entry points: [`main.py`](https://github.com/medbensaad26-cell/tunisia_ai_traffic_map/blob/main/main.py) (Prediction API), [`app.js`](https://github.com/medbensaad26-cell/tunisia_ai_traffic_map/blob/main/app.js) (Map and search UI), [`documentation`](https://github.com/medbensaad26-cell/tunisia_ai_traffic_map/tree/main/documentation) (Synthetic traffic generation), [`tunisia_model.pkl`](https://github.com/medbensaad26-cell/tunisia_ai_traffic_map/blob/main/tunisia_model.pkl) (Congestion classifier)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Map interface"]
  node_map_ui["Map and search UI<br/>[app.js]"]
  node_geocoding["Location search<br/>[app.js]"]
  node_results_ui["Recommendation display<br/>[app.js]"]
end

subgraph group_routing["Route analysis"]
  node_route_lookup["Route alternatives<br/>[app.js]"]
  node_feature_extraction["Route feature extraction<br/>[app.js]"]
  node_time_context["Temporal features<br/>[app.js]"]
end

subgraph group_inference["Prediction service"]
  node_prediction_api["Prediction API<br/>[main.py]"]
  node_request_validation["Route validation<br/>[main.py]"]
  node_classifier["Congestion classifier<br/>[tunisia_model.pkl]"]
  node_model_metadata["Model metadata"]
end

subgraph group_training["Model development"]
  node_road_extraction["Road network extraction"]
  node_traffic_simulation["Synthetic traffic generation"]
  node_training_features["Training feature engineering"]
  node_model_training["Model training"]
end

node_user(("Traveler"))
node_map_tiles["OpenStreetMap tiles"]
node_photon["Photon geocoder"]
node_osrm["OSRM routing"]

node_user -->|"chooses locations"| node_map_ui
node_map_ui -->|"loads tiles"| node_map_tiles
node_map_ui -->|"enters query"| node_geocoding
node_geocoding -->|"geocodes"| node_photon
node_map_ui -->|"requests routes"| node_route_lookup
node_route_lookup -->|"retrieves alternatives"| node_osrm
node_route_lookup -->|"extracts features"| node_feature_extraction
node_feature_extraction -->|"uses time features"| node_time_context
node_feature_extraction -->|"posts route features"| node_prediction_api
node_prediction_api -->|"validates routes"| node_request_validation
node_prediction_api -->|"predicts classes"| node_classifier
node_prediction_api -->|"reads feature labels"| node_model_metadata
node_prediction_api -->|"returns predictions"| node_results_ui
node_results_ui -->|"shows recommendation"| node_user
node_road_extraction -.->|"supplies road data"| node_traffic_simulation
node_traffic_simulation -.->|"generates labeled data"| node_training_features
node_training_features -.->|"supplies training data"| node_model_training
node_model_training -.->|"produces model"| node_classifier

click node_map_ui "https://github.com/medbensaad26-cell/tunisia_ai_traffic_map/blob/main/app.js"
click node_geocoding "https://github.com/medbensaad26-cell/tunisia_ai_traffic_map/blob/main/app.js"
click node_route_lookup "https://github.com/medbensaad26-cell/tunisia_ai_traffic_map/blob/main/app.js"
click node_feature_extraction "https://github.com/medbensaad26-cell/tunisia_ai_traffic_map/blob/main/app.js"
click node_time_context "https://github.com/medbensaad26-cell/tunisia_ai_traffic_map/blob/main/app.js"
click node_results_ui "https://github.com/medbensaad26-cell/tunisia_ai_traffic_map/blob/main/app.js"
click node_prediction_api "https://github.com/medbensaad26-cell/tunisia_ai_traffic_map/blob/main/main.py"
click node_request_validation "https://github.com/medbensaad26-cell/tunisia_ai_traffic_map/blob/main/main.py"
click node_classifier "https://github.com/medbensaad26-cell/tunisia_ai_traffic_map/blob/main/tunisia_model.pkl"
click node_model_metadata "https://github.com/medbensaad26-cell/tunisia_ai_traffic_map/blob/main/model_metadata.json"
click node_road_extraction "https://github.com/medbensaad26-cell/tunisia_ai_traffic_map/tree/main/documentation"
click node_traffic_simulation "https://github.com/medbensaad26-cell/tunisia_ai_traffic_map/tree/main/documentation"
click node_training_features "https://github.com/medbensaad26-cell/tunisia_ai_traffic_map/tree/main/documentation"
click node_model_training "https://github.com/medbensaad26-cell/tunisia_ai_traffic_map/tree/main/documentation"

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_map_ui,node_geocoding,node_results_ui toneBlue
class node_route_lookup,node_feature_extraction,node_time_context toneAmber
class node_prediction_api,node_request_validation,node_classifier,node_model_metadata toneMint
class node_road_extraction,node_traffic_simulation,node_training_features,node_model_training toneRose
class node_user,node_map_tiles,node_photon,node_osrm toneIndigo
```

## Components

### Map interface

- [Map and search UI](https://github.com/medbensaad26-cell/tunisia_ai_traffic_map/blob/main/app.js): `app.js`
- [Location search](https://github.com/medbensaad26-cell/tunisia_ai_traffic_map/blob/main/app.js): `app.js`
- [Recommendation display](https://github.com/medbensaad26-cell/tunisia_ai_traffic_map/blob/main/app.js): `app.js`

### Route analysis

- [Route alternatives](https://github.com/medbensaad26-cell/tunisia_ai_traffic_map/blob/main/app.js): `app.js`
- [Route feature extraction](https://github.com/medbensaad26-cell/tunisia_ai_traffic_map/blob/main/app.js): `app.js`
- [Temporal features](https://github.com/medbensaad26-cell/tunisia_ai_traffic_map/blob/main/app.js): `app.js`

### Prediction service

- [Prediction API](https://github.com/medbensaad26-cell/tunisia_ai_traffic_map/blob/main/main.py): `main.py`
- [Route validation](https://github.com/medbensaad26-cell/tunisia_ai_traffic_map/blob/main/main.py): `main.py`
- [Congestion classifier](https://github.com/medbensaad26-cell/tunisia_ai_traffic_map/blob/main/tunisia_model.pkl): `tunisia_model.pkl`
- [Model metadata](https://github.com/medbensaad26-cell/tunisia_ai_traffic_map/blob/main/model_metadata.json): `model_metadata.json`

### Model development

- [Road network extraction](https://github.com/medbensaad26-cell/tunisia_ai_traffic_map/tree/main/documentation): `documentation`
- [Synthetic traffic generation](https://github.com/medbensaad26-cell/tunisia_ai_traffic_map/tree/main/documentation): `documentation`
- [Training feature engineering](https://github.com/medbensaad26-cell/tunisia_ai_traffic_map/tree/main/documentation): `documentation`
- [Model training](https://github.com/medbensaad26-cell/tunisia_ai_traffic_map/tree/main/documentation): `documentation`

### Other components

- **Traveler**
- **OpenStreetMap tiles**
- **Photon geocoder**
- **OSRM routing**

## Connections

- Traveler → Map and search UI: chooses locations (evidence: `README.md`)
- Map and search UI → OpenStreetMap tiles: loads tiles (evidence: `app.js`)
- Map and search UI → Location search: enters query (evidence: `app.js`)
- Location search → Photon geocoder: geocodes (evidence: `app.js`)
- Map and search UI → Route alternatives: requests routes (evidence: `README.md`)
- Route alternatives → OSRM routing: retrieves alternatives (evidence: `README.md`)
- Route alternatives → Route feature extraction: extracts features (evidence: `README.md`)
- Route feature extraction → Temporal features: uses time features (evidence: `app.js`)
- Route feature extraction → Prediction API: posts route features (evidence: `app.js`)
- Prediction API → Route validation: validates routes (evidence: `main.py`)
- Prediction API → Congestion classifier: predicts classes (evidence: `main.py`)
- Prediction API → Model metadata: reads feature labels (evidence: `main.py`)
- Prediction API → Recommendation display: returns predictions (evidence: `README.md`)
- Recommendation display → Traveler: shows recommendation (evidence: `README.md`)
- Road network extraction → Synthetic traffic generation: supplies road data (evidence: `README.md`)
- Synthetic traffic generation → Training feature engineering: generates labeled data (evidence: `README.md`)
- Training feature engineering → Model training: supplies training data (evidence: `README.md`)
- Model training → Congestion classifier: produces model (evidence: `README.md`)
