# tarunk0209/energy-consumption-prediction architecture

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

- Interactive diagram: https://gitdiagram.com/tarunk0209/energy-consumption-prediction
- Repository: https://github.com/tarunk0209/energy-consumption-prediction

## Overview

This is a manufacturing energy-prediction web application. Users manage products, machine types, shifts, and production batches, then request an estimate for a saved batch; the backend sends its production features to a regression-model service, stores the result, and exposes prediction history for the frontend. The graph also includes the documented model-training/data branch. Relationships involving unsampled service and training details rely on README documentation; source excerpts show the frontend routing and the backend’s ML-service request.

Main entry points: [`frontend/src/App.jsx`](https://github.com/tarunk0209/energy-consumption-prediction/blob/main/frontend/src/App.jsx) (Workspace app), [`frontend/src/api.js`](https://github.com/tarunk0209/energy-consumption-prediction/blob/main/frontend/src/api.js) (HTTP API client), [`backend/main.py`](https://github.com/tarunk0209/energy-consumption-prediction/blob/main/backend/main.py) (REST API and prediction orchestration), [`ml_service/train_model.py`](https://github.com/tarunk0209/energy-consumption-prediction/blob/main/ml_service/train_model.py) (Model training and evaluation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_app["Workspace app<br/>[App.jsx]"]
  node_products["Product management<br/>[Products.jsx]"]
  node_master["Machine and shift management<br/>[MasterData.jsx]"]
  node_batches["Batch management"]
  node_prediction_ui["Prediction interface"]
  node_history_ui["Prediction history view"]
  node_api_client["HTTP API client<br/>[api.js]"]
end

subgraph group_backend["Backend API and storage"]
  node_backend_api["REST API and prediction orchestration<br/>[main.py]"]
  node_schemas["Request and response schemas<br/>[schemas.py]"]
  node_orm["Production and prediction records<br/>[models.py]"]
  node_sqlite[("SQLite database<br/>[database.py]")]
end

subgraph group_ml["Prediction and modeling"]
  node_ml_api["ML prediction service<br/>[main.py]"]
  node_model["Saved regression pipeline"]
end

subgraph group_training["Training data"]
  node_train["Model training and evaluation<br/>[train_model.py]"]
  node_generator["Sample data generator<br/>[generate_data.py]"]
  node_dataset["Historical production data"]
end

node_operator(("User"))

node_operator -->|"uses"| node_app
node_app -->|"renders"| node_products
node_app -->|"renders"| node_master
node_app -->|"renders"| node_batches
node_app -->|"renders"| node_prediction_ui
node_app -->|"renders"| node_history_ui
node_app -->|"requests products"| node_api_client
node_products -->|"sends CRUD requests"| node_api_client
node_master -->|"sends CRUD requests"| node_api_client
node_batches -->|"sends batch requests"| node_api_client
node_prediction_ui -->|"requests predictions"| node_api_client
node_history_ui -->|"loads history"| node_api_client
node_api_client -->|"sends HTTP requests"| node_backend_api
node_backend_api -->|"uses schemas"| node_schemas
node_backend_api -->|"queries and updates"| node_orm
node_backend_api -->|"persists records"| node_sqlite
node_orm -->|"maps records"| node_sqlite
node_backend_api -->|"posts batch features"| node_ml_api
node_ml_api -->|"loads for inference"| node_model
node_train -->|"trains from"| node_dataset
node_generator -->|"generates"| node_dataset
node_train -->|"saves pipeline"| node_model

click node_app "https://github.com/tarunk0209/energy-consumption-prediction/blob/main/frontend/src/App.jsx"
click node_products "https://github.com/tarunk0209/energy-consumption-prediction/blob/main/frontend/src/Products.jsx"
click node_master "https://github.com/tarunk0209/energy-consumption-prediction/blob/main/frontend/src/MasterData.jsx"
click node_batches "https://github.com/tarunk0209/energy-consumption-prediction/blob/main/frontend/src/ProductionBatches.jsx"
click node_prediction_ui "https://github.com/tarunk0209/energy-consumption-prediction/blob/main/frontend/src/EnergyPrediction.jsx"
click node_history_ui "https://github.com/tarunk0209/energy-consumption-prediction/blob/main/frontend/src/PredictionHistory.jsx"
click node_api_client "https://github.com/tarunk0209/energy-consumption-prediction/blob/main/frontend/src/api.js"
click node_backend_api "https://github.com/tarunk0209/energy-consumption-prediction/blob/main/backend/main.py"
click node_schemas "https://github.com/tarunk0209/energy-consumption-prediction/blob/main/backend/schemas.py"
click node_orm "https://github.com/tarunk0209/energy-consumption-prediction/blob/main/backend/models.py"
click node_sqlite "https://github.com/tarunk0209/energy-consumption-prediction/blob/main/backend/database.py"
click node_ml_api "https://github.com/tarunk0209/energy-consumption-prediction/blob/main/ml_service/main.py"
click node_model "https://github.com/tarunk0209/energy-consumption-prediction/blob/main/models/energy_model.joblib"
click node_train "https://github.com/tarunk0209/energy-consumption-prediction/blob/main/ml_service/train_model.py"
click node_generator "https://github.com/tarunk0209/energy-consumption-prediction/blob/main/ml_service/generate_data.py"
click node_dataset "https://github.com/tarunk0209/energy-consumption-prediction/blob/main/data/historical_production.csv"

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_app,node_products,node_master,node_batches,node_prediction_ui,node_history_ui,node_api_client,node_operator toneBlue
class node_backend_api,node_schemas,node_orm,node_sqlite toneAmber
class node_ml_api,node_model toneMint
class node_train,node_generator,node_dataset toneRose
```

## Components

### Frontend

- [Workspace app](https://github.com/tarunk0209/energy-consumption-prediction/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Product management](https://github.com/tarunk0209/energy-consumption-prediction/blob/main/frontend/src/Products.jsx): `frontend/src/Products.jsx`
- [Machine and shift management](https://github.com/tarunk0209/energy-consumption-prediction/blob/main/frontend/src/MasterData.jsx): `frontend/src/MasterData.jsx`
- [Batch management](https://github.com/tarunk0209/energy-consumption-prediction/blob/main/frontend/src/ProductionBatches.jsx): `frontend/src/ProductionBatches.jsx`
- [Prediction interface](https://github.com/tarunk0209/energy-consumption-prediction/blob/main/frontend/src/EnergyPrediction.jsx): `frontend/src/EnergyPrediction.jsx`
- [Prediction history view](https://github.com/tarunk0209/energy-consumption-prediction/blob/main/frontend/src/PredictionHistory.jsx): `frontend/src/PredictionHistory.jsx`
- [HTTP API client](https://github.com/tarunk0209/energy-consumption-prediction/blob/main/frontend/src/api.js): `frontend/src/api.js`

### Backend API and storage

- [REST API and prediction orchestration](https://github.com/tarunk0209/energy-consumption-prediction/blob/main/backend/main.py): `backend/main.py`
- [Request and response schemas](https://github.com/tarunk0209/energy-consumption-prediction/blob/main/backend/schemas.py): `backend/schemas.py`
- [Production and prediction records](https://github.com/tarunk0209/energy-consumption-prediction/blob/main/backend/models.py): `backend/models.py`
- [SQLite database](https://github.com/tarunk0209/energy-consumption-prediction/blob/main/backend/database.py): `backend/database.py`

### Prediction and modeling

- [ML prediction service](https://github.com/tarunk0209/energy-consumption-prediction/blob/main/ml_service/main.py): `ml_service/main.py`
- [Saved regression pipeline](https://github.com/tarunk0209/energy-consumption-prediction/blob/main/models/energy_model.joblib): `models/energy_model.joblib`

### Training data

- [Model training and evaluation](https://github.com/tarunk0209/energy-consumption-prediction/blob/main/ml_service/train_model.py): `ml_service/train_model.py`
- [Sample data generator](https://github.com/tarunk0209/energy-consumption-prediction/blob/main/ml_service/generate_data.py): `ml_service/generate_data.py`
- [Historical production data](https://github.com/tarunk0209/energy-consumption-prediction/blob/main/data/historical_production.csv): `data/historical_production.csv`

### Other components

- **User**

## Connections

- User → Workspace app: uses (evidence: `README.md`)
- Workspace app → Product management: renders (evidence: `frontend/src/App.jsx`)
- Workspace app → Machine and shift management: renders (evidence: `frontend/src/App.jsx`)
- Workspace app → Batch management: renders (evidence: `frontend/src/App.jsx`)
- Workspace app → Prediction interface: renders (evidence: `frontend/src/App.jsx`)
- Workspace app → Prediction history view: renders (evidence: `frontend/src/App.jsx`)
- Workspace app → HTTP API client: requests products (evidence: `frontend/src/App.jsx`)
- Product management → HTTP API client: sends CRUD requests (evidence: `frontend/src/Products.jsx`)
- Machine and shift management → HTTP API client: sends CRUD requests (evidence: `frontend/src/MasterData.jsx`)
- Batch management → HTTP API client: sends batch requests (evidence: `frontend/src/ProductionBatches.jsx`)
- Prediction interface → HTTP API client: requests predictions (evidence: `frontend/src/EnergyPrediction.jsx`)
- Prediction history view → HTTP API client: loads history (evidence: `frontend/src/PredictionHistory.jsx`)
- HTTP API client → REST API and prediction orchestration: sends HTTP requests (evidence: `frontend/src/api.js`)
- REST API and prediction orchestration → Request and response schemas: uses schemas (evidence: `backend/main.py`)
- REST API and prediction orchestration → Production and prediction records: queries and updates (evidence: `backend/main.py`)
- REST API and prediction orchestration → SQLite database: persists records (evidence: `backend/main.py`)
- Production and prediction records → SQLite database: maps records (evidence: `backend/models.py`)
- REST API and prediction orchestration → ML prediction service: posts batch features (evidence: `backend/main.py`)
- ML prediction service → Saved regression pipeline: loads for inference (evidence: `README.md`)
- Model training and evaluation → Historical production data: trains from (evidence: `README.md`)
- Sample data generator → Historical production data: generates (evidence: `README.md`)
- Model training and evaluation → Saved regression pipeline: saves pipeline (evidence: `README.md`)
