# nkhanna94/road-accident-analysis-and-traffic-severity-prediction architecture

> Architecture diagram of the GitHub repository nkhanna94/road-accident-analysis-and-traffic-severity-prediction, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nkhanna94/road-accident-analysis-and-traffic-severity-prediction
- Repository: https://github.com/nkhanna94/road-accident-analysis-and-traffic-severity-prediction

## Overview

##### Project Type and Purpose
- This is a full-stack machine-learning application:
– Data ingestion, cleaning, EDA, and model training happen offline via Jupyter notebooks and scripts.
– A trained XGBoost model is served in a Flask web application for real-time severity predictions.

##### Main Architectural Components
a. Data Layer
- Raw data files (Data/*.csv)
- EDA & outlier‐removal notebooks (Data/*.ipynb)
b. Processing & Modeling Layer
- Model‐training notebooks (Models/*.ipynb) for DecisionTree, RandomForest, SVM, XGBoost, etc.
- Model artifacts (e.g., serialized XGBoost model – stored under WebApp/finaln.csv or a pickle file).
c. Deployment Layer (WebApp)
- Flask service (WebApp/app.py and root app.py)
- Templates (WebApp/templates/index.html, result.html)
- Static assets (WebApp/static/*.css)
d. Presentation Layer
- User’s web browser interacting with the Flask UI

##### Relationships & Data Flows
- Data Ingestion → Data Cleaning & EDA
(CSV files flow into notebooks/scripts under Data/)
- Cleaned data → Model Training
(Processed data fed into Models/*.ipynb)
- Model Training → Model Registry
(Best model (XGBoost) persisted into WebApp/finaln.csv or pickle)
- Model Registry → Flask API
(Flask app loads the model at startup)
- User Input → Flask API → Prediction Engine → Result
(Browser submits HTTP form to Flask; Flask passes features to the model; returns severity prediction; displayed in result.html)

##### Architectural Patterns & Design Principles
- Separation of concerns:
– Data processing and model training are decoupled from deployment code.
– Frontend templates & static assets isolated from Python logic.
- Reproducibility:
– Notebooks/documentation under Data/ and Models/ track experiments.
- Model selection pipeline:
– Multiple algorithms evaluated; best-performing XGBoost chosen for deployment.

##### Technologies & Frameworks to Annotate
- Python, Pandas, NumPy – data handling
- Matplotlib/Seaborn – visualizations (Graphs/)
- Scikit-learn, XGBoost – ML algorithms
- Flask – web service
- HTML/CSS – frontend

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Layer
    subgraph "Data Layer"
        direction TB
        RawCSVs[(Raw CSV Files)]:::data
        CSV1["3yearsuntouched.csv"]:::data
        CSV2["IQR_data.csv"]:::data
        CSV3["WithoutOutliers.csv"]:::data
        CSV4["Cleandata.csv"]:::data
        EDA_Notebooks[(EDA & Outlier-Removal Notebooks)]:::data
        NB1["EDA.ipynb"]:::data
        NB2["IQR_data.ipynb"]:::data
        NB3["Modified_Zscore.ipynb"]:::data
        NB4["Standard Dev.ipynb"]:::data
        NB5["Zscore_data.ipynb"]:::data

        RawCSVs -->|contains| CSV1
        RawCSVs -->|contains| CSV2
        RawCSVs -->|contains| CSV3
        RawCSVs -->|contains| CSV4
        RawCSVs -->|ingested into| EDA_Notebooks
        EDA_Notebooks -->|notebooks| NB1
        EDA_Notebooks -->|notebooks| NB2
        EDA_Notebooks -->|notebooks| NB3
        EDA_Notebooks -->|notebooks| NB4
        EDA_Notebooks -->|notebooks| NB5
    end

    %% Processing & Modeling Layer
    subgraph "Processing & Modeling Layer"
        direction TB
        Training_Notebooks[(Model Training Notebooks)]:::ml
        MNB1["Decision Tree - Random Forest.ipynb"]:::ml
        MNB2["LogisticReg.ipynb"]:::ml
        MNB3["MLP.ipynb"]:::ml
        MNB4["ada-boosting.ipynb"]:::ml
        MNB5["gradient-boosting.ipynb"]:::ml
        MNB6["mlp-severity.ipynb"]:::ml
        MNB7["nbc.ipynb"]:::ml
        MNB8["svm.ipynb"]:::ml
        MNB9["xg-boost.ipynb"]:::ml
        IntermediateData[(Intermediate Data)]:::data
        LabelEnc["LabelEncoded.csv"]:::data

        EDA_Notebooks -->|cleans data for| Training_Notebooks
        Training_Notebooks -->|notebooks| MNB1
        Training_Notebooks -->|notebooks| MNB2
        Training_Notebooks -->|notebooks| MNB3
        Training_Notebooks -->|notebooks| MNB4
        Training_Notebooks -->|notebooks| MNB5
        Training_Notebooks -->|notebooks| MNB6
        Training_Notebooks -->|notebooks| MNB7
        Training_Notebooks -->|notebooks| MNB8
        Training_Notebooks -->|notebooks| MNB9
        Training_Notebooks -->|produces| LabelEnc
    end

    %% Model Registry / Artifact
    ModelArtifact[(Model Artifact)]:::web
    click ModelArtifact "https://github.com/nkhanna94/road-accident-analysis-and-traffic-severity-prediction/blob/main/WebApp/finaln.csv"

    LabelEnc -->|feeds into training and registry| ModelArtifact

    %% Deployment Layer
    subgraph "Deployment Layer"
        direction TB
        FlaskService[(Flask Service)]:::web
        click FlaskService "https://github.com/nkhanna94/road-accident-analysis-and-traffic-severity-prediction/blob/main/WebApp/app.py"
        RootApp[(Root Entry)]:::web
        click RootApp "https://github.com/nkhanna94/road-accident-analysis-and-traffic-severity-prediction/blob/main/app.py"
        Templates[(Templates)]:::web
        index["index.html"]:::web
        click index "https://github.com/nkhanna94/road-accident-analysis-and-traffic-severity-prediction/blob/main/WebApp/templates/index.html"
        result["result.html"]:::web
        click result "https://github.com/nkhanna94/road-accident-analysis-and-traffic-severity-prediction/blob/main/WebApp/templates/result.html"
        Static[(Static Assets)]:::web
        style1["style.css"]:::web
        style2["styles.css"]:::web
        click style1 "https://github.com/nkhanna94/road-accident-analysis-and-traffic-severity-prediction/blob/main/WebApp/static/style.css"
        click style2 "https://github.com/nkhanna94/road-accident-analysis-and-traffic-severity-prediction/blob/main/WebApp/static/styles.css"
        
        ModelArtifact -->|loaded at startup| FlaskService
        RootApp -->|imports| FlaskService
        FlaskService -->|renders| Templates
        Templates --> index
        Templates --> result
        FlaskService -->|serves| Static
        Static --> style1
        Static --> style2
    end

    %% Presentation Layer
    Browser[(User Browser)]:::user

    Browser -->|HTTP POST→prediction| FlaskService
    FlaskService -->|"returns prediction"| result

    %% Styles
    classDef data fill:#a2d2ff,stroke:#0366d6,color:#000;
    classDef ml fill:#c4f1be,stroke:#2f855a,color:#000;
    classDef web fill:#fdd835,stroke:#e65100,color:#000;
    classDef user fill:#eeeeee,stroke:#999999,color:#000;
```
