How shiv3/ocpp-cp-simulator works
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: services Services · hooks Data hooks · handlers Protocol handlers · cli CLI runtime
Components 18
Browser app
Current interactive simulator UI and its data-facing layer.
- Main app · Current browser application shell and top-level composition.
src/App.tsx - UI components · Primary visual surfaces for charge point, settings, logs, and scenario control.
src/components - Scenario editor · Browser controls for building and running scripted simulator scenarios.
src/components/scenario - State timeline · Visualizes state transitions and scenario/runtime history for inspection.
src/components/state-transition - Data provider · Connects UI hooks to repositories and local simulator services.
src/data/providers/DataProvider.tsx - Data hooks · View-model hooks for charge points, connectors, scenarios, config, and history.
src/data/hooks - Local data · Browser-side repository implementations and local state persistence.
src/data/local
Simulation core
Shared charge point model, orchestration, and transport integration.
- Domain model · Core charge point entities and value objects: charge point, connector, reservation, transaction, configuration, EV settings, and meter scheduling.
src/cp/domain - Services · State management, heartbeat behavior, and state history recording.
src/cp/application/services - State machines · Explicit connector and scenario state-machine behavior.
src/cp/application/state/machines - Scenario engine · Execution, runtime coordination, and management for scripted simulator behavior.
src/cp/application/scenario - OCPP transport · WebSocket connection management and OCPP message dispatch.
src/cp/infrastructure/transport - Protocol handlers · 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 · Headless command-line surface for automation, REPL use, and machine-driven control.
src/cli/main.ts - CLI runtime · Client transport, daemon orchestration, and shared service layer for the CLI.
src/cli
Legacy v1
Older isolated implementation kept alongside the current architecture.
Desktop wrapper
Tauri packaging boundary for the browser app.
- Tauri shell · Native wrapper and packaging boundary for the browser application.
src-tauri
Connections 20
- 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.