# aronagent/vehicles_severity_ml_model architecture

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

- Interactive diagram: https://gitdiagram.com/aronagent/vehicles_severity_ml_model
- Repository: https://github.com/aronagent/vehicles_severity_ml_model

## Overview

##### Project Type and Purpose
- This is a full-stack web application built with Django that integrates a Machine Learning (ML) model to predict vehicle accident severity.
- It accepts user inputs, processes them through an ML model (loaded via joblib), and returns a prediction. It also exposes a REST API endpoint for programmatic access.

##### File Structure
- The primary Django project directory (VehicleSeverity) contains all Django configuration files (settings.py, urls.py, asgi.py, wsgi.py) and the core app files (views.py, __init__.py).
- There is a joblib file (accident_ready.joblib) which represents the saved ML model.
- A SQLite database (db.sqlite3) is used by Django as the data storage.
- The project includes templates (index.html, modelresponse.html) for the front-end and static assets (style.css) for styling.
- The Django management script (manage.py) is present to run the server and handle migrations.

##### README for Additional Insights
- The README outlines the core functionalities: user input, ML-based prediction, and REST API support.
- It lists the factors input into the model and the expected prediction output (Minor, Major, or Fatal).
- Instructions to set up the virtual environment, install dependencies, and run the application are provided.
- The provided API section indicates the existence of an endpoint (/predict/) that accepts JSON payload via POST.

a. Main Components:
- Web Server / Django Application: This includes the core Django components (views, URL configs, settings).
- ML Prediction Engine: Represented by the accident_ready.joblib file, used within Django views to make predictions.
- Database: SQLite (db.sqlite3) for persisting data.
- Frontend Components: Templates (index.html, modelresponse.html) and static assets (CSS) for the UI.
- RESTful API Layer: An endpoint (likely mapped in urls.py) that accepts prediction requests.

b. Relationships and Interactions:
- The Client (web browser or API consumer) sends HTTP requests to the Django server.
- Django’s URL routing maps requests to specific view functions.
- View functions process inputs, invoke the ML prediction model, and route the results back to the client (either by rendering an HTML template or returning a JSON response).
- The static files and templates serve as presentation layers.
- The database may be used to store logs, user sessions, or any persistent data as required.

c. Architectural Patterns / Design Principles:
- Separation of Concerns: Clearly defined roles for presentation (templates and static files), business logic (views handling user input and predictions), and data storage (SQLite).
- Integration of ML components into web routes: The use of joblib for model persistence and integration into a web request-response cycle.

d. Relevant Technologies and Frameworks:
- Django Framework (for the web application and API endpoints).
- joblib (for loading the pre-trained ML model).
- SQLite (as the database).
- HTML/CSS for UI components.
- REST API concepts using Django routes.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Client / Browser"]:::client

    subgraph "Django Application"
        B["Django URL Router"]:::router
        C["View Logic / Controller"]:::controller
        D["ML Prediction Engine"]:::ml
        E["REST API Endpoint (/predict/)"]:::api
    end

    F["SQLite Database"]:::database

    subgraph "Frontend Components"
        G["Templates"]:::frontend
        H["Static Assets"]:::frontend
    end

    I["Django Management Script"]:::management

    A -->|"HTTP-request"| B
    B -->|"routes"| C
    C -->|"invokes"| D
    C -->|"calls_API"| E
    E -->|"JSON_response"| A
    C -->|"renders_HTML"| G
    G -->|"delivers_UI"| A
    C -->|"logs_to"| F
    I -->|"starts_server"| B

    click B "https://github.com/aronagent/vehicles_severity_ml_model/tree/main/VehicleSeverity/VehicleSeverity/"
    click D "https://github.com/aronagent/vehicles_severity_ml_model/blob/main/VehicleSeverity/accident_ready.joblib"
    click F "https://github.com/aronagent/vehicles_severity_ml_model/blob/main/VehicleSeverity/db.sqlite3"
    click G "https://github.com/aronagent/vehicles_severity_ml_model/tree/main/VehicleSeverity/templates"
    click H "https://github.com/aronagent/vehicles_severity_ml_model/tree/main/VehicleSeverity/static"
    click E "https://github.com/aronagent/vehicles_severity_ml_model/blob/main/VehicleSeverity/VehicleSeverity/urls.py"
    click E "https://github.com/aronagent/vehicles_severity_ml_model/blob/main/VehicleSeverity/VehicleSeverity/views.py"
    click I "https://github.com/aronagent/vehicles_severity_ml_model/blob/main/VehicleSeverity/manage.py"

    classDef client fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef router fill:#ccf,stroke:#333,stroke-width:2px;
    classDef controller fill:#cfc,stroke:#333,stroke-width:2px;
    classDef ml fill:#ff99cc,stroke:#333,stroke-width:2px;
    classDef api fill:#ff9966,stroke:#333,stroke-width:2px;
    classDef database fill:#ffff99,stroke:#333,stroke-width:2px;
    classDef frontend fill:#99ccff,stroke:#333,stroke-width:2px;
    classDef management fill:#dddddd,stroke:#333,stroke-width:2px;
```
