# pourmousavi/bess-scada-data architecture

> Architecture diagram of the GitHub repository pourmousavi/bess-scada-data, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pourmousavi/bess-scada-data
- Repository: https://github.com/pourmousavi/bess-scada-data

## Overview

1. **Overall shape**
   - This is a single FastAPI application that serves both an API and a static browser UI.
   - The core architectural boundary is: **browser UI → REST API → AEMO NEMWEB fetchers/processors**.

2. **Frontend layer**
   - `app/static/index.html`, `css/style.css`, and `js/app.js` implement a vanilla HTML/CSS/JS client.
   - The UI renders interactive Plotly.js time-series charts, pulls data from the API, and handles user-driven filtering/download actions.
   - There is no separate frontend build system; the static assets are served directly by FastAPI.

3. **API entrypoint and routing**
   - `app/main.py` initializes the FastAPI app and serves the static files.
   - `app/routers/api.py` contains the REST surface described in the README: BESS list, SCADA data, dispatch/energy data, downloads, quality flags, app info, and analytics.
   - The router is the main orchestration point that connects request parameters to the relevant service modules.

4. **AEMO data access layer**
   - `app/services/aemo_fetcher.py` and `app/services/dispatch_fetcher.py` are the external-data ingestion layer.
   - They retrieve archive/current ZIP bundles from AEMO NEMWEB using HTTP, including remote archive access for the older bundled SCADA files.
   - This layer is responsible for dealing with AEMO’s file formats and archive layout, not business logic.

5. **Data transformation layer**
   - `app/services/data_processor.py` and `app/services/dispatch_processor.py` use Polars to filter, normalize, and shape the raw CSV payloads into API-ready data.
   - This is where the domain-specific rules live: date filtering, interval handling, output shaping, and CSV/Parquet preparation.
   - The processors are the bridge between AEMO’s raw archive structure and the client-facing query model.

6. **Two primary data products**
   - **SCADA / `PUBLIC_NEXT_DAY_FPPMW`**: 4-second measurements with `MEASURED_MW` and `MW_QUALITY_FLAG`.
   - **Dispatch / `DISPATCH_UNIT_SOLUTION`**: 5-minute interval dispatch and energy storage fields such as `INITIALMW` and `ENERGY_STORAGE`.
   - The API exposes these as separate paths and download formats, so the architecture has two parallel data pipelines rather than one generic one.

7. **Reference data and fallback assets**
   - `app/services/gen_info_fetcher.py` fetches the live BESS list from AEMO generation information, with a 24-hour cache behavior noted in the README.
   - `app/data/bess_list.json` is the local fallback if the live list is unavailable.
   - `app/data/quality_flags.json` provides the static description map for SCADA quality flags.

8. **Analytics and operational telemetry**
   - `app/services/analytics.py` adds a small internal persistence boundary for request logging, apparently backed by SQLite.
   - The `/api/analytics` endpoint is token-protected via `ANALYTICS_TOKEN`, separating operational stats from the public data API.
   - This is the only clear server-side persistence path; the main datasets themselves are not stored on the server.

9. **Runtime and deployment**
   - The project targets Python 3.11, runs with Uvicorn, and is containerized via `Dockerfile`.
   - Deployment is intended for Hugging Face Spaces, and the repo includes GitHub Actions to refresh the BESS list and sync the app to HF.
   - That means the architecture is optimized for stateless request handling in containers, with external data fetched on demand.

10. **Maintenance and automation**
   - `scripts/refresh_bess_list.py` is a maintenance utility for regenerating the fallback BESS list.
   - GitHub Actions in `.github/workflows/refresh_bess_list.yml` and `sync_to_hf.yml` automate data refresh and deployment sync.
   - These jobs support the live-data architecture by keeping bundled metadata current without introducing a server-side database for the main datasets.

Main entry points: [`app/routers/api.py`](https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/app/routers/api.py) (REST API), [`app/services/gen_info_fetcher.py`](https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/app/services/gen_info_fetcher.py) (Gen info fetcher), [`app/static/index.html`](https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/app/static/index.html) (UI shell), [`app/main.py`](https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/app/main.py) (FastAPI app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_frontend["Browser UI"]
  node_node_ui_html["UI shell<br/>static html<br/>[index.html]"]
  node_node_ui_css["Styles<br/>static css<br/>[style.css]"]
  node_node_ui_js["Client app<br/>static js<br/>[app.js]"]
end

subgraph group_group_api["API Layer"]
  node_node_main["FastAPI app<br/>entrypoint<br/>[main.py]"]
  node_node_router["REST API<br/>router<br/>[api.py]"]
  node_node_config["Config<br/>settings<br/>[config.py]"]
end

subgraph group_group_data["Data Services"]
  node_node_fetch_aemo[("AEMO fetcher<br/>archive fetcher<br/>[aemo_fetcher.py]")]
  node_node_fetch_dispatch[("Dispatch fetcher")]
  node_node_fetch_gen[("Gen info fetcher<br/>reference fetcher")]
  node_node_proc_scada{{"SCADA processor<br/>[data_processor.py]"}}
  node_node_proc_dispatch{{"Dispatch processor"}}
  node_node_analytics[("Analytics<br/>telemetry store<br/>[analytics.py]")]
  node_node_bess_data["BESS fallback<br/>reference data<br/>[bess_list.json]"]
  node_node_quality_data["Quality flags<br/>reference data<br/>[quality_flags.json]"]
  node_node_bess_meta["BESS meta<br/>metadata"]
end

subgraph group_group_ops["Operations"]
  node_node_docker["Container<br/>deployment"]
  node_node_refresh["Refresh script<br/>maintenance script"]
  node_node_workflows["GitHub Actions<br/>ci workflows<br/>[sync_to_hf.yml]"]
end

node_node_ui_html -->|"loads"| node_node_ui_js
node_node_ui_html -->|"styles"| node_node_ui_css
node_node_ui_js -->|"API calls"| node_node_router
node_node_main -->|"serves"| node_node_ui_html
node_node_main -->|"mounts"| node_node_router
node_node_router -->|"reads config"| node_node_config
node_node_router -->|"BESS list"| node_node_fetch_gen
node_node_router -->|"SCADA source"| node_node_fetch_aemo
node_node_router -->|"dispatch source"| node_node_fetch_dispatch
node_node_router -->|"scada API"| node_node_proc_scada
node_node_router -->|"dispatch API"| node_node_proc_dispatch
node_node_router -->|"flag map"| node_node_quality_data
node_node_router -->|"analytics"| node_node_analytics
node_node_fetch_gen -->|"fallback"| node_node_bess_data
node_node_fetch_gen -->|"metadata"| node_node_bess_meta
node_node_proc_scada -->|"raw input"| node_node_fetch_aemo
node_node_proc_dispatch -->|"raw input"| node_node_fetch_dispatch
node_node_refresh -->|"regenerates"| node_node_bess_data
node_node_workflows -->|"runs"| node_node_refresh
node_node_workflows -->|"deploys"| node_node_docker
node_node_docker -->|"runs"| node_node_main

click node_node_main "https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/app/main.py"
click node_node_router "https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/app/routers/api.py"
click node_node_config "https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/app/config.py"
click node_node_ui_html "https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/app/static/index.html"
click node_node_ui_css "https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/app/static/css/style.css"
click node_node_ui_js "https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/app/static/js/app.js"
click node_node_fetch_aemo "https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/app/services/aemo_fetcher.py"
click node_node_fetch_dispatch "https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/app/services/dispatch_fetcher.py"
click node_node_fetch_gen "https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/app/services/gen_info_fetcher.py"
click node_node_proc_scada "https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/app/services/data_processor.py"
click node_node_proc_dispatch "https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/app/services/dispatch_processor.py"
click node_node_analytics "https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/app/services/analytics.py"
click node_node_bess_data "https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/app/data/bess_list.json"
click node_node_quality_data "https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/app/data/quality_flags.json"
click node_node_bess_meta "https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/app/data/bess_list_meta.json"
click node_node_docker "https://github.com/pourmousavi/bess-scada-data/tree/claude/nem-battery-scada-data-E9GpX/Dockerfile"
click node_node_refresh "https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/scripts/refresh_bess_list.py"
click node_node_workflows "https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/.github/workflows/sync_to_hf.yml"

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_node_ui_html,node_node_ui_css,node_node_ui_js toneBlue
class node_node_main,node_node_router,node_node_config toneAmber
class node_node_fetch_aemo,node_node_fetch_dispatch,node_node_fetch_gen,node_node_proc_scada,node_node_proc_dispatch,node_node_analytics,node_node_bess_data,node_node_quality_data,node_node_bess_meta toneMint
class node_node_docker,node_node_refresh,node_node_workflows toneRose
```

## Components

### Browser UI

Static client served directly by FastAPI.

- [UI shell](https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/app/static/index.html): static html · Browser entry page for the client. · `app/static/index.html`
- [Styles](https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/app/static/css/style.css): static css · Presentation styling for the browser UI. · `app/static/css/style.css`
- [Client app](https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/app/static/js/app.js): static js · Vanilla JS client that calls the API and renders charts. · `app/static/js/app.js`

### API Layer

FastAPI entrypoint and REST routing.

- [FastAPI app](https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/app/main.py): entrypoint · Creates the application and serves static assets. · `app/main.py`
- [REST API](https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/app/routers/api.py): router · Main request orchestration for app endpoints. · `app/routers/api.py`
- [Config](https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/app/config.py): settings · Runtime settings and environment-driven configuration. · `app/config.py`

### Data Services

External fetchers, processors, reference data, and analytics.

- [AEMO fetcher](https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/app/services/aemo_fetcher.py): archive fetcher · Downloads NEMWEB archive and current ZIP bundles. · `app/services/aemo_fetcher.py`
- [Dispatch fetcher](https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/app/services/dispatch_fetcher.py): dispatch fetcher · Retrieves dispatch unit solution data from AEMO. · `app/services/dispatch_fetcher.py`
- [Gen info fetcher](https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/app/services/gen_info_fetcher.py): reference fetcher · Loads the live BESS generation information list with caching. · `app/services/gen_info_fetcher.py`
- [SCADA processor](https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/app/services/data_processor.py): scada processor · Filters and shapes PUBLIC_NEXT_DAY_FPPMW data for API responses. · `app/services/data_processor.py`
- [Dispatch processor](https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/app/services/dispatch_processor.py): dispatch processor · Normalizes DISPATCH_UNIT_SOLUTION intervals and exports. · `app/services/dispatch_processor.py`
- [Analytics](https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/app/services/analytics.py): telemetry store · Persists request logging and serves protected analytics. · `app/services/analytics.py`
- [BESS fallback](https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/app/data/bess_list.json): reference data · Local fallback list for generation metadata. · `app/data/bess_list.json`
- [Quality flags](https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/app/data/quality_flags.json): reference data · Static descriptions for SCADA quality flags. · `app/data/quality_flags.json`
- [BESS meta](https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/app/data/bess_list_meta.json): metadata · Metadata for the bundled BESS list refresh. · `app/data/bess_list_meta.json`

### Operations

Containerization, workflows, and maintenance scripts.

- [Container](https://github.com/pourmousavi/bess-scada-data/tree/claude/nem-battery-scada-data-E9GpX/Dockerfile): deployment · Container image and runtime definition. · `Dockerfile`
- [Refresh script](https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/scripts/refresh_bess_list.py): maintenance script · Regenerates the bundled BESS list. · `scripts/refresh_bess_list.py`
- [GitHub Actions](https://github.com/pourmousavi/bess-scada-data/blob/claude/nem-battery-scada-data-E9GpX/.github/workflows/sync_to_hf.yml): ci workflows · Automation for data refresh and Hugging Face sync. · `.github/workflows/sync_to_hf.yml`

## Connections

- UI shell → Client app: loads · The HTML shell loads the client logic.
- UI shell → Styles: styles · The HTML shell is styled by the CSS asset.
- Client app → REST API: API calls · Browser actions fetch data and trigger downloads through the REST API.
- FastAPI app → UI shell: serves · FastAPI serves the static browser UI.
- FastAPI app → REST API: mounts · Application wires the API router into the FastAPI app.
- REST API → Config: reads config · Endpoint behavior depends on environment settings and tokens.
- REST API → Gen info fetcher: BESS list · Retrieves the current generation information reference list.
- REST API → AEMO fetcher: SCADA source · Fetches NEMWEB archives for SCADA data.
- REST API → Dispatch fetcher: dispatch source · Fetches dispatch solution data from AEMO.
- REST API → SCADA processor: scada API · Transforms raw SCADA payloads into query results and downloads.
- REST API → Dispatch processor: dispatch API · Transforms dispatch payloads into query results and downloads.
- REST API → Quality flags: flag map · Exposes the static quality-flag descriptions.
- REST API → Analytics: analytics · Writes and reads protected operational telemetry.
- Gen info fetcher → BESS fallback: fallback · Uses the bundled BESS list when live fetch is unavailable.
- Gen info fetcher → BESS meta: metadata · Tracks refresh metadata for the bundled reference list.
- SCADA processor → AEMO fetcher: raw input · Processes the SCADA archive payloads fetched from AEMO.
- Dispatch processor → Dispatch fetcher: raw input · Processes dispatch ZIP payloads fetched from AEMO.
- Refresh script → BESS fallback: regenerates · Maintenance script rebuilds the fallback BESS list.
- GitHub Actions → Refresh script: runs · Automation invokes the refresh script.
- GitHub Actions → Container: deploys · Automation supports containerized sync and release flow.
- Container → FastAPI app: runs · Container starts the FastAPI application under Uvicorn.
