# demontrick/energy-forecaster-api architecture

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

- Interactive diagram: https://gitdiagram.com/demontrick/energy-forecaster-api
- Repository: https://github.com/demontrick/energy-forecaster-api

## Overview

This repository is a building-aware energy forecasting API plus a model preparation and training workflow. The principal runtime flow validates a building-and-weather request, encodes the building through the loaded artifact mapping, predicts load, and returns a typed response. Training prepares features and a building mapping before saving the model bundle. Evidence is limited by a path mismatch: preparation writes `Data/energy_training_data.csv`, while `train.py` reads `data/energy_training_data.csv`; the tree contains only the former. `app/model.py` is a separate inference wrapper not imported by the sampled API entry point.

Main entry points: [`app/main.py`](https://github.com/demontrick/energy-forecaster-api/blob/main/app/main.py) (API Endpoints), [`prepare_data.py`](https://github.com/demontrick/energy-forecaster-api/blob/main/prepare_data.py) (Data Preparation), [`app/models/energy_model.pkl`](https://github.com/demontrick/energy-forecaster-api/blob/main/app/models/energy_model.pkl) (Model Bundle), [`app/model.py`](https://github.com/demontrick/energy-forecaster-api/blob/main/app/model.py) (Inference Wrapper)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Forecast API"]
  node_main["API Endpoints<br/>[main.py]"]
  node_schemas["Request Schemas<br/>[schemas.py]"]
  node_model_wrapper["Inference Wrapper<br/>[model.py]"]
end

subgraph group_training["Model Training"]
  node_prepare["Data Preparation<br/>[prepare_data.py]"]
  node_training_data["Prepared Dataset"]
  node_trainer["Model Trainer<br/>[train.py]"]
end

subgraph group_artifacts["Model Artifacts"]
  node_artifact[("Model Bundle<br/>[energy_model.pkl]")]
end

node_client(("API Client"))
node_consumption["Consumption Input"]
node_weather["Weather Input"]

node_client -->|"sends request"| node_main
node_main -->|"validates with"| node_schemas
node_main -->|"loads bundle"| node_artifact
node_main -->|"returns forecast"| node_client
node_model_wrapper -->|"loads bundle"| node_artifact
node_model_wrapper -->|"accepts payload"| node_schemas
node_prepare -->|"reads"| node_consumption
node_prepare -->|"reads"| node_weather
node_prepare -->|"writes dataset"| node_training_data
node_trainer -->|"writes bundle"| node_artifact

click node_main "https://github.com/demontrick/energy-forecaster-api/blob/main/app/main.py"
click node_schemas "https://github.com/demontrick/energy-forecaster-api/blob/main/app/schemas.py"
click node_model_wrapper "https://github.com/demontrick/energy-forecaster-api/blob/main/app/model.py"
click node_prepare "https://github.com/demontrick/energy-forecaster-api/blob/main/prepare_data.py"
click node_training_data "https://github.com/demontrick/energy-forecaster-api/blob/main/Data/energy_training_data.csv"
click node_trainer "https://github.com/demontrick/energy-forecaster-api/blob/main/train.py"
click node_artifact "https://github.com/demontrick/energy-forecaster-api/blob/main/app/models/energy_model.pkl"

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_main,node_schemas,node_model_wrapper,node_client toneBlue
class node_prepare,node_training_data,node_trainer toneAmber
class node_artifact toneMint
class node_consumption,node_weather toneIndigo
```

## Components

### Forecast API

- [API Endpoints](https://github.com/demontrick/energy-forecaster-api/blob/main/app/main.py): `app/main.py`
- [Request Schemas](https://github.com/demontrick/energy-forecaster-api/blob/main/app/schemas.py): `app/schemas.py`
- [Inference Wrapper](https://github.com/demontrick/energy-forecaster-api/blob/main/app/model.py): `app/model.py`

### Model Training

- [Data Preparation](https://github.com/demontrick/energy-forecaster-api/blob/main/prepare_data.py): `prepare_data.py`
- [Prepared Dataset](https://github.com/demontrick/energy-forecaster-api/blob/main/Data/energy_training_data.csv): `Data/energy_training_data.csv`
- [Model Trainer](https://github.com/demontrick/energy-forecaster-api/blob/main/train.py): `train.py`

### Model Artifacts

- [Model Bundle](https://github.com/demontrick/energy-forecaster-api/blob/main/app/models/energy_model.pkl): `app/models/energy_model.pkl`

### Other components

- **API Client**
- **Consumption Input**
- **Weather Input**

## Connections

- API Client → API Endpoints: sends request
- API Endpoints → Request Schemas: validates with
- API Endpoints → Model Bundle: loads bundle
- API Endpoints → API Client: returns forecast
- Inference Wrapper → Model Bundle: loads bundle
- Inference Wrapper → Request Schemas: accepts payload
- Data Preparation → Consumption Input: reads
- Data Preparation → Weather Input: reads
- Data Preparation → Prepared Dataset: writes dataset
- Model Trainer → Model Bundle: writes bundle
