# tsoun/bess-hil-simulator architecture

> Architecture diagram of the GitHub repository tsoun/bess-hil-simulator, 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/tsoun/bess-hil-simulator
- Repository: https://github.com/tsoun/bess-hil-simulator

## Overview

BESS HIL Simulator is a digital twin for validating an external EMS against a battery and power-conversion system. In real-time mode, the simulator starts a Modbus TCP server, advances the physics model in a loop, and publishes delayed telemetry; the EMS supplies setpoints through Modbus. The model applies power limits, capability curves, dynamics, and battery-state integration. The application also supports CSV-driven simulation. README-described grid scenarios and some runtime wiring are not fully visible in the excerpts, so uncertain connections are omitted.

Main entry points: [`BessSim.Hil/Program.cs`](https://github.com/tsoun/bess-hil-simulator/blob/main/BessSim.Hil/Program.cs) (Runtime Orchestrator), [`BessSim.Core/BessPhysicsModel.cs`](https://github.com/tsoun/bess-hil-simulator/blob/main/BessSim.Core/BessPhysicsModel.cs) (BESS Physics), [`BessSim.Hil/ModbusServerWrapper.cs`](https://github.com/tsoun/bess-hil-simulator/blob/main/BessSim.Hil/ModbusServerWrapper.cs) (Modbus TCP Server), [`BessSim.Core/PqCapabilityCurve.cs`](https://github.com/tsoun/bess-hil-simulator/blob/main/BessSim.Core/PqCapabilityCurve.cs) (P-Q Capability)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Simulation Runtime"]
  node_program["Runtime Orchestrator<br/>[Program.cs]"]
  node_csv["CSV Simulation<br/>[Program.cs]"]
  node_config["Simulation Settings<br/>[sim-config.json]"]
end

subgraph group_plant["Plant Model"]
  node_model["BESS Physics"]
  node_curve["P-Q Capability"]
  node_curve_data["Capability Data<br/>[pq-curves.json]"]
  node_output["Plant Output Contract<br/>[Types.cs]"]
end

subgraph group_interface["EMS Interface"]
  node_modbus["Modbus TCP Server"]
end

node_ems(("External EMS"))

node_ems -->|"writes setpoints"| node_modbus
node_modbus -->|"serves telemetry"| node_ems
node_program -->|"updates registers"| node_modbus
node_program -->|"steps physics"| node_model
node_model -->|"queries limits"| node_curve
node_curve -->|"loads curves"| node_curve_data
node_model -->|"returns state"| node_output
node_program -->|"loads settings"| node_config
node_program -->|"runs CSV mode"| node_csv

click node_program "https://github.com/tsoun/bess-hil-simulator/blob/main/BessSim.Hil/Program.cs"
click node_csv "https://github.com/tsoun/bess-hil-simulator/blob/main/BessSim.Hil/Program.cs"
click node_config "https://github.com/tsoun/bess-hil-simulator/blob/main/sim-config.json"
click node_model "https://github.com/tsoun/bess-hil-simulator/blob/main/BessSim.Core/BessPhysicsModel.cs"
click node_curve "https://github.com/tsoun/bess-hil-simulator/blob/main/BessSim.Core/PqCapabilityCurve.cs"
click node_curve_data "https://github.com/tsoun/bess-hil-simulator/blob/main/pq-curves.json"
click node_output "https://github.com/tsoun/bess-hil-simulator/blob/main/BessSim.Core/Types.cs"
click node_modbus "https://github.com/tsoun/bess-hil-simulator/blob/main/BessSim.Hil/ModbusServerWrapper.cs"

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_program,node_csv,node_config toneBlue
class node_model,node_curve,node_curve_data,node_output toneAmber
class node_modbus toneMint
class node_ems toneIndigo
```

## Components

### Simulation Runtime

- [Runtime Orchestrator](https://github.com/tsoun/bess-hil-simulator/blob/main/BessSim.Hil/Program.cs): `BessSim.Hil/Program.cs`
- [CSV Simulation](https://github.com/tsoun/bess-hil-simulator/blob/main/BessSim.Hil/Program.cs): `BessSim.Hil/Program.cs`
- [Simulation Settings](https://github.com/tsoun/bess-hil-simulator/blob/main/sim-config.json): `sim-config.json`

### Plant Model

- [BESS Physics](https://github.com/tsoun/bess-hil-simulator/blob/main/BessSim.Core/BessPhysicsModel.cs): `BessSim.Core/BessPhysicsModel.cs`
- [P-Q Capability](https://github.com/tsoun/bess-hil-simulator/blob/main/BessSim.Core/PqCapabilityCurve.cs): `BessSim.Core/PqCapabilityCurve.cs`
- [Capability Data](https://github.com/tsoun/bess-hil-simulator/blob/main/pq-curves.json): `pq-curves.json`
- [Plant Output Contract](https://github.com/tsoun/bess-hil-simulator/blob/main/BessSim.Core/Types.cs): `BessSim.Core/Types.cs`

### EMS Interface

- [Modbus TCP Server](https://github.com/tsoun/bess-hil-simulator/blob/main/BessSim.Hil/ModbusServerWrapper.cs): `BessSim.Hil/ModbusServerWrapper.cs`

### Other components

- **External EMS**

## Connections

- External EMS → Modbus TCP Server: writes setpoints (evidence: `README.md`)
- Modbus TCP Server → External EMS: serves telemetry (evidence: `README.md`)
- Runtime Orchestrator → Modbus TCP Server: updates registers (evidence: `BessSim.Hil/Program.cs`)
- Runtime Orchestrator → BESS Physics: steps physics (evidence: `BessSim.Hil/Program.cs`)
- BESS Physics → P-Q Capability: queries limits (evidence: `BessSim.Core/BessPhysicsModel.cs`)
- P-Q Capability → Capability Data: loads curves (evidence: `BessSim.Core/PqCapabilityCurve.cs`)
- BESS Physics → Plant Output Contract: returns state (evidence: `BessSim.Core/BessPhysicsModel.cs`)
- Runtime Orchestrator → Simulation Settings: loads settings (evidence: `BessSim.Hil/Program.cs`)
- Runtime Orchestrator → CSV Simulation: runs CSV mode (evidence: `BessSim.Hil/Program.cs`)
