# niranjanzoro/smart-energy-prediction architecture

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

- Interactive diagram: https://gitdiagram.com/niranjanzoro/smart-energy-prediction
- Repository: https://github.com/niranjanzoro/smart-energy-prediction

## Overview

Smart Energy Consumption Predictor is a Flask-backed household energy forecasting dashboard. Users view hourly history, request forecasts up to 72 hours ahead, inspect prediction intervals and model metrics, and submit series for anomaly detection or saving suggestions. Model preparation, Ridge/LSTM training, evaluation and multi-step back-testing form a separate supporting workflow. The README and excerpts establish the main paths; unsampled API routes and UI wiring are represented only where documentation or shown calls support them.

Main entry points: [`backend/app.py`](https://github.com/niranjanzoro/smart-energy-prediction/blob/main/backend/app.py) (Flask API), [`scripts/train_models.py`](https://github.com/niranjanzoro/smart-energy-prediction/blob/main/scripts/train_models.py) (Training workflow), [`frontend/static/js/app.js`](https://github.com/niranjanzoro/smart-energy-prediction/blob/main/frontend/static/js/app.js) (Web dashboard), [`models/forecaster.py`](https://github.com/niranjanzoro/smart-energy-prediction/blob/main/models/forecaster.py) (Recursive forecaster)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_dashboard["Dashboard"]
  node_ui["Web dashboard<br/>[app.js]"]
  node_page["Dashboard page<br/>[index.html]"]
end

subgraph group_serving["Forecasting API"]
  node_api["Flask API<br/>[app.py]"]
  node_history[("Hourly history")]
  node_artifacts[("Saved models and metadata")]
end

subgraph group_modeling["Data And Models"]
  node_loader["Data preparation<br/>[data_loader.py]"]
  node_ridge["Ridge model<br/>[linear_model.py]"]
  node_lstm["Stacked LSTM<br/>[lstm_model.py]"]
  node_forecaster["Recursive forecaster<br/>[forecaster.py]"]
  node_training["Training workflow<br/>[train_models.py]"]
  node_metrics["Model metrics<br/>[metrics.py]"]
end

subgraph group_insights["Energy Insights"]
  node_anomaly["Anomaly detection"]
  node_suggestions["Saving suggestions"]
end

node_resident(("Dashboard user"))

node_resident -->|"uses"| node_ui
node_ui -.->|"renders"| node_page
node_ui -->|"requests data"| node_api
node_api -->|"reads history"| node_history
node_api -->|"loads models"| node_artifacts
node_api -->|"loads model"| node_ridge
node_api -->|"loads model"| node_lstm
node_api -->|"requests forecast"| node_forecaster
node_api -->|"detects anomalies"| node_anomaly
node_api -->|"generates tips"| node_suggestions
node_training -->|"prepares data"| node_loader
node_training -->|"trains and saves"| node_ridge
node_training -->|"trains and saves"| node_lstm
node_training -->|"back-tests"| node_forecaster
node_training -->|"evaluates predictions"| node_metrics
node_training -->|"writes artifacts"| node_artifacts
node_forecaster -->|"builds features"| node_loader

click node_ui "https://github.com/niranjanzoro/smart-energy-prediction/blob/main/frontend/static/js/app.js"
click node_page "https://github.com/niranjanzoro/smart-energy-prediction/blob/main/frontend/templates/index.html"
click node_api "https://github.com/niranjanzoro/smart-energy-prediction/blob/main/backend/app.py"
click node_history "https://github.com/niranjanzoro/smart-energy-prediction/blob/main/data/processed_energy.csv"
click node_artifacts "https://github.com/niranjanzoro/smart-energy-prediction/tree/main/models/saved"
click node_loader "https://github.com/niranjanzoro/smart-energy-prediction/blob/main/models/data_loader.py"
click node_ridge "https://github.com/niranjanzoro/smart-energy-prediction/blob/main/models/linear_model.py"
click node_lstm "https://github.com/niranjanzoro/smart-energy-prediction/blob/main/models/lstm_model.py"
click node_forecaster "https://github.com/niranjanzoro/smart-energy-prediction/blob/main/models/forecaster.py"
click node_training "https://github.com/niranjanzoro/smart-energy-prediction/blob/main/scripts/train_models.py"
click node_metrics "https://github.com/niranjanzoro/smart-energy-prediction/blob/main/models/metrics.py"
click node_anomaly "https://github.com/niranjanzoro/smart-energy-prediction/blob/main/models/anomaly_detector.py"
click node_suggestions "https://github.com/niranjanzoro/smart-energy-prediction/blob/main/models/anomaly_detector.py"

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_ui,node_page,node_resident toneBlue
class node_api,node_history,node_artifacts toneAmber
class node_loader,node_ridge,node_lstm,node_forecaster,node_training,node_metrics toneMint
class node_anomaly,node_suggestions toneRose
```

## Components

### Dashboard

- [Web dashboard](https://github.com/niranjanzoro/smart-energy-prediction/blob/main/frontend/static/js/app.js): `frontend/static/js/app.js`
- [Dashboard page](https://github.com/niranjanzoro/smart-energy-prediction/blob/main/frontend/templates/index.html): `frontend/templates/index.html`

### Forecasting API

- [Flask API](https://github.com/niranjanzoro/smart-energy-prediction/blob/main/backend/app.py): `backend/app.py`
- [Hourly history](https://github.com/niranjanzoro/smart-energy-prediction/blob/main/data/processed_energy.csv): `data/processed_energy.csv`
- [Saved models and metadata](https://github.com/niranjanzoro/smart-energy-prediction/tree/main/models/saved): `models/saved`

### Data And Models

- [Data preparation](https://github.com/niranjanzoro/smart-energy-prediction/blob/main/models/data_loader.py): `models/data_loader.py`
- [Ridge model](https://github.com/niranjanzoro/smart-energy-prediction/blob/main/models/linear_model.py): `models/linear_model.py`
- [Stacked LSTM](https://github.com/niranjanzoro/smart-energy-prediction/blob/main/models/lstm_model.py): `models/lstm_model.py`
- [Recursive forecaster](https://github.com/niranjanzoro/smart-energy-prediction/blob/main/models/forecaster.py): `models/forecaster.py`
- [Training workflow](https://github.com/niranjanzoro/smart-energy-prediction/blob/main/scripts/train_models.py): `scripts/train_models.py`
- [Model metrics](https://github.com/niranjanzoro/smart-energy-prediction/blob/main/models/metrics.py): `models/metrics.py`

### Energy Insights

- [Anomaly detection](https://github.com/niranjanzoro/smart-energy-prediction/blob/main/models/anomaly_detector.py): `models/anomaly_detector.py`
- [Saving suggestions](https://github.com/niranjanzoro/smart-energy-prediction/blob/main/models/anomaly_detector.py): `models/anomaly_detector.py`

### Other components

- **Dashboard user**

## Connections

- Dashboard user → Web dashboard: uses (evidence: `README.md`)
- Web dashboard → Dashboard page: renders
- Web dashboard → Flask API: requests data (evidence: `frontend/static/js/app.js`)
- Flask API → Hourly history: reads history (evidence: `README.md`)
- Flask API → Saved models and metadata: loads models (evidence: `README.md`)
- Flask API → Ridge model: loads model (evidence: `backend/app.py`)
- Flask API → Stacked LSTM: loads model (evidence: `backend/app.py`)
- Flask API → Recursive forecaster: requests forecast (evidence: `backend/app.py`)
- Flask API → Anomaly detection: detects anomalies (evidence: `backend/app.py`)
- Flask API → Saving suggestions: generates tips (evidence: `README.md`)
- Training workflow → Data preparation: prepares data (evidence: `scripts/train_models.py`)
- Training workflow → Ridge model: trains and saves (evidence: `scripts/train_models.py`)
- Training workflow → Stacked LSTM: trains and saves (evidence: `scripts/train_models.py`)
- Training workflow → Recursive forecaster: back-tests (evidence: `scripts/train_models.py`)
- Training workflow → Model metrics: evaluates predictions (evidence: `scripts/train_models.py`)
- Training workflow → Saved models and metadata: writes artifacts (evidence: `README.md`)
- Recursive forecaster → Data preparation: builds features (evidence: `models/forecaster.py`)
