# prabhunde/bess architecture

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

- Interactive diagram: https://gitdiagram.com/prabhunde/bess
- Repository: https://github.com/prabhunde/bess

## Overview

This is an AC-coupled battery-storage plant simulator and EMS lab. The main runtime starts a shared plant state, MQTT integration, a timestep engine, optional CSV logging, and a Flask operator dashboard. Each engine tick samples PV and load, applies scenario inputs and EMS mode selection, advances battery/PCS behavior, then publishes telemetry and optionally archives it. Operators can view live state and submit overrides, faults, and scenarios; an external EMS can send mode commands over MQTT. Some links to unsampled modules are omitted or marked unverified.

Main entry points: [`simulator_engine.py`](https://github.com/prabhunde/bess/blob/main/simulator_engine.py) (Simulation engine), [`app.py`](https://github.com/prabhunde/bess/blob/main/app.py) (Runtime entry), [`dashboard/app.py`](https://github.com/prabhunde/bess/blob/main/dashboard/app.py) (Dashboard API), [`state_manager.py`](https://github.com/prabhunde/bess/blob/main/state_manager.py) (Shared plant state)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime coordination"]
  node_app["Runtime entry<br/>[app.py]"]
  node_config["Plant configuration<br/>[config.py]"]
  node_state["Shared plant state<br/>[state_manager.py]"]
end

subgraph group_physics["Plant simulation"]
  node_engine["Simulation engine"]
  node_solar["Solar model<br/>[solar_model.py]"]
  node_load["Load model<br/>[load_model.py]"]
  node_battery["Battery model<br/>[battery_model.py]"]
  node_embedded_ems["Embedded EMS policy"]
  node_ems_logic["EMS mode logic<br/>[ems_logic.py]"]
end

subgraph group_integration["EMS and telemetry"]
  node_mqtt["MQTT manager<br/>[mqtt_manager.py]"]
  node_csv[("CSV archive<br/>[csv_logger.py]")]
end

subgraph group_operator["Operator tools"]
  node_scenarios["Scenario presets<br/>[scenario_lab.py]"]
  node_dashboard["Dashboard API<br/>[app.py]"]
  node_dashboard_template["Dashboard page<br/>[index.html]"]
  node_dashboard_client["Dashboard client<br/>[simple_lab.js]"]
end

node_operator_actor(("Operator"))
node_ems_actor(("External EMS"))
node_mqtt_broker{{"MQTT broker"}}

node_operator_actor -->|"uses controls"| node_dashboard
node_app -->|"creates"| node_state
node_app -->|"starts"| node_mqtt
node_app -->|"starts"| node_engine
node_app -->|"configures"| node_csv
node_app -->|"runs"| node_dashboard
node_app -->|"reads settings"| node_config
node_dashboard -->|"reads and updates"| node_state
node_dashboard -->|"renders"| node_dashboard_template
node_dashboard -->|"reads settings"| node_config
node_dashboard_client -.->|"uses API"| node_dashboard
node_engine -->|"reads and updates"| node_state
node_engine -->|"samples"| node_solar
node_engine -->|"samples"| node_load
node_engine -->|"advances SOC"| node_battery
node_engine -->|"selects mode"| node_embedded_ems
node_engine -->|"reads settings"| node_config
node_engine -->|"publishes telemetry"| node_mqtt
node_engine -->|"appends rows"| node_csv
node_state -->|"resolves scenario"| node_scenarios
node_state -.->|"normalizes mode"| node_ems_logic
node_mqtt -->|"publishes and subscribes"| node_mqtt_broker
node_ems_actor -->|"sends commands"| node_mqtt_broker
node_mqtt_broker -->|"delivers commands"| node_mqtt
node_mqtt -->|"forwards commands"| node_state

click node_app "https://github.com/prabhunde/bess/blob/main/app.py"
click node_config "https://github.com/prabhunde/bess/blob/main/config.py"
click node_state "https://github.com/prabhunde/bess/blob/main/state_manager.py"
click node_engine "https://github.com/prabhunde/bess/blob/main/simulator_engine.py"
click node_solar "https://github.com/prabhunde/bess/blob/main/solar_model.py"
click node_load "https://github.com/prabhunde/bess/blob/main/load_model.py"
click node_battery "https://github.com/prabhunde/bess/blob/main/battery_model.py"
click node_embedded_ems "https://github.com/prabhunde/bess/blob/main/embedded_simple_ems.py"
click node_ems_logic "https://github.com/prabhunde/bess/blob/main/ems_logic.py"
click node_scenarios "https://github.com/prabhunde/bess/blob/main/scenario_lab.py"
click node_mqtt "https://github.com/prabhunde/bess/blob/main/mqtt_manager.py"
click node_csv "https://github.com/prabhunde/bess/blob/main/csv_logger.py"
click node_dashboard "https://github.com/prabhunde/bess/blob/main/dashboard/app.py"
click node_dashboard_template "https://github.com/prabhunde/bess/blob/main/dashboard/templates/index.html"
click node_dashboard_client "https://github.com/prabhunde/bess/blob/main/dashboard/static/simple_lab.js"

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_config,node_state toneBlue
class node_engine,node_solar,node_load,node_battery,node_embedded_ems,node_ems_logic toneAmber
class node_mqtt,node_csv toneMint
class node_scenarios,node_dashboard,node_dashboard_template,node_dashboard_client toneRose
class node_operator_actor,node_ems_actor,node_mqtt_broker toneIndigo
```

## Components

### Runtime coordination

- [Runtime entry](https://github.com/prabhunde/bess/blob/main/app.py): `app.py`
- [Plant configuration](https://github.com/prabhunde/bess/blob/main/config.py): `config.py`
- [Shared plant state](https://github.com/prabhunde/bess/blob/main/state_manager.py): `state_manager.py`

### Plant simulation

- [Simulation engine](https://github.com/prabhunde/bess/blob/main/simulator_engine.py): `simulator_engine.py`
- [Solar model](https://github.com/prabhunde/bess/blob/main/solar_model.py): `solar_model.py`
- [Load model](https://github.com/prabhunde/bess/blob/main/load_model.py): `load_model.py`
- [Battery model](https://github.com/prabhunde/bess/blob/main/battery_model.py): `battery_model.py`
- [Embedded EMS policy](https://github.com/prabhunde/bess/blob/main/embedded_simple_ems.py): `embedded_simple_ems.py`
- [EMS mode logic](https://github.com/prabhunde/bess/blob/main/ems_logic.py): `ems_logic.py`

### EMS and telemetry

- [MQTT manager](https://github.com/prabhunde/bess/blob/main/mqtt_manager.py): `mqtt_manager.py`
- [CSV archive](https://github.com/prabhunde/bess/blob/main/csv_logger.py): `csv_logger.py`

### Operator tools

- [Scenario presets](https://github.com/prabhunde/bess/blob/main/scenario_lab.py): `scenario_lab.py`
- [Dashboard API](https://github.com/prabhunde/bess/blob/main/dashboard/app.py): `dashboard/app.py`
- [Dashboard page](https://github.com/prabhunde/bess/blob/main/dashboard/templates/index.html): `dashboard/templates/index.html`
- [Dashboard client](https://github.com/prabhunde/bess/blob/main/dashboard/static/simple_lab.js): `dashboard/static/simple_lab.js`

### Other components

- **Operator**
- **External EMS**
- **MQTT broker**

## Connections

- Operator → Dashboard API: uses controls (evidence: `README.md`)
- Runtime entry → Shared plant state: creates (evidence: `app.py`)
- Runtime entry → MQTT manager: starts (evidence: `app.py`)
- Runtime entry → Simulation engine: starts (evidence: `app.py`)
- Runtime entry → CSV archive: configures (evidence: `app.py`)
- Runtime entry → Dashboard API: runs (evidence: `app.py`)
- Runtime entry → Plant configuration: reads settings (evidence: `app.py`)
- Dashboard API → Shared plant state: reads and updates (evidence: `dashboard/app.py`)
- Dashboard API → Dashboard page: renders (evidence: `dashboard/app.py`)
- Dashboard API → Plant configuration: reads settings (evidence: `dashboard/app.py`)
- Dashboard client → Dashboard API: uses API
- Simulation engine → Shared plant state: reads and updates (evidence: `simulator_engine.py`)
- Simulation engine → Solar model: samples (evidence: `simulator_engine.py`)
- Simulation engine → Load model: samples (evidence: `simulator_engine.py`)
- Simulation engine → Battery model: advances SOC (evidence: `simulator_engine.py`)
- Simulation engine → Embedded EMS policy: selects mode (evidence: `simulator_engine.py`)
- Simulation engine → Plant configuration: reads settings (evidence: `simulator_engine.py`)
- Simulation engine → MQTT manager: publishes telemetry (evidence: `app.py`)
- Simulation engine → CSV archive: appends rows (evidence: `simulator_engine.py`)
- Shared plant state → Scenario presets: resolves scenario (evidence: `state_manager.py`)
- Shared plant state → EMS mode logic: normalizes mode (evidence: `state_manager.py`)
- MQTT manager → MQTT broker: publishes and subscribes (evidence: `mqtt_manager.py`)
- External EMS → MQTT broker: sends commands (evidence: `README.md`)
- MQTT broker → MQTT manager: delivers commands (evidence: `README.md`)
- MQTT manager → Shared plant state: forwards commands (evidence: `app.py`)
