# vedhakoushik/accident-prediction-analysis architecture

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

- Interactive diagram: https://gitdiagram.com/vedhakoushik/accident-prediction-analysis
- Repository: https://github.com/vedhakoushik/accident-prediction-analysis

## Overview

1. This repository is centered on an accident-risk prediction system with a Python backend, a dataset-driven ML pipeline, and separate offline analysis/reporting scripts. The core serving path is FastAPI-based; the data science and visualization work is split out from the API.

2. The main data source is `df.csv`, which appears to be the training/analysis dataset for accident risk modeling. It is the primary input to both model development and any derived risk predictions exposed by the backend.

3. `predict.py` is the model and inference layer. Based on the README, it likely contains the training pipeline plus prediction logic reused by the API rather than embedding model logic directly in the web server. This creates a clear boundary between ML computation and request handling.

4. `backend/main.py` is the application entrypoint for the FastAPI service. It exposes the runtime API for:
   - metadata retrieval,
   - single-point prediction,
   - route prediction.
   This is the main integration surface for any client application.

5. `backend/city_data.py` is a supporting data/metadata module. It likely stores city-specific or route-related information needed to normalize inputs, look up locations, or enrich predictions with geographic context. This is a lightweight domain-data boundary between the API and the prediction logic.

6. Route prediction has an external dependency on OpenRouteService, controlled by `ORS_API_KEY`. If the key is present, the backend can use routing data from that service; if not, it falls back to alternate behavior. That makes routing a conditional external integration, not a hard dependency.

7. `main.py` at the repository root is separate from the API server and is described as an analysis/visualization script. It likely drives exploratory data analysis, chart generation, or result comparison for the project’s documentation rather than serving requests.

8. The `.docx` files in the root are report artifacts, not runtime components. They appear to capture the methodology, EDA, model comparison, accuracy results, and conclusion/future work, which suggests the repo also serves as a research/project delivery package.

9. The README references a React + Vite + React Leaflet frontend, even though that frontend directory is not included in the provided tree. Architecturally, that frontend is the presentation layer and consumes the FastAPI backend through the configured `VITE_API_BASE_URL`.

10. The system boundary is therefore:
    - data and model assets (`df.csv`, `predict.py`, `city_data.py`),
    - serving layer (`backend/main.py` via Uvicorn),
    - offline analysis/reporting (`main.py`, `.docx` outputs),
    - optional external routing service (OpenRouteService),
    - and, per README, an external browser client.

11. In deployment terms, the backend runs on Python 3.11+ as an ASGI app, while the client side uses Node.js 18+ in development. The backend is the authoritative prediction engine; the frontend is just a consumer of its HTTP API.

Main entry points: [`backend/main.py`](https://github.com/vedhakoushik/accident-prediction-analysis/blob/main/backend/main.py) (API App), [`main.py`](https://github.com/vedhakoushik/accident-prediction-analysis/blob/main/main.py) (Analysis Script), [`predict.py`](https://github.com/vedhakoushik/accident-prediction-analysis/blob/main/predict.py) (Predict Engine), [`README.md`](https://github.com/vedhakoushik/accident-prediction-analysis/blob/main/README.md) (README)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_data_model["Data & Model"]
  node_node_dataset[("Training Data<br/>dataset<br/>[df.csv]")]
  node_node_predict["Predict Engine<br/>ml pipeline<br/>[predict.py]"]
  node_node_city_data["City Data<br/>domain metadata<br/>[city_data.py]"]
end

subgraph group_group_api["Serving Layer"]
  node_node_backend_main["API App<br/>[main.py]"]
  node_node_metadata_ep(("Metadata API<br/>endpoint set<br/>[main.py]"))
  node_node_single_pred_ep(("Single Prediction<br/>endpoint<br/>[main.py]"))
  node_node_route_pred_ep(("Route Prediction<br/>endpoint<br/>[main.py]"))
end

subgraph group_group_offline["Offline Analysis"]
  node_node_offline_main["Analysis Script<br/>eda/report script<br/>[main.py]"]
  node_node_eda_doc["EDA Output<br/>report artifact"]
  node_node_methods_doc["Methods Doc<br/>report artifact"]
  node_node_compare_doc["Comparison Doc<br/>report artifact"]
  node_node_results_doc["Results Doc<br/>report artifact"]
  node_node_conclusion_doc["Conclusion Doc<br/>report artifact"]
end

subgraph group_group_external["External Integrations"]
  node_node_ors{{"OpenRouteService<br/>external routing"}}
  node_node_frontend["Web Client<br/>react frontend"]
end

node_node_readme["README<br/>project docs<br/>[README.md]"]

node_node_readme -->|"describes"| node_node_backend_main
node_node_readme -->|"mentions"| node_node_frontend
node_node_backend_main -->|"serves"| node_node_metadata_ep
node_node_backend_main -->|"serves"| node_node_single_pred_ep
node_node_backend_main -->|"serves"| node_node_route_pred_ep
node_node_backend_main -->|"calls"| node_node_predict
node_node_backend_main -->|"uses"| node_node_city_data
node_node_predict -->|"trains on"| node_node_dataset
node_node_predict -->|"enriches with"| node_node_city_data
node_node_route_pred_ep -.->|"optionally calls"| node_node_ors
node_node_offline_main -->|"analyzes"| node_node_dataset
node_node_offline_main -->|"produces"| node_node_eda_doc
node_node_offline_main -->|"produces"| node_node_methods_doc
node_node_offline_main -->|"produces"| node_node_compare_doc
node_node_offline_main -->|"produces"| node_node_results_doc
node_node_offline_main -->|"produces"| node_node_conclusion_doc
node_node_frontend -->|"consumes"| node_node_backend_main
node_node_results_doc -.->|"summarizes"| node_node_predict

click node_node_readme "https://github.com/vedhakoushik/accident-prediction-analysis/blob/main/README.md"
click node_node_dataset "https://github.com/vedhakoushik/accident-prediction-analysis/blob/main/df.csv"
click node_node_predict "https://github.com/vedhakoushik/accident-prediction-analysis/blob/main/predict.py"
click node_node_city_data "https://github.com/vedhakoushik/accident-prediction-analysis/blob/main/backend/city_data.py"
click node_node_backend_main "https://github.com/vedhakoushik/accident-prediction-analysis/blob/main/backend/main.py"
click node_node_metadata_ep "https://github.com/vedhakoushik/accident-prediction-analysis/blob/main/backend/main.py"
click node_node_single_pred_ep "https://github.com/vedhakoushik/accident-prediction-analysis/blob/main/backend/main.py"
click node_node_route_pred_ep "https://github.com/vedhakoushik/accident-prediction-analysis/blob/main/backend/main.py"
click node_node_offline_main "https://github.com/vedhakoushik/accident-prediction-analysis/blob/main/main.py"
click node_node_eda_doc "https://github.com/vedhakoushik/accident-prediction-analysis/blob/main/EDA_Visual_Output.docx"
click node_node_methods_doc "https://github.com/vedhakoushik/accident-prediction-analysis/blob/main/Methods_and_Model_Implementation_Code_IO.docx"
click node_node_compare_doc "https://github.com/vedhakoushik/accident-prediction-analysis/blob/main/Comparison_Proposed_vs_Existing_Work.docx"
click node_node_results_doc "https://github.com/vedhakoushik/accident-prediction-analysis/blob/main/Prediction_Results_Accuracy_Table_Graph.docx"
click node_node_conclusion_doc "https://github.com/vedhakoushik/accident-prediction-analysis/blob/main/Result_Discussion_Conclusion_Future_Enhancement_References.docx"

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_node_dataset,node_node_predict,node_node_city_data toneBlue
class node_node_backend_main,node_node_metadata_ep,node_node_single_pred_ep,node_node_route_pred_ep toneAmber
class node_node_offline_main,node_node_eda_doc,node_node_methods_doc,node_node_compare_doc,node_node_results_doc,node_node_conclusion_doc toneMint
class node_node_ors,node_node_frontend toneRose
class node_node_readme toneNeutral
```

## Components

### Data & Model

Dataset, inference, and domain metadata used for accident-risk prediction

- [Training Data](https://github.com/vedhakoushik/accident-prediction-analysis/blob/main/df.csv): dataset · Primary CSV dataset used for model development and prediction context · `df.csv`
- [Predict Engine](https://github.com/vedhakoushik/accident-prediction-analysis/blob/main/predict.py): ml pipeline · Model training and inference logic reused by the API · `predict.py`
- [City Data](https://github.com/vedhakoushik/accident-prediction-analysis/blob/main/backend/city_data.py): domain metadata · City or route-related lookup data supporting prediction inputs · `backend/city_data.py`

### Serving Layer

FastAPI application and runtime request handling

- [API App](https://github.com/vedhakoushik/accident-prediction-analysis/blob/main/backend/main.py): fastapi app · Application entrypoint exposing prediction and metadata endpoints · `backend/main.py`
- [Metadata API](https://github.com/vedhakoushik/accident-prediction-analysis/blob/main/backend/main.py): endpoint set · Retrieves model or domain metadata for clients · `backend/main.py`
- [Single Prediction](https://github.com/vedhakoushik/accident-prediction-analysis/blob/main/backend/main.py): endpoint · Predicts accident risk for a single input point · `backend/main.py`
- [Route Prediction](https://github.com/vedhakoushik/accident-prediction-analysis/blob/main/backend/main.py): endpoint · Predicts risk along a route, with optional routing enrichment · `backend/main.py`

### Offline Analysis

Exploration, visualization, and report artifacts

- [Analysis Script](https://github.com/vedhakoushik/accident-prediction-analysis/blob/main/main.py): eda/report script · Offline exploration and visualization driver · `main.py`
- [EDA Output](https://github.com/vedhakoushik/accident-prediction-analysis/blob/main/EDA_Visual_Output.docx): report artifact · Exploratory analysis deliverable · `EDA_Visual_Output.docx`
- [Methods Doc](https://github.com/vedhakoushik/accident-prediction-analysis/blob/main/Methods_and_Model_Implementation_Code_IO.docx): report artifact · Methodology and implementation write-up · `Methods_and_Model_Implementation_Code_IO.docx`
- [Comparison Doc](https://github.com/vedhakoushik/accident-prediction-analysis/blob/main/Comparison_Proposed_vs_Existing_Work.docx): report artifact · Proposed-versus-existing-work comparison write-up · `Comparison_Proposed_vs_Existing_Work.docx`
- [Results Doc](https://github.com/vedhakoushik/accident-prediction-analysis/blob/main/Prediction_Results_Accuracy_Table_Graph.docx): report artifact · Accuracy tables, graphs, and evaluation summary · `Prediction_Results_Accuracy_Table_Graph.docx`
- [Conclusion Doc](https://github.com/vedhakoushik/accident-prediction-analysis/blob/main/Result_Discussion_Conclusion_Future_Enhancement_References.docx): report artifact · Discussion, conclusion, and future enhancement notes · `Result_Discussion_Conclusion_Future_Enhancement_References.docx`

### External Integrations

Optional services and client-side consumers

- **OpenRouteService**: external routing · Optional external route data provider controlled by ORS_API_KEY
- **Web Client**: react frontend · Browser client described in the README, consuming the FastAPI API

### Other components

- [README](https://github.com/vedhakoushik/accident-prediction-analysis/blob/main/README.md): project docs · Top-level overview, setup, and architecture notes · `README.md`

## Connections

- README → API App: describes · README documents the API server as the main runtime
- README → Web Client: mentions · README references a separate React/Vite presentation layer
- API App → Metadata API: serves · API exposes metadata retrieval endpoints
- API App → Single Prediction: serves · API exposes single-point prediction endpoints
- API App → Route Prediction: serves · API exposes route prediction endpoints
- API App → Predict Engine: calls · Request handling delegates model work to the ML layer
- API App → City Data: uses · API consults city and route metadata during prediction flows
- Predict Engine → Training Data: trains on · Model pipeline is driven by the CSV dataset
- Predict Engine → City Data: enriches with · Inference may use location metadata for normalization or context
- Route Prediction → OpenRouteService: optionally calls · Route enrichment can use OpenRouteService when configured
- Analysis Script → Training Data: analyzes · Offline analysis reads the core dataset
- Analysis Script → EDA Output: produces · Exploratory workflow feeds documentation artifacts
- Analysis Script → Methods Doc: produces · Offline workflow supports implementation notes and methods write-up
- Analysis Script → Comparison Doc: produces · Offline workflow contributes comparison material
- Analysis Script → Results Doc: produces · Analysis generates evaluation results and figures
- Analysis Script → Conclusion Doc: produces · Analysis contributes discussion and conclusion content
- Web Client → API App: consumes · Browser client reads and invokes the HTTP API
- Results Doc → Predict Engine: summarizes · Results documentation reflects model performance
