# thang170725/01wa-lightgbm architecture

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

- Interactive diagram: https://gitdiagram.com/thang170725/01wa-lightgbm
- Repository: https://github.com/thang170725/01wa-lightgbm

## Overview

This repository provides hourly electricity forecasting: users upload a time/value CSV, the backend forecasts future load (24 hours by default), and the frontend presents forecast, comparison, and evaluation results. A separate documented workflow explores and prepares historical electricity data, trains models, and persists them for prediction. The graph preserves both the documented `app/utils` workflow and the substantial `preprocessing_services` implementation. Some connections are based on README descriptions; unsampled source is not assumed to establish additional calls.

Main entry points: [`frontend/app/page.tsx`](https://github.com/thang170725/01wa-lightgbm/blob/main/frontend/app/page.tsx) (Forecast page), [`backend/preprocessing_services/preprocessor.py`](https://github.com/thang170725/01wa-lightgbm/blob/main/backend/preprocessing_services/preprocessor.py) (Hourly preprocessing), [`backend/application.py`](https://github.com/thang170725/01wa-lightgbm/blob/main/backend/application.py) (Forecast API), [`backend/app/models/lightgbm.py`](https://github.com/thang170725/01wa-lightgbm/blob/main/backend/app/models/lightgbm.py) (LightGBM and Ridge)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data_prep["Data preparation"]
  node_eda["Load exploration<br/>[visualizations.py]"]
  node_hourly["Hourly conversion"]
  node_quality["Data quality checks<br/>[data_checker.py]"]
  node_prep_app["Training preprocessing<br/>[preprocessor.py]"]
  node_split["Dataset splitting"]
  node_sample_data["Sample user data<br/>[gen_data_user.py]"]
  node_csv_viz["CSV visualizations"]
end

subgraph group_modeling["Forecast modeling"]
  node_trainer["LightGBM and Ridge<br/>[lightgbm.py]"]
  node_model_store[("Model persistence<br/>[model_manager.py]")]
  node_feature_builder["Forecast features<br/>[feature_builder.py]"]
end

subgraph group_serving["Prediction service"]
  node_api["Forecast API<br/>[application.py]"]
end

subgraph group_frontend["Web interface"]
  node_upload_ui["Upload interface<br/>[Upload.tsx]"]
  node_api_client["API client<br/>[UploadApi.ts]"]
  node_page["Forecast page<br/>[page.tsx]"]
  node_charts["Forecast charts<br/>[Chart.tsx]"]
  node_comparison["Comparison chart"]
  node_daily_chart["Daily chart<br/>[DailyChart.tsx]"]
  node_daily_table["Daily table<br/>[DailyTable.tsx]"]
  node_metrics["Forecast metrics<br/>[Metrics.tsx]"]
  node_table["Forecast table<br/>[Table.tsx]"]
  node_daily_helpers["Daily data helpers<br/>[daily.ts]"]
end

subgraph group_preprocessing_alt["Preprocessing services"]
  node_preproc_service["Hourly preprocessing<br/>[preprocessor.py]"]
  node_service_features["Leakage-safe features"]
  node_service_hourly["Hourly dataset builder"]
  node_service_checker["Preprocessing checks<br/>[data_checker.py]"]
  node_service_viz["Preprocessing visualization<br/>[visualization.py]"]
  node_component_features["Feature component"]
  node_outliers["Outlier detection"]
  node_split_io["Split I/O<br/>[split_io.py]"]
end

node_uci[("UCI dataset")]
node_user(("CSV uploader"))

node_uci -->|"explores"| node_eda
node_uci -->|"resamples"| node_hourly
node_hourly -->|"checks"| node_quality
node_quality -->|"prepares"| node_prep_app
node_prep_app -->|"splits"| node_split
node_split -->|"trains from"| node_trainer
node_trainer -->|"saves and loads"| node_model_store
node_trainer -->|"uses features"| node_feature_builder
node_user -->|"uploads CSV"| node_upload_ui
node_upload_ui -.->|"submits file"| node_api_client
node_api_client -->|"requests forecast"| node_api
node_api -->|"forecasts with"| node_trainer
node_api -->|"loads bundles"| node_model_store
node_api -->|"returns results"| node_page
node_page -.->|"renders"| node_charts
node_page -.->|"renders"| node_comparison
node_page -.->|"renders"| node_daily_chart
node_page -.->|"renders"| node_daily_table
node_page -.->|"renders"| node_metrics
node_page -.->|"renders"| node_table
node_page -.->|"uses"| node_daily_helpers
node_service_hourly -.->|"feeds"| node_preproc_service
node_preproc_service -->|"builds features"| node_service_features
node_preproc_service -.->|"delegates to"| node_component_features
node_preproc_service -.->|"uses"| node_outliers
node_preproc_service -.->|"uses"| node_split_io

click node_eda "https://github.com/thang170725/01wa-lightgbm/blob/main/backend/app/utils/visualizations.py"
click node_hourly "https://github.com/thang170725/01wa-lightgbm/blob/main/backend/app/utils/build_hourly_dataset.py"
click node_quality "https://github.com/thang170725/01wa-lightgbm/blob/main/backend/app/utils/data_checker.py"
click node_prep_app "https://github.com/thang170725/01wa-lightgbm/blob/main/backend/app/utils/preprocessor.py"
click node_split "https://github.com/thang170725/01wa-lightgbm/blob/main/backend/app/utils/split_electricity_dataset.py"
click node_sample_data "https://github.com/thang170725/01wa-lightgbm/blob/main/backend/app/utils/gen_data_user.py"
click node_csv_viz "https://github.com/thang170725/01wa-lightgbm/blob/main/backend/app/utils/visualizations_csv.py"
click node_preproc_service "https://github.com/thang170725/01wa-lightgbm/blob/main/backend/preprocessing_services/preprocessor.py"
click node_service_features "https://github.com/thang170725/01wa-lightgbm/blob/main/backend/preprocessing_services/feature_engineering.py"
click node_service_hourly "https://github.com/thang170725/01wa-lightgbm/blob/main/backend/preprocessing_services/build_hourly_dataset.py"
click node_service_checker "https://github.com/thang170725/01wa-lightgbm/blob/main/backend/preprocessing_services/data_checker.py"
click node_service_viz "https://github.com/thang170725/01wa-lightgbm/blob/main/backend/preprocessing_services/visualization.py"
click node_component_features "https://github.com/thang170725/01wa-lightgbm/blob/main/backend/preprocessing_services/components/feature_engineering.py"
click node_outliers "https://github.com/thang170725/01wa-lightgbm/blob/main/backend/preprocessing_services/components/outlier_detection.py"
click node_split_io "https://github.com/thang170725/01wa-lightgbm/blob/main/backend/preprocessing_services/components/split_io.py"
click node_trainer "https://github.com/thang170725/01wa-lightgbm/blob/main/backend/app/models/lightgbm.py"
click node_model_store "https://github.com/thang170725/01wa-lightgbm/blob/main/backend/app/models/model_manager.py"
click node_feature_builder "https://github.com/thang170725/01wa-lightgbm/blob/main/backend/app/models/feature_builder.py"
click node_api "https://github.com/thang170725/01wa-lightgbm/blob/main/backend/application.py"
click node_upload_ui "https://github.com/thang170725/01wa-lightgbm/blob/main/frontend/src/components/Upload.tsx"
click node_api_client "https://github.com/thang170725/01wa-lightgbm/blob/main/frontend/routes/UploadApi.ts"
click node_page "https://github.com/thang170725/01wa-lightgbm/blob/main/frontend/app/page.tsx"
click node_charts "https://github.com/thang170725/01wa-lightgbm/blob/main/frontend/src/components/Chart.tsx"
click node_comparison "https://github.com/thang170725/01wa-lightgbm/blob/main/frontend/src/components/ComparisonChart.tsx"
click node_daily_chart "https://github.com/thang170725/01wa-lightgbm/blob/main/frontend/src/components/DailyChart.tsx"
click node_daily_table "https://github.com/thang170725/01wa-lightgbm/blob/main/frontend/src/components/DailyTable.tsx"
click node_metrics "https://github.com/thang170725/01wa-lightgbm/blob/main/frontend/src/components/Metrics.tsx"
click node_table "https://github.com/thang170725/01wa-lightgbm/blob/main/frontend/src/components/Table.tsx"
click node_daily_helpers "https://github.com/thang170725/01wa-lightgbm/blob/main/frontend/src/lib/daily.ts"

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_eda,node_hourly,node_quality,node_prep_app,node_split,node_sample_data,node_csv_viz toneBlue
class node_trainer,node_model_store,node_feature_builder,node_uci toneAmber
class node_api toneMint
class node_upload_ui,node_api_client,node_page,node_charts,node_comparison,node_daily_chart,node_daily_table,node_metrics,node_table,node_daily_helpers toneRose
class node_preproc_service,node_service_features,node_service_hourly,node_service_checker,node_service_viz,node_component_features,node_outliers,node_split_io,node_user toneIndigo
```

## Components

### Data preparation

- [Load exploration](https://github.com/thang170725/01wa-lightgbm/blob/main/backend/app/utils/visualizations.py): `backend/app/utils/visualizations.py`
- [Hourly conversion](https://github.com/thang170725/01wa-lightgbm/blob/main/backend/app/utils/build_hourly_dataset.py): `backend/app/utils/build_hourly_dataset.py`
- [Data quality checks](https://github.com/thang170725/01wa-lightgbm/blob/main/backend/app/utils/data_checker.py): `backend/app/utils/data_checker.py`
- [Training preprocessing](https://github.com/thang170725/01wa-lightgbm/blob/main/backend/app/utils/preprocessor.py): `backend/app/utils/preprocessor.py`
- [Dataset splitting](https://github.com/thang170725/01wa-lightgbm/blob/main/backend/app/utils/split_electricity_dataset.py): `backend/app/utils/split_electricity_dataset.py`
- [Sample user data](https://github.com/thang170725/01wa-lightgbm/blob/main/backend/app/utils/gen_data_user.py): `backend/app/utils/gen_data_user.py`
- [CSV visualizations](https://github.com/thang170725/01wa-lightgbm/blob/main/backend/app/utils/visualizations_csv.py): `backend/app/utils/visualizations_csv.py`

### Forecast modeling

- [LightGBM and Ridge](https://github.com/thang170725/01wa-lightgbm/blob/main/backend/app/models/lightgbm.py): `backend/app/models/lightgbm.py`
- [Model persistence](https://github.com/thang170725/01wa-lightgbm/blob/main/backend/app/models/model_manager.py): `backend/app/models/model_manager.py`
- [Forecast features](https://github.com/thang170725/01wa-lightgbm/blob/main/backend/app/models/feature_builder.py): `backend/app/models/feature_builder.py`

### Prediction service

- [Forecast API](https://github.com/thang170725/01wa-lightgbm/blob/main/backend/application.py): `backend/application.py`

### Web interface

- [Upload interface](https://github.com/thang170725/01wa-lightgbm/blob/main/frontend/src/components/Upload.tsx): `frontend/src/components/Upload.tsx`
- [API client](https://github.com/thang170725/01wa-lightgbm/blob/main/frontend/routes/UploadApi.ts): `frontend/routes/UploadApi.ts`
- [Forecast page](https://github.com/thang170725/01wa-lightgbm/blob/main/frontend/app/page.tsx): `frontend/app/page.tsx`
- [Forecast charts](https://github.com/thang170725/01wa-lightgbm/blob/main/frontend/src/components/Chart.tsx): `frontend/src/components/Chart.tsx`
- [Comparison chart](https://github.com/thang170725/01wa-lightgbm/blob/main/frontend/src/components/ComparisonChart.tsx): `frontend/src/components/ComparisonChart.tsx`
- [Daily chart](https://github.com/thang170725/01wa-lightgbm/blob/main/frontend/src/components/DailyChart.tsx): `frontend/src/components/DailyChart.tsx`
- [Daily table](https://github.com/thang170725/01wa-lightgbm/blob/main/frontend/src/components/DailyTable.tsx): `frontend/src/components/DailyTable.tsx`
- [Forecast metrics](https://github.com/thang170725/01wa-lightgbm/blob/main/frontend/src/components/Metrics.tsx): `frontend/src/components/Metrics.tsx`
- [Forecast table](https://github.com/thang170725/01wa-lightgbm/blob/main/frontend/src/components/Table.tsx): `frontend/src/components/Table.tsx`
- [Daily data helpers](https://github.com/thang170725/01wa-lightgbm/blob/main/frontend/src/lib/daily.ts): `frontend/src/lib/daily.ts`

### Preprocessing services

- [Hourly preprocessing](https://github.com/thang170725/01wa-lightgbm/blob/main/backend/preprocessing_services/preprocessor.py): `backend/preprocessing_services/preprocessor.py`
- [Leakage-safe features](https://github.com/thang170725/01wa-lightgbm/blob/main/backend/preprocessing_services/feature_engineering.py): `backend/preprocessing_services/feature_engineering.py`
- [Hourly dataset builder](https://github.com/thang170725/01wa-lightgbm/blob/main/backend/preprocessing_services/build_hourly_dataset.py): `backend/preprocessing_services/build_hourly_dataset.py`
- [Preprocessing checks](https://github.com/thang170725/01wa-lightgbm/blob/main/backend/preprocessing_services/data_checker.py): `backend/preprocessing_services/data_checker.py`
- [Preprocessing visualization](https://github.com/thang170725/01wa-lightgbm/blob/main/backend/preprocessing_services/visualization.py): `backend/preprocessing_services/visualization.py`
- [Feature component](https://github.com/thang170725/01wa-lightgbm/blob/main/backend/preprocessing_services/components/feature_engineering.py): `backend/preprocessing_services/components/feature_engineering.py`
- [Outlier detection](https://github.com/thang170725/01wa-lightgbm/blob/main/backend/preprocessing_services/components/outlier_detection.py): `backend/preprocessing_services/components/outlier_detection.py`
- [Split I/O](https://github.com/thang170725/01wa-lightgbm/blob/main/backend/preprocessing_services/components/split_io.py): `backend/preprocessing_services/components/split_io.py`

### Other components

- **UCI dataset**
- **CSV uploader**

## Connections

- UCI dataset → Load exploration: explores
- UCI dataset → Hourly conversion: resamples
- Hourly conversion → Data quality checks: checks
- Data quality checks → Training preprocessing: prepares
- Training preprocessing → Dataset splitting: splits
- Dataset splitting → LightGBM and Ridge: trains from
- LightGBM and Ridge → Model persistence: saves and loads (evidence: `backend/app/models/lightgbm.py`)
- LightGBM and Ridge → Forecast features: uses features (evidence: `backend/app/models/lightgbm.py`)
- CSV uploader → Upload interface: uploads CSV
- Upload interface → API client: submits file
- API client → Forecast API: requests forecast
- Forecast API → LightGBM and Ridge: forecasts with (evidence: `backend/application.py`)
- Forecast API → Model persistence: loads bundles (evidence: `backend/application.py`)
- Forecast API → Forecast page: returns results
- Forecast page → Forecast charts: renders
- Forecast page → Comparison chart: renders
- Forecast page → Daily chart: renders
- Forecast page → Daily table: renders
- Forecast page → Forecast metrics: renders
- Forecast page → Forecast table: renders
- Forecast page → Daily data helpers: uses
- Hourly dataset builder → Hourly preprocessing: feeds
- Hourly preprocessing → Leakage-safe features: builds features (evidence: `backend/preprocessing_services/preprocessor.py`)
- Hourly preprocessing → Feature component: delegates to
- Hourly preprocessing → Outlier detection: uses
- Hourly preprocessing → Split I/O: uses
