# hariom710/evoptima architecture

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

- Interactive diagram: https://gitdiagram.com/hariom710/evoptima
- Repository: https://github.com/hariom710/evoptima

## Overview

##### Project type and purpose
- This is a Django-based web application that integrates a pre-trained machine learning model to predict electric vehicle (EV) charging demand.
- The project serves HTML pages (via Django templates), loads a serialized scikit-learn model (model.joblib) and scaler (scaler.joblib), accepts user input through a form, and stores/retrieves data in a local SQLite database.

##### File structure
- Top level:
- ev_charging_prediction.ipynb – Jupyter notebook for data exploration, feature engineering, model training
- ev_charging_data2.xlsx – source dataset
- requirements.txt – Python dependencies
- ev_charging_project/
- manage.py and ev_charging_project/settings.py, urls.py, wsgi.py, asgi.py – Django project configuration
- db.sqlite3 – development database
- ev_charging_project/model/
- model.joblib, scaler.joblib – serialized ML artifacts
- ev_charging_project/prediction/ (Django app)
- models.py – any data models
- forms.py – user input form definitions
- views.py – request handlers that load the ML model, apply scaler, return predictions
- templates/prediction/*.html – base.html and predict.html for UI
- static/css & static/js – styling and client-side scripts
- staticfiles/ – collected static assets for production

##### Key insights from README
- Core use case: predict kWh consumption based on session duration, temperature, timestamp features
- Tech: Python 3.10, Django 4.0, scikit-learn, SQLite (dev) / MySQL or PostgreSQL (prod)
- Future roadmap hints at API layers and React dashboard, but current code uses server-rendered templates.

##### Main components
a. Client (web browser)
– Sends HTTP GET/POST to Django server
– Renders predict.html and base.html, executes static JS/CSS
b. Django Web Server (Monolith)
– URL router → prediction.views
– Loads forms, validates inputs
– ML layer: loads scaler.joblib & model.joblib, transforms input, obtains prediction
– Renders template with result
– ORM layer queries/stores in database
c. Database
– SQLite (dev) or MySQL/PostgreSQL (prod) storing historical sessions, user inputs, logs
d. Static Asset Store
– CSS/JS served from staticfiles directory
e. (Optional training pipeline)
– Jupyter Notebook or separate Python script training model and exporting joblib files

##### Architectural patterns and principles
- MVC / MTV (Model-Template-View) pattern inherent in Django
- Single-process monolith: all layers coexist in one codebase
- Separation of concerns:
- prediction/ handles domain logic and ML
- model/ holds artifacts, could be extracted to a microservice later
- static & templates separate presentation

##### Elements
- Clear component names (e.g., “Django Prediction View”)
- ML model loading path (file system → memory)
- Database interactions (ORM → SQL)
- Static asset serving path (URL → staticfiles)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client (Browser)" 
        direction TB
        Browser["Web Browser"]:::frontend
    end

    %% Presentation Layer
    subgraph "Presentation Layer" 
        direction TB
        Templates["Django Templates"]:::frontend
        StaticAssets["Static Assets"]:::frontend
    end

    %% Application Logic
    subgraph "Django Web Server" 
        direction TB
        Config["Django Configuration"]:::app
        Router["URL Router"]:::app
        Views["Prediction View"]:::app
        Forms["Form Processor"]:::app
        ORM["Django ORM"]:::app
        Renderer["Template Renderer"]:::app
    end

    %% ML Artifact Store
    subgraph "ML Artifact Store" 
        direction TB
        ModelStore["Model & Scaler Files"]:::ml
    end

    %% Data Storage
    subgraph "Data Storage" 
        direction TB
        Database["SQLite / MySQL"]:::data
    end

    %% Training Pipeline
    subgraph "Training & Exploration" 
        direction TB
        Notebook["Jupyter Notebook"]:::util
        Dataset["Excel Dataset"]:::util
    end

    %% Data Flows
    Browser -->|"HTTP GET/POST"| Router
    Router -->|"calls view"| Views
    Views -->|"validate input"| Forms
    Forms -->|"joblib.load"| ModelStore
    ModelStore -->|"load model/scaler"| Views
    Views -->|"ORM query/write"| ORM
    ORM -->|"SQL SELECT/INSERT"| Database
    Views -->|"render with data"| Renderer
    Renderer -->|"HTTP Response HTML"| Browser
    Browser -->|"fetch CSS/JS"| StaticAssets

    Notebook -->|"reads data"| Dataset
    Notebook -->|"exports joblib"| ModelStore

    %% Click Events for component mappings
    click Config "https://github.com/hariom710/evoptima/blob/main/ev_charging_project/manage.py"
    click Config "https://github.com/hariom710/evoptima/blob/main/ev_charging_project/ev_charging_project/settings.py"
    click Router "https://github.com/hariom710/evoptima/blob/main/ev_charging_project/ev_charging_project/urls.py"
    click Config "https://github.com/hariom710/evoptima/blob/main/ev_charging_project/ev_charging_project/asgi.py"
    click Config "https://github.com/hariom710/evoptima/blob/main/ev_charging_project/ev_charging_project/wsgi.py"

    click ModelStore "https://github.com/hariom710/evoptima/blob/main/ev_charging_project/model/model.joblib"
    click ModelStore "https://github.com/hariom710/evoptima/blob/main/ev_charging_project/model/scaler.joblib"

    click ORM "https://github.com/hariom710/evoptima/blob/main/ev_charging_project/prediction/models.py"
    click Forms "https://github.com/hariom710/evoptima/blob/main/ev_charging_project/prediction/forms.py"
    click Views "https://github.com/hariom710/evoptima/blob/main/ev_charging_project/prediction/views.py"
    click Views "https://github.com/hariom710/evoptima/blob/main/ev_charging_project/prediction/admin.py"
    click Views "https://github.com/hariom710/evoptima/blob/main/ev_charging_project/prediction/apps.py"

    click Templates "https://github.com/hariom710/evoptima/blob/main/ev_charging_project/prediction/templates/prediction/base.html"
    click Templates "https://github.com/hariom710/evoptima/blob/main/ev_charging_project/prediction/templates/prediction/predict.html"

    click StaticAssets "https://github.com/hariom710/evoptima/blob/main/ev_charging_project/static/css/style.css"
    click StaticAssets "https://github.com/hariom710/evoptima/blob/main/ev_charging_project/static/js/script.js"
    click StaticAssets "https://github.com/hariom710/evoptima/tree/main/staticfiles/"

    click Database "https://github.com/hariom710/evoptima/blob/main/ev_charging_project/db.sqlite3"

    click Notebook "https://github.com/hariom710/evoptima/blob/main/ev_charging_prediction.ipynb"
    click Dataset "https://github.com/hariom710/evoptima/blob/main/ev_charging_data2.xlsx"

    click Accelerator "https://github.com/hariom710/evoptima/blob/main/requirements.txt"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366D6,color:#0366D6;
    classDef app fill:#DFF5E1,stroke:#028A0F,color:#028A0F;
    classDef ml fill:#FFE5B4,stroke:#FF8C00,color:#FF8C00;
    classDef data fill:#E0E0E0,stroke:#5A5A5A,color:#5A5A5A;
    classDef util fill:#F0D9FF,stroke:#A020F0,color:#A020F0;
```
