# santhoshkumarrs/road-traffic-accident-severity-classification architecture

> Architecture diagram of the GitHub repository santhoshkumarrs/road-traffic-accident-severity-classification, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/santhoshkumarrs/road-traffic-accident-severity-classification
- Repository: https://github.com/santhoshkumarrs/road-traffic-accident-severity-classification

## Overview

#### Purpose and Entry Points
This repository delivers multiclass road-traffic accident severity prediction (Slight, Serious, Fatal injury) for Addis Ababa accident records. The runtime entry point is the Streamlit application at `app.py`; it delegates input transformation and inference to `prediction.py` and loads the persisted Random Forest artifact at `Model/rf_model.joblib`.

#### Interactive Prediction Layer
`app.py` is the user-facing boundary. It collects scene, driver, vehicle, road, time, and casualty details through Streamlit controls, invokes prediction logic, and displays the predicted severity. It is intended to run with `streamlit run app.py`; `setup.sh` provides deployment-oriented Streamlit server setup.

Paths: `app.py`, `setup.sh`

#### Feature Encoding and Inference Contract
`prediction.py` contains the application-side ordinal encoding and model prediction functions. Its principal architectural responsibility is preserving the feature representation expected by the serialized classifier. The app must supply the selected top-10 training features in the same semantic ordering and encoded form used when the model was trained.

Paths: `prediction.py`, `Model/rf_model.joblib`

#### Model Artifact Boundary
`Model/rf_model.joblib` is a pre-trained scikit-learn Random Forest classifier, rather than a model trained at application startup. This separates expensive training and evaluation from low-latency serving. Any retraining or preprocessing change must produce a compatible replacement artifact and update inference encoding together.

Paths: `Model/rf_model.joblib`, `prediction.py`

#### Offline Data and Training Workflow
The raw corpus is stored locally in `Dataset/RTA_Dataset.csv` (12,316 records, 32 source features). The notebook is the authoritative offline workflow: EDA, removal of selected bias-prone fields, modal missing-value imputation, categorical label encoding, SMOTE balancing, mutual-information top-10 feature selection, grid search, evaluation, and SHAP analysis.

Paths: `Dataset/RTA_Dataset.csv`, `Notebook/Road Traffic Severity Classification-checkpoint.ipynb`

#### Primary Data Flow
Raw accident records flow from `Dataset/RTA_Dataset.csv` into notebook-based preprocessing and model selection. The chosen Random Forest is serialized to `Model/rf_model.joblib`. At serving time, browser input flows through `app.py`, is encoded/predicted in `prediction.py`, then returns a severity label to Streamlit. The training dataset and notebook are not required on the online prediction path.

#### Runtime and Infrastructure
The serving runtime is Python 3.11 with Streamlit, scikit-learn, and joblib; dependencies are declared in `requirements.txt`. The README identifies Render as the deployed hosting platform. The app has no database or API integration evident in the repository; model and dataset are filesystem-backed artifacts.

Paths: `requirements.txt`, `app.py`, `Model/rf_model.joblib`

Main entry points: [`app.py`](https://github.com/santhoshkumarrs/road-traffic-accident-severity-classification/blob/main/app.py) (Streamlit app), [`prediction.py`](https://github.com/santhoshkumarrs/road-traffic-accident-severity-classification/blob/main/prediction.py) (Encoding & inference), [`Notebook/Road Traffic Severity Classification-checkpoint.ipynb`](https://github.com/santhoshkumarrs/road-traffic-accident-severity-classification/blob/main/Notebook/Road%20Traffic%20Severity%20Classification-checkpoint.ipynb) (Training workflow), [`Model/rf_model.joblib`](https://github.com/santhoshkumarrs/road-traffic-accident-severity-classification/blob/main/Model/rf_model.joblib) (Random Forest artifact)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_serving["Online Serving"]
  node_streamlit_user(("Streamlit user<br/>browser client"))
  node_app["Streamlit app<br/>UI runtime<br/>[app.py]"]
  node_inference["Encoding &amp; inference<br/>prediction contract<br/>[prediction.py]"]
  node_model[("Random Forest artifact<br/>serialized sklearn model<br/>[rf_model.joblib]")]
  node_setup["Deployment setup<br/>Streamlit server setup<br/>[setup.sh]"]
end

subgraph group_training["Offline Training"]
  node_dataset[("Accident dataset<br/>raw CSV corpus<br/>[RTA_Dataset.csv]")]
  node_notebook["Training workflow<br/>analysis notebook"]
end

node_dependencies["Python dependencies<br/>runtime manifest<br/>[requirements.txt]"]

node_streamlit_user -->|"accident inputs"| node_app
node_app -->|"top-10 feature values"| node_inference
node_inference -->|"predict encoded vector"| node_model
node_inference -->|"severity class"| node_app
node_app -->|"display prediction"| node_streamlit_user
node_setup -.->|"configures server"| node_app
node_dependencies -.->|"runtime packages"| node_app
node_dataset -->|"raw records"| node_notebook
node_notebook -->|"serialize selected model"| node_model
node_notebook -.->|"defines compatible encoding"| node_inference

click node_app "https://github.com/santhoshkumarrs/road-traffic-accident-severity-classification/blob/main/app.py"
click node_inference "https://github.com/santhoshkumarrs/road-traffic-accident-severity-classification/blob/main/prediction.py"
click node_model "https://github.com/santhoshkumarrs/road-traffic-accident-severity-classification/blob/main/Model/rf_model.joblib"
click node_setup "https://github.com/santhoshkumarrs/road-traffic-accident-severity-classification/blob/main/setup.sh"
click node_dependencies "https://github.com/santhoshkumarrs/road-traffic-accident-severity-classification/blob/main/requirements.txt"
click node_dataset "https://github.com/santhoshkumarrs/road-traffic-accident-severity-classification/blob/main/Dataset/RTA_Dataset.csv"
click node_notebook "https://github.com/santhoshkumarrs/road-traffic-accident-severity-classification/blob/main/Notebook/Road%20Traffic%20Severity%20Classification-checkpoint.ipynb"

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_streamlit_user,node_app,node_inference,node_model,node_setup toneBlue
class node_dataset,node_notebook toneAmber
class node_dependencies toneNeutral
```

## Components

### Online Serving

- **Streamlit user**: browser client · Supplies accident-scene inputs and receives a severity label.
- [Streamlit app](https://github.com/santhoshkumarrs/road-traffic-accident-severity-classification/blob/main/app.py): UI runtime · Collects scene, driver, vehicle, road, time, and casualty inputs. · `app.py`
- [Encoding & inference](https://github.com/santhoshkumarrs/road-traffic-accident-severity-classification/blob/main/prediction.py): prediction contract · Ordinal-encodes the selected top-10 features and invokes the classifier. · `prediction.py`
- [Random Forest artifact](https://github.com/santhoshkumarrs/road-traffic-accident-severity-classification/blob/main/Model/rf_model.joblib): serialized sklearn model · Pre-trained multiclass severity classifier. · `Model/rf_model.joblib`
- [Deployment setup](https://github.com/santhoshkumarrs/road-traffic-accident-severity-classification/blob/main/setup.sh): Streamlit server setup · `setup.sh`

### Offline Training

- [Accident dataset](https://github.com/santhoshkumarrs/road-traffic-accident-severity-classification/blob/main/Dataset/RTA_Dataset.csv): raw CSV corpus · 12,316 Addis Ababa accident records with 32 source features. · `Dataset/RTA_Dataset.csv`
- [Training workflow](https://github.com/santhoshkumarrs/road-traffic-accident-severity-classification/blob/main/Notebook/Road%20Traffic%20Severity%20Classification-checkpoint.ipynb): analysis notebook · Performs preprocessing, balancing, feature selection, tuning, evaluation, and SHAP analysis. · `Notebook/Road Traffic Severity Classification-checkpoint.ipynb`

### Other components

- [Python dependencies](https://github.com/santhoshkumarrs/road-traffic-accident-severity-classification/blob/main/requirements.txt): runtime manifest · Declares Python 3.11 serving dependencies including Streamlit, scikit-learn, and joblib. · `requirements.txt`

## Connections

- Streamlit user → Streamlit app: accident inputs
- Streamlit app → Encoding & inference: top-10 feature values
- Encoding & inference → Random Forest artifact: predict encoded vector
- Encoding & inference → Streamlit app: severity class
- Streamlit app → Streamlit user: display prediction
- Deployment setup → Streamlit app: configures server
- Python dependencies → Streamlit app: runtime packages
- Accident dataset → Training workflow: raw records
- Training workflow → Random Forest artifact: serialize selected model
- Training workflow → Encoding & inference: defines compatible encoding
