# shiv3/ocpp-cp-simulator architecture

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

- Interactive diagram: https://gitdiagram.com/shiv3/ocpp-cp-simulator
- Repository: https://github.com/shiv3/ocpp-cp-simulator

## Overview

1. **Overall shape**
   - This repository is an **OCPP 1.6J charge point simulator** with three user-facing entry points: the main browser/desktop app, a legacy v1 web app, and a headless CLI.
   - The architectural center is the **charge point simulation core** under `src/cp`, which is reused by the interactive UI and the automation-oriented CLI.

2. **Main runtime surfaces**
   - `src/App.tsx` and `src/components/*` form the **current browser UI**.
   - `src-tauri/*` wraps that browser app as a **Tauri desktop app**, so the same front-end can run in a web browser or as a desktop binary.
   - `src/v1/*` is a **separate legacy implementation** with its own UI, state store, and CP logic, kept isolated from the newer architecture.
   - `src/cli/*` provides a **headless Bun-based command-line interface** for scripting, CI, and machine-driven control.

3. **Core simulator boundary**
   - `src/cp/domain` contains the business objects and value types for the simulated charge point: **ChargePoint, Connector, Reservation, Transaction, Configuration, EV settings, and meter value scheduling**.
   - This layer is the most stable part of the repo and is where the simulator’s state model lives, independent of UI or transport details.

4. **Application orchestration**
   - `src/cp/application` coordinates behavior above the domain model.
   - `scenario/*` handles **scenario execution and runtime management**.
   - `services/*` handles **state management, heartbeat behavior, and state history recording**.
   - `state/machines/*` defines explicit **state-machine logic** for connector state and scenario state, which is important for diagramming transitions and lifecycle control.

5. **OCPP transport layer**
   - `src/cp/infrastructure/transport` is the boundary to the external OCPP central system.
   - `OCPPWebSocket.ts` and `OCPPMessageHandler.ts` manage the **WebSocket connection and message dispatch**.
   - `handlers/*` splits OCPP traffic into **call** and **callresult** handlers, with dedicated handlers for operations such as configuration, diagnostics, remote start/stop, reservations, reset, and smart charging.
   - This is the main outbound/inbound integration point with the external OCPP backend.

6. **Message dispatch and protocol handling**
   - `MessageHandlerRegistry.ts` centralizes handler lookup, so incoming OCPP messages are routed to the right handler by message type/action.
   - The separation between protocol transport and domain/application logic makes it easier to diagram the simulator as: **WebSocket → message handling → application services/state machines → domain objects**.

7. **Scenario system**
   - The scenario subsystem under `src/cp/application/scenario` models scripted simulator behavior.
   - It includes an executor, manager, runtime, and typed scenario definitions, plus a test suite for the executor.
   - The browser UI in `src/components/scenario/*` is the editing/control surface for these scenarios, and the node components under `scenario/nodes/*` represent scenario steps such as delays, status changes, reservations, connector plug actions, meter values, and transaction events.

8. **State visualization and history**
   - `src/components/state-transition/*` and `src/data/hooks/useStateHistory.ts` are the UI-facing view of runtime state changes.
   - `StateHistory` and `StateSnapshot`/`StateTransition` types provide the underlying timeline data used by visualizers.
   - This subsystem is useful in diagrams because it shows that runtime state is not only simulated, but also **captured and replayed for inspection**.

9. **Data-access abstraction**
   - `src/data/interfaces` defines repository/service boundaries for charge points, connectors, scenarios, config, and state history.
   - `src/data/local/*` provides the concrete local implementations used by the UI.
   - `src/data/providers/DataProvider.tsx` and the `use*` hooks form the bridge between React components and simulator data, keeping the UI decoupled from storage and runtime details.

10. **Persistence and local helpers**
   - `src/utils/scenarioStorage.ts`, `connectorStorage.ts`, and `scenarioTemplates.ts` suggest browser-side persistence/templates for the interactive app.
   - `src/data/local/*` and `src/v1/store/*` indicate that the browser experiences maintain some **local client-side state**, rather than relying on a server-side database.

11. **CLI architecture**
   - `src/cli/*` is a separate headless surface built for automation.
   - Its structure suggests a split between **client transport**, **daemon/service orchestration**, **interactive REPL**, **JSON mode output**, and **human-readable output formatting**.
   - For a diagram, treat it as a second consumer of the simulator/runtime concepts, optimized for non-UI control over the same charge point behavior.

12. **Legacy v1 architecture**
   - `src/v1/*` is a self-contained older implementation with its own CP model, components, store, and bootstrap.
   - It should be drawn as a **parallel legacy stack**, not as a direct dependency of the newer browser app.

13. **Build and packaging boundaries**
   - The repo is TypeScript-based, built with **Vite** for the browser side and **Bun** for CLI execution.
   - `src-tauri` adds a native packaging boundary for the desktop distribution.
   - GitHub Actions under `.github/workflows` handle release/deploy automation, which matters for understanding how the browser/Tauri artifacts are shipped.

14. **How the pieces fit together**
   - The most important runtime flow is: **UI or CLI input → application services/scenario engine → domain state → OCPP WebSocket transport → external central system**, with state history fed back into the UI for inspection.
   - The repo’s main architectural boundary is between **presentation/interaction layers** and the **shared simulation core** under `src/cp`.

Main entry points: [`src/cp/application/services`](https://github.com/shiv3/ocpp-cp-simulator/tree/main/src/cp/application/services) (Services), [`src/data/hooks`](https://github.com/shiv3/ocpp-cp-simulator/tree/main/src/data/hooks) (Data hooks), [`src/cp/infrastructure/transport/handlers`](https://github.com/shiv3/ocpp-cp-simulator/tree/main/src/cp/infrastructure/transport/handlers) (Protocol handlers), [`src/cli`](https://github.com/shiv3/ocpp-cp-simulator/tree/main/src/cli) (CLI runtime)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g_browser["Browser app"]
  node_n_app["Main app<br/>React entry<br/>[App.tsx]"]
  node_n_ui_components["UI components<br/>React UI"]
  node_n_scenario_editor_ui["Scenario editor<br/>Scenario UI"]
  node_n_state_view["State timeline<br/>History UI"]
  node_n_data_provider["Data provider<br/>React data bridge<br/>[DataProvider.tsx]"]
  node_n_data_hooks["Data hooks<br/>UI hooks"]
  node_n_local_data["Local data<br/>Client storage"]
end

subgraph group_g_core["Simulation core"]
  node_n_cp_domain[("Domain model<br/>Simulator domain")]
  node_n_cp_services["Services"]
  node_n_cp_machines{{"State machines<br/>Lifecycle logic"}}
  node_n_cp_scenario["Scenario engine<br/>Scenario runtime"]
  node_n_cp_transport["OCPP transport<br/>WebSocket protocol"]
  node_n_cp_handlers["Protocol handlers<br/>OCPP routing"]
end

subgraph group_g_cli["CLI"]
  node_n_cli_main["CLI entry<br/>Bun CLI<br/>[main.ts]"]
  node_n_cli_runtime["CLI runtime<br/>Daemon/service"]
end

subgraph group_g_legacy["Legacy v1"]
  node_n_legacy_app["V1 app<br/>Legacy React<br/>[V1App.tsx]"]
  node_n_legacy_cp["V1 core<br/>Legacy simulator"]
end

subgraph group_g_desktop["Desktop wrapper"]
  node_n_desktop["Tauri shell<br/>Desktop packaging"]
end

node_n_app -->|"renders"| node_n_ui_components
node_n_app -->|"uses"| node_n_data_provider
node_n_ui_components -->|"reads"| node_n_data_hooks
node_n_scenario_editor_ui -->|"reads"| node_n_data_hooks
node_n_state_view -->|"reads"| node_n_data_hooks
node_n_data_provider -->|"binds"| node_n_local_data
node_n_data_hooks -->|"queries"| node_n_local_data
node_n_local_data -->|"drives"| node_n_cp_services
node_n_cp_services -->|"updates"| node_n_cp_domain
node_n_cp_services -->|"coordinates"| node_n_cp_machines
node_n_cp_scenario -->|"controls"| node_n_cp_domain
node_n_cp_scenario -->|"advances"| node_n_cp_machines
node_n_cp_transport -->|"dispatches"| node_n_cp_handlers
node_n_cp_handlers -->|"commands"| node_n_cp_domain
node_n_cp_handlers -->|"invokes"| node_n_cp_services
node_n_cli_main -->|"boots"| node_n_cli_runtime
node_n_cli_runtime -->|"orchestrates"| node_n_cp_scenario
node_n_cli_runtime -->|"connects"| node_n_cp_transport
node_n_legacy_app -->|"uses"| node_n_legacy_cp
node_n_desktop -->|"wraps"| node_n_app

click node_n_app "https://github.com/shiv3/ocpp-cp-simulator/blob/main/src/App.tsx"
click node_n_ui_components "https://github.com/shiv3/ocpp-cp-simulator/tree/main/src/components"
click node_n_scenario_editor_ui "https://github.com/shiv3/ocpp-cp-simulator/tree/main/src/components/scenario"
click node_n_state_view "https://github.com/shiv3/ocpp-cp-simulator/tree/main/src/components/state-transition"
click node_n_data_provider "https://github.com/shiv3/ocpp-cp-simulator/blob/main/src/data/providers/DataProvider.tsx"
click node_n_data_hooks "https://github.com/shiv3/ocpp-cp-simulator/tree/main/src/data/hooks"
click node_n_local_data "https://github.com/shiv3/ocpp-cp-simulator/tree/main/src/data/local"
click node_n_cp_domain "https://github.com/shiv3/ocpp-cp-simulator/tree/main/src/cp/domain"
click node_n_cp_services "https://github.com/shiv3/ocpp-cp-simulator/tree/main/src/cp/application/services"
click node_n_cp_machines "https://github.com/shiv3/ocpp-cp-simulator/tree/main/src/cp/application/state/machines"
click node_n_cp_scenario "https://github.com/shiv3/ocpp-cp-simulator/tree/main/src/cp/application/scenario"
click node_n_cp_transport "https://github.com/shiv3/ocpp-cp-simulator/tree/main/src/cp/infrastructure/transport"
click node_n_cp_handlers "https://github.com/shiv3/ocpp-cp-simulator/tree/main/src/cp/infrastructure/transport/handlers"
click node_n_cli_main "https://github.com/shiv3/ocpp-cp-simulator/blob/main/src/cli/main.ts"
click node_n_cli_runtime "https://github.com/shiv3/ocpp-cp-simulator/tree/main/src/cli"
click node_n_legacy_app "https://github.com/shiv3/ocpp-cp-simulator/blob/main/src/v1/V1App.tsx"
click node_n_legacy_cp "https://github.com/shiv3/ocpp-cp-simulator/tree/main/src/v1/cp"
click node_n_desktop "https://github.com/shiv3/ocpp-cp-simulator/tree/main/src-tauri"

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_n_app,node_n_ui_components,node_n_scenario_editor_ui,node_n_state_view,node_n_data_provider,node_n_data_hooks,node_n_local_data toneBlue
class node_n_cp_domain,node_n_cp_services,node_n_cp_machines,node_n_cp_scenario,node_n_cp_transport,node_n_cp_handlers toneAmber
class node_n_cli_main,node_n_cli_runtime toneMint
class node_n_legacy_app,node_n_legacy_cp toneRose
class node_n_desktop toneIndigo
```

## Components

### Browser app

Current interactive simulator UI and its data-facing layer.

- [Main app](https://github.com/shiv3/ocpp-cp-simulator/blob/main/src/App.tsx): React entry · Current browser application shell and top-level composition. · `src/App.tsx`
- [UI components](https://github.com/shiv3/ocpp-cp-simulator/tree/main/src/components): React UI · Primary visual surfaces for charge point, settings, logs, and scenario control. · `src/components`
- [Scenario editor](https://github.com/shiv3/ocpp-cp-simulator/tree/main/src/components/scenario): Scenario UI · Browser controls for building and running scripted simulator scenarios. · `src/components/scenario`
- [State timeline](https://github.com/shiv3/ocpp-cp-simulator/tree/main/src/components/state-transition): History UI · Visualizes state transitions and scenario/runtime history for inspection. · `src/components/state-transition`
- [Data provider](https://github.com/shiv3/ocpp-cp-simulator/blob/main/src/data/providers/DataProvider.tsx): React data bridge · Connects UI hooks to repositories and local simulator services. · `src/data/providers/DataProvider.tsx`
- [Data hooks](https://github.com/shiv3/ocpp-cp-simulator/tree/main/src/data/hooks): UI hooks · View-model hooks for charge points, connectors, scenarios, config, and history. · `src/data/hooks`
- [Local data](https://github.com/shiv3/ocpp-cp-simulator/tree/main/src/data/local): Client storage · Browser-side repository implementations and local state persistence. · `src/data/local`

### Simulation core

Shared charge point model, orchestration, and transport integration.

- [Domain model](https://github.com/shiv3/ocpp-cp-simulator/tree/main/src/cp/domain): Simulator domain · Core charge point entities and value objects: charge point, connector, reservation, transaction, configuration, EV settings, and meter scheduling. · `src/cp/domain`
- [Services](https://github.com/shiv3/ocpp-cp-simulator/tree/main/src/cp/application/services): App services · State management, heartbeat behavior, and state history recording. · `src/cp/application/services`
- [State machines](https://github.com/shiv3/ocpp-cp-simulator/tree/main/src/cp/application/state/machines): Lifecycle logic · Explicit connector and scenario state-machine behavior. · `src/cp/application/state/machines`
- [Scenario engine](https://github.com/shiv3/ocpp-cp-simulator/tree/main/src/cp/application/scenario): Scenario runtime · Execution, runtime coordination, and management for scripted simulator behavior. · `src/cp/application/scenario`
- [OCPP transport](https://github.com/shiv3/ocpp-cp-simulator/tree/main/src/cp/infrastructure/transport): WebSocket protocol · WebSocket connection management and OCPP message dispatch. · `src/cp/infrastructure/transport`
- [Protocol handlers](https://github.com/shiv3/ocpp-cp-simulator/tree/main/src/cp/infrastructure/transport/handlers): OCPP routing · Registry plus call/callresult handlers for configuration, diagnostics, remote control, reservations, reset, and smart charging. · `src/cp/infrastructure/transport/handlers`

### CLI

Headless automation and scripting entry point.

- [CLI entry](https://github.com/shiv3/ocpp-cp-simulator/blob/main/src/cli/main.ts): Bun CLI · Headless command-line surface for automation, REPL use, and machine-driven control. · `src/cli/main.ts`
- [CLI runtime](https://github.com/shiv3/ocpp-cp-simulator/tree/main/src/cli): Daemon/service · Client transport, daemon orchestration, and shared service layer for the CLI. · `src/cli`

### Legacy v1

Older isolated implementation kept alongside the current architecture.

- [V1 app](https://github.com/shiv3/ocpp-cp-simulator/blob/main/src/v1/V1App.tsx): Legacy React · Older standalone browser app and bootstrap. · `src/v1/V1App.tsx`
- [V1 core](https://github.com/shiv3/ocpp-cp-simulator/tree/main/src/v1/cp): Legacy simulator · Legacy charge point model, WebSocket transport, message handling, and local state store. · `src/v1/cp`

### Desktop wrapper

Tauri packaging boundary for the browser app.

- [Tauri shell](https://github.com/shiv3/ocpp-cp-simulator/tree/main/src-tauri): Desktop packaging · Native wrapper and packaging boundary for the browser application. · `src-tauri`

## Connections

- Main app → UI components: renders · Main app composes the shared browser UI.
- Main app → Data provider: uses · App is wired to simulator data through the provider.
- UI components → Data hooks: reads · Visual components consume typed hooks for simulator state.
- Scenario editor → Data hooks: reads · Scenario editor uses scenario and config hooks.
- State timeline → Data hooks: reads · Timeline and transition views consume history hooks.
- Data provider → Local data: binds · Provider connects React data access to local repositories and services.
- Data hooks → Local data: queries · Hooks are backed by local implementations.
- Local data → Services: drives · Local repositories and services manage simulator state.
- Services → Domain model: updates · Application services act on the core domain model.
- Services → State machines: coordinates · Services use explicit lifecycle state machines.
- Scenario engine → Domain model: controls · Scenario execution mutates and queries core simulator state.
- Scenario engine → State machines: advances · Scenario runtime uses scenario-state machinery.
- OCPP transport → Protocol handlers: dispatches · Transport hands messages to protocol handlers.
- Protocol handlers → Domain model: commands · OCPP handlers translate protocol actions into domain changes.
- Protocol handlers → Services: invokes · Handlers call into application services and state management.
- CLI entry → CLI runtime: boots · CLI entry selects daemon, REPL, JSON, or output modes.
- CLI runtime → Scenario engine: orchestrates · Headless CLI reuses the shared scenario/runtime layer.
- CLI runtime → OCPP transport: connects · CLI can drive the same OCPP transport layer.
- V1 app → V1 core: uses · Legacy UI is paired with the legacy charge point implementation.
- Tauri shell → Main app: wraps · Tauri packages the current browser app as a desktop binary.
