# glocker/aetherflow architecture

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

- Interactive diagram: https://gitdiagram.com/glocker/aetherflow
- Repository: https://github.com/glocker/aetherflow

## Overview

##### End-to-end data flow
The primary flow is: `controller_simulator` emits CAN SYNC frames, those frames traverse a UDP multicast “virtual CAN bus,” `eps_simulator` consumes them and produces EPS housekeeping telemetry as SpaceCAN REPLY frames, and `bridge_service` listens passively, reassembles packets, parses telemetry, and exposes the result to a dashboard over HTTP/WebSocket.

##### Transport boundary
`transport/` contains the pluggable bus backends. The current demo backend is `udp_transport.c`, which uses multicast as a local development bus. `socketcan_transport.c` and `memory_transport.c` exist as future/alternate backends. The important boundary is `can_frame_t`: protocol code never speaks UDP or SocketCAN directly; it only reads/writes canonical CAN frame objects.

##### Wire encoding
Because UDP is only a transport wrapper, the repo defines an explicit `AFC1` wire envelope in `can_frame_wire.c` / `can_frame_wire.h`. That keeps frame encoding stable across compilers and platforms by serializing the CAN ID, DLC, and 8-byte data payload explicitly instead of shipping raw C structs.

##### SpaceCAN protocol stack
`src/spacecan_*.c` and `include/spacecan*.h` implement the transport-independent protocol layer: CAN ID calculation, fragmentation of SpaceCAN packets into CAN frames, reassembly back into packets, and parsing of service/subtype/payload fields. The code also defines the core arbitration IDs used throughout the system: SYNC (`0x080`), REQUEST (`0x600 + node_id`), REPLY (`0x580 + node_id`), and HEARTBEAT (`0x700 + node_id`).

##### EPS simulator as an onboard subsystem
`eps_simulator.c` models a single EPS node with a small state machine (`BOOT -> PRE_OPERATIONAL -> OPERATIONAL`). Once operational, each SYNC tick produces deterministic housekeeping telemetry. That telemetry is encoded as SpaceCAN service 3, subtype 25, then fragmented into CAN frames and sent back on the bus. This subsystem is the source of the demo’s actual telemetry data.

##### Bridge service as ground-segment ingestion
`bridge_service_main.c` is the ground station boundary. It subscribes to the multicast bus, reconstructs SpaceCAN packets, filters for the EPS housekeeping service, and converts the decoded values into JSON. It then exposes the data through HTTP endpoints and a WebSocket stream, making it the integration point between the bus layer and any UI/consumer.

##### Dashboard/UI boundary
`openmct/` is a separate frontend subsystem. It contains an Open MCT plugin, telemetry provider, realtime plumbing, formatting/dictionary logic, and custom UI components. Architecturally, it does not talk to the simulators directly; it consumes the bridge’s HTTP/WebSocket API. The repo also includes a minimal built-in dashboard served by `bridge_service` for a dependency-light smoke test of the bridge boundary.

##### Compatibility and verification
`compat/` and `tools/generate_spacecan_vectors.c` provide byte-level protocol compatibility checks. The generated vectors and Python harness verify both directions: C-generated frames/packets can be parsed by Python, and Python can re-encode scenarios to exactly match the C output. This is an important architectural guardrail because the protocol is intended to remain portable across future implementations.

##### Testing strategy
The test suite is split by subsystem: `tests/test_spacecan_codec.c` validates protocol encoding/decoding and `tests/test_eps_simulator.c` validates the EPS state machine and telemetry behavior. This mirrors the architecture: protocol correctness is tested separately from simulator behavior, which is separate from transport and UI concerns.

##### Build and orchestration
`Makefile` and `tools/run_demo.sh` orchestrate the full demo. The default demo mode builds the C services, runs them as separate local processes, and starts the Open MCT dev server. Environment variables control the controller rate and bridge/dashboard URLs, which keeps the runtime topology configurable without changing code.

Main entry points: [`src/spacecan_id.c`](https://github.com/glocker/aetherflow/blob/main/src/spacecan_id.c) (SpaceCAN Core), [`src/bridge_service_main.c`](https://github.com/glocker/aetherflow/blob/main/src/bridge_service_main.c) (Bridge), [`include/transport.h`](https://github.com/glocker/aetherflow/blob/main/include/transport.h) (Transport API), [`tools/run_demo.sh`](https://github.com/glocker/aetherflow/blob/main/tools/run_demo.sh) (Demo Script)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_controller_simulator_main(("Controller<br/>simulator entry"))
  node_eps_simulator_main(("EPS Main<br/>simulator entry"))
  node_eps_simulator["EPS Node<br/>state machine<br/>[eps_simulator.c]"]
end

subgraph group_protocol["Protocol"]
  node_spacecan_core["SpaceCAN Core<br/>protocol stack<br/>[spacecan_id.c]"]
  node_spacecan_packets["Packets<br/>packet codec<br/>[spacecan_packet.c]"]
  node_spacecan_reassembly["Reassembly<br/>stream codec"]
  node_spacecan_services["Services<br/>service defs"]
  node_can_frame_api["CAN Frame<br/>transport boundary<br/>[can_frame.h]"]
  node_wire_envelope["AFC1 Wire<br/>frame encoding<br/>[can_frame_wire.c]"]
  node_transport_api["Transport API<br/>backend interface<br/>[transport.h]"]
  node_udp_transport["UDP Bus<br/>transport backend<br/>[udp_transport.c]"]
  node_socketcan_transport["SocketCAN<br/>transport backend"]
  node_memory_transport["Memory Bus<br/>transport backend<br/>[memory_transport.c]"]
end

subgraph group_ground["Ground"]
  node_bridge_service_main["Bridge<br/>ingest service"]
end

subgraph group_ui["UI"]
  node_openmct_plugin["Open MCT<br/>frontend plugin<br/>[plugin.js]"]
  node_telemetry_provider["Telemetry API<br/>data adapter"]
end

subgraph group_verify["Verify"]
  node_compat_vectors["Vectors<br/>compatibility data"]
  node_vector_checker["Vector Check<br/>compat harness<br/>[check_vectors.py]"]
  node_spacecan_tests["Codec Tests<br/>unit tests"]
  node_eps_tests["EPS Tests<br/>unit tests"]
end

subgraph group_build["Build"]
  node_run_demo["Demo Script<br/>orchestration<br/>[run_demo.sh]"]
end

node_controller_simulator_main -->|"uses bus"| node_transport_api
node_eps_simulator_main -->|"starts"| node_eps_simulator
node_eps_simulator -->|"encodes telemetry"| node_spacecan_core
node_controller_simulator_main -->|"SYNC ids"| node_spacecan_core
node_spacecan_core -->|"fragments"| node_spacecan_packets
node_spacecan_core -->|"reassembles"| node_spacecan_reassembly
node_spacecan_core -->|"parses"| node_spacecan_services
node_spacecan_core -->|"frames"| node_can_frame_api
node_can_frame_api -->|"serializes"| node_wire_envelope
node_transport_api -->|"backend"| node_udp_transport
node_transport_api -->|"backend"| node_socketcan_transport
node_transport_api -->|"backend"| node_memory_transport
node_udp_transport -->|"ships frames"| node_wire_envelope
node_bridge_service_main -->|"listens via"| node_transport_api
node_bridge_service_main -->|"decodes"| node_spacecan_reassembly
node_bridge_service_main -->|"filters telemetry"| node_spacecan_services
node_bridge_service_main -->|"serves api"| node_telemetry_provider
node_telemetry_provider -->|"feeds"| node_openmct_plugin
node_compat_vectors -->|"verified by"| node_vector_checker
node_spacecan_tests -->|"covers"| node_spacecan_core
node_eps_tests -->|"covers"| node_eps_simulator
node_run_demo -->|"launches"| node_controller_simulator_main
node_run_demo -->|"launches"| node_eps_simulator_main
node_run_demo -->|"launches"| node_bridge_service_main
node_run_demo -->|"launches"| node_openmct_plugin

click node_controller_simulator_main "https://github.com/glocker/aetherflow/blob/main/src/controller_simulator_main.c"
click node_eps_simulator_main "https://github.com/glocker/aetherflow/blob/main/src/eps_simulator_main.c"
click node_eps_simulator "https://github.com/glocker/aetherflow/blob/main/src/eps_simulator.c"
click node_bridge_service_main "https://github.com/glocker/aetherflow/blob/main/src/bridge_service_main.c"
click node_spacecan_core "https://github.com/glocker/aetherflow/blob/main/src/spacecan_id.c"
click node_spacecan_packets "https://github.com/glocker/aetherflow/blob/main/src/spacecan_packet.c"
click node_spacecan_reassembly "https://github.com/glocker/aetherflow/blob/main/src/spacecan_reassembly.c"
click node_spacecan_services "https://github.com/glocker/aetherflow/blob/main/src/spacecan_services.c"
click node_can_frame_api "https://github.com/glocker/aetherflow/blob/main/include/can_frame.h"
click node_wire_envelope "https://github.com/glocker/aetherflow/blob/main/src/can_frame_wire.c"
click node_transport_api "https://github.com/glocker/aetherflow/blob/main/include/transport.h"
click node_udp_transport "https://github.com/glocker/aetherflow/blob/main/transport/udp_transport.c"
click node_socketcan_transport "https://github.com/glocker/aetherflow/blob/main/transport/socketcan_transport.c"
click node_memory_transport "https://github.com/glocker/aetherflow/blob/main/transport/memory_transport.c"
click node_openmct_plugin "https://github.com/glocker/aetherflow/blob/main/openmct/src/plugin.js"
click node_telemetry_provider "https://github.com/glocker/aetherflow/blob/main/openmct/src/telemetry-provider.js"
click node_compat_vectors "https://github.com/glocker/aetherflow/blob/main/compat/vectors/aetherflow_spacecan_vectors.json"
click node_vector_checker "https://github.com/glocker/aetherflow/blob/main/compat/python/check_vectors.py"
click node_spacecan_tests "https://github.com/glocker/aetherflow/blob/main/tests/test_spacecan_codec.c"
click node_eps_tests "https://github.com/glocker/aetherflow/blob/main/tests/test_eps_simulator.c"
click node_run_demo "https://github.com/glocker/aetherflow/blob/main/tools/run_demo.sh"

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_controller_simulator_main,node_eps_simulator_main,node_eps_simulator toneBlue
class node_spacecan_core,node_spacecan_packets,node_spacecan_reassembly,node_spacecan_services,node_can_frame_api,node_wire_envelope,node_transport_api,node_udp_transport,node_socketcan_transport,node_memory_transport toneAmber
class node_bridge_service_main toneMint
class node_openmct_plugin,node_telemetry_provider toneRose
class node_compat_vectors,node_vector_checker,node_spacecan_tests,node_eps_tests toneIndigo
class node_run_demo toneTeal
```

## Components

### Runtime

Simulators and services that run the demo loop

- [Controller](https://github.com/glocker/aetherflow/blob/main/src/controller_simulator_main.c): simulator entry · Emits SYNC frames to drive the demo bus · `src/controller_simulator_main.c`
- [EPS Main](https://github.com/glocker/aetherflow/blob/main/src/eps_simulator_main.c): simulator entry · Starts the onboard EPS node process · `src/eps_simulator_main.c`
- [EPS Node](https://github.com/glocker/aetherflow/blob/main/src/eps_simulator.c): state machine · Boots, transitions to operational, and generates housekeeping telemetry · `src/eps_simulator.c`

### Protocol

Transport-independent CAN and SpaceCAN layers

- [SpaceCAN Core](https://github.com/glocker/aetherflow/blob/main/src/spacecan_id.c): protocol stack · ID calculation, packet fragmentation, reassembly, and service parsing · `src/spacecan_id.c`
- [Packets](https://github.com/glocker/aetherflow/blob/main/src/spacecan_packet.c): packet codec · SpaceCAN packet framing and payload handling · `src/spacecan_packet.c`
- [Reassembly](https://github.com/glocker/aetherflow/blob/main/src/spacecan_reassembly.c): stream codec · Rebuilds SpaceCAN packets from CAN frames · `src/spacecan_reassembly.c`
- [Services](https://github.com/glocker/aetherflow/blob/main/src/spacecan_services.c): service defs · Defines SpaceCAN service and subtype mappings · `src/spacecan_services.c`
- [CAN Frame](https://github.com/glocker/aetherflow/blob/main/include/can_frame.h): transport boundary · Canonical CAN frame abstraction shared by all protocol code · `include/can_frame.h`
- [AFC1 Wire](https://github.com/glocker/aetherflow/blob/main/src/can_frame_wire.c): frame encoding · Explicit wire serialization for CAN frames over transport · `src/can_frame_wire.c`
- [Transport API](https://github.com/glocker/aetherflow/blob/main/include/transport.h): backend interface · Abstracts bus backends behind a common CAN frame interface · `include/transport.h`
- [UDP Bus](https://github.com/glocker/aetherflow/blob/main/transport/udp_transport.c): transport backend · Multicast demo backend for the virtual CAN bus · `transport/udp_transport.c`
- [SocketCAN](https://github.com/glocker/aetherflow/blob/main/transport/socketcan_transport.c): transport backend · Host CAN backend for future or alternate deployments · `transport/socketcan_transport.c`
- [Memory Bus](https://github.com/glocker/aetherflow/blob/main/transport/memory_transport.c): transport backend · In-process transport for tests and alternate wiring · `transport/memory_transport.c`

### Ground

Bridge and dashboard ingestion

- [Bridge](https://github.com/glocker/aetherflow/blob/main/src/bridge_service_main.c): ingest service · Reassembles packets, decodes telemetry, and serves JSON/WebSocket output · `src/bridge_service_main.c`

### UI

Open MCT frontend and realtime consumer

- [Open MCT](https://github.com/glocker/aetherflow/blob/main/openmct/src/plugin.js): frontend plugin · Dashboard plugin, realtime plumbing, and telemetry presentation · `openmct/src/plugin.js`
- [Telemetry API](https://github.com/glocker/aetherflow/blob/main/openmct/src/telemetry-provider.js): data adapter · Consumes bridge service data for Open MCT · `openmct/src/telemetry-provider.js`

### Verify

Compatibility vectors and subsystem tests

- [Vectors](https://github.com/glocker/aetherflow/blob/main/compat/vectors/aetherflow_spacecan_vectors.json): compatibility data · Reference protocol vectors for byte-level cross-language checks · `compat/vectors/aetherflow_spacecan_vectors.json`
- [Vector Check](https://github.com/glocker/aetherflow/blob/main/compat/python/check_vectors.py): compat harness · Python harness that validates generated protocol vectors · `compat/python/check_vectors.py`
- [Codec Tests](https://github.com/glocker/aetherflow/blob/main/tests/test_spacecan_codec.c): unit tests · Validates SpaceCAN encoding and decoding behavior · `tests/test_spacecan_codec.c`
- [EPS Tests](https://github.com/glocker/aetherflow/blob/main/tests/test_eps_simulator.c): unit tests · Validates EPS state transitions and telemetry output · `tests/test_eps_simulator.c`

### Build

Orchestration and demo launch scripts

- [Demo Script](https://github.com/glocker/aetherflow/blob/main/tools/run_demo.sh): orchestration · Builds and launches the simulated bus, bridge, and UI · `tools/run_demo.sh`

## Connections

- Controller → Transport API: uses bus · Controller publishes SYNC frames through the abstract transport
- EPS Main → EPS Node: starts · Main entry boots the EPS node state machine
- EPS Node → SpaceCAN Core: encodes telemetry · EPS creates SpaceCAN housekeeping packets before fragmentation
- Controller → SpaceCAN Core: SYNC ids · Controller relies on protocol ID constants for SYNC traffic
- SpaceCAN Core → Packets: fragments · Protocol layer fragments packets into CAN frames
- SpaceCAN Core → Reassembly: reassembles · Protocol layer rebuilds packets from incoming frames
- SpaceCAN Core → Services: parses · Protocol layer interprets service and subtype fields
- SpaceCAN Core → CAN Frame: frames · All protocol work is expressed in canonical CAN frames
- CAN Frame → AFC1 Wire: serializes · CAN frames are encoded into the AFC1 wire envelope
- Transport API → UDP Bus: backend · Current demo transport implementation
- Transport API → SocketCAN: backend · Alternative host CAN implementation
- Transport API → Memory Bus: backend · In-process transport implementation
- UDP Bus → AFC1 Wire: ships frames · UDP backend moves serialized CAN frames over multicast
- Bridge → Transport API: listens via · Bridge subscribes to the bus through the transport abstraction
- Bridge → Reassembly: decodes · Bridge reconstructs packets from received frames
- Bridge → Services: filters telemetry · Bridge selects EPS housekeeping service data
- Bridge → Telemetry API: serves api · Bridge exposes decoded telemetry for UI consumption
- Telemetry API → Open MCT: feeds · Open MCT plugin consumes bridge telemetry and status data
- Vectors → Vector Check: verified by · Generated vectors are checked by the Python harness
- Codec Tests → SpaceCAN Core: covers · Codec tests validate protocol behavior
- EPS Tests → EPS Node: covers · EPS tests validate the onboard state machine and output
- Demo Script → Controller: launches · Demo script starts the controller process
- Demo Script → EPS Main: launches · Demo script starts the EPS process
- Demo Script → Bridge: launches · Demo script starts the bridge process
- Demo Script → Open MCT: launches · Demo script serves the dashboard frontend
