# aochenxiao/stream-punk architecture

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

- Interactive diagram: https://gitdiagram.com/aochenxiao/stream-punk
- Repository: https://github.com/aochenxiao/stream-punk

## Overview

#### Purpose and Entry Points
StreamPunk is a C++20, header-oriented framework for defining C++ data models once and deriving binary serialization, JSON, deep copy, metadata, ORM SQL, and cross-language interoperability. The primary C++ API is `include/stream-punk/StreamPunk.hpp`; optional capabilities are layered through headers such as `include/stream-punk/StreamPunkJson.hpp`. Consumers initialize global type machinery with `INIT_StreamPunk()`.

Repository-level build entry is `CMakeLists.txt`. The standalone generator entry point is `tools/sp-gen/main.cpp`. Feature-oriented runnable entry points are under `examples/*/main.cpp` and server mains.

#### C++ Type and Metadata Core
The core model is C++ classes derived from `Base`, declared through X-macro-based `UseData` definitions. Compile-time descriptors and registration provide member names, type tokens, construction, serialization, and reflection-like metadata without requiring native static reflection.
- `include/stream-punk/StreamPunk.hpp`
- `include/stream-punk/MetaData.hpp`
- `include/stream-punk/StreamPunkSchema.hpp`

This is the principal boundary: application C++ types must conform to StreamPunk’s inheritance/macro conventions; generated metadata and protocol operations depend on that shape.

#### Object Processing Services
The core serialization layer uses compact little-endian binary streams and supports pointer/object identity tracking. Adjacent extensions expose JSON conversion, deep copy, and SQL-oriented ORM metadata/generation from the same model declaration.
- `include/stream-punk/StreamPunk.hpp`
- `include/stream-punk/StreamPunkJson.hpp`
- `include/stream-punk/StreamPunkOrmGen.hpp`

The binary format is the interchange and persistence boundary; portability is constrained to same-endian architectures. ORM emits SQL suitable for MySQL/SQLite-style persistence but does not itself constitute a database runtime.

#### Metadata Extraction and Cross-Language Generation
A project-specific C++ metadata extractor includes the user’s model headers, emits a binary metadata file, and is rebuilt when types change. `sp-gen` then reads that file and generates data types, SPOI builders, and selected executor registries without recompiling the generator.
- `tools/sp-gen/main.cpp`
- `tools/sp-gen/meta-reader.hpp`
- `tools/sp-gen/generators.hpp`

Language backends cover TypeScript, Python, Java, Go, Rust, and Kotlin; examples of backend implementations include `tools/sp-gen/python_generator.cpp` and `tools/sp-gen/spoi_ts_generator.cpp`. Generated code relies on matching runtime libraries.

#### Cross-Language Runtime Layer
Each supported target language has a runtime implementing compatible binary object access plus SPOI instruction construction/execution. These are distributed source files intended to be copied or integrated into consuming applications rather than hosted services.
- `runtimes/py/stream-punk.py`
- `runtimes/ts/stream-punk.ts`
- `runtimes/go/stream-punk.go`

SPOI compatibility is a protocol boundary: query/update bytes can travel over any transport and be executed against in-memory collections in another supported runtime.

#### SPOI Query, Update, and Shadow Pipeline
SPOI represents pipeline-style in-memory operations—filtering, sorting, projection, aggregation—and field-level update instructions. C++ provides builders, execution, ranges, and a Shadow proxy that records mutations as deltas; these can support realtime synchronization or snapshot-plus-WAL recovery.
- `include/stream-punk/StreamPunkSPOI.hpp`
- `include/stream-punk/StreamPunkSPOIExecutor.hpp`
- `include/stream-punk/StreamPunkSPOIShadow.hpp`

Control flow is: builder/proxy creates instruction bytes → application transports or appends them → executor applies/query-runs them over local data → compact result or updated state is returned. Transport, authorization, conflict resolution, and durable storage policies remain application responsibilities.

#### Demonstration Applications and Infrastructure
Examples exercise the framework from basic C++ through multi-language and realtime client/server applications. C++ servers commonly use WebSockets; browser clients are Vite-based Vue/React applications. Notable end-to-end references:
- `examples/10-game/server/main.cpp`
- `examples/13-whiteboard/server/main.cpp`
- `examples/16-collab-editor/server/server.cpp`

Some examples require external infrastructure: Drogon for `examples/07-full-stack/server/web_server_main.cpp`, ixwebsocket for the collaborative editor, Node.js/npm for browser clients, and vcpkg for dependency provisioning. The optional C++26 reflection path is isolated in `include/stream-punk-reflection/StreamPunkReflection.hpp`.

Main entry points: [`include/stream-punk/MetaData.hpp`](https://github.com/aochenxiao/stream-punk/blob/main/include/stream-punk/MetaData.hpp) (Type descriptors), [`include/stream-punk/StreamPunkSPOI.hpp`](https://github.com/aochenxiao/stream-punk/blob/main/include/stream-punk/StreamPunkSPOI.hpp) (SPOI instruction bytes), [`runtimes/py/stream-punk.py`](https://github.com/aochenxiao/stream-punk/blob/main/runtimes/py/stream-punk.py) (Language runtimes), [`include/stream-punk/StreamPunkSPOIExecutor.hpp`](https://github.com/aochenxiao/stream-punk/blob/main/include/stream-punk/StreamPunkSPOIExecutor.hpp) (SPOI executor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cpp["C++ Framework"]
  node_cpp_api["Primary C++ API<br/>header API<br/>[StreamPunk.hpp]"]
  node_model["Application models<br/>Base / UseData types"]
  node_metadata["Type descriptors<br/>compile-time metadata<br/>[MetaData.hpp]"]
  node_schema["Schema support<br/>model schema"]
  node_binary["Binary object codec<br/>little-endian format<br/>[StreamPunk.hpp]"]
  node_json["JSON conversion<br/>optional extension<br/>[StreamPunkJson.hpp]"]
  node_orm["ORM SQL generation<br/>optional extension"]
  node_reflection["C++26 reflection path<br/>optional API"]
end

subgraph group_generation["Metadata &amp; Generation"]
  node_extractor["Metadata extractor<br/>project-specific extractor<br/>[meta-reader.hpp]"]
  node_generator{{"sp-gen<br/>code generator<br/>[main.cpp]"}}
  node_backends["Language backends<br/>generator backends<br/>[generators.hpp]"]
  node_generated["Generated bindings<br/>consumer source"]
end

subgraph group_runtime["Cross-language Runtimes"]
  node_language_runtimes["Language runtimes<br/>compatible binary/SPOI runtime<br/>[stream-punk.py]"]
end

subgraph group_spoi["SPOI Pipeline"]
  node_spoi_builder["SPOI builders &amp; Shadow<br/>instruction producer"]
  node_spoi_protocol["SPOI instruction bytes<br/>transport-neutral protocol<br/>[StreamPunkSPOI.hpp]"]
  node_spoi_executor["SPOI executor<br/>in-memory execution"]
end

subgraph group_examples["Examples"]
  node_realtime_examples["Realtime examples<br/>[main.cpp]"]
end

node_build["CMake build<br/>build entry<br/>[CMakeLists.txt]"]
node_applications["Application transport &amp; storage<br/>application responsibility"]

node_build -->|"builds"| node_cpp_api
node_cpp_api -->|"defines"| node_model
node_model -->|"registers"| node_metadata
node_metadata -->|"supplies"| node_schema
node_metadata -->|"drives"| node_binary
node_model -->|"converts"| node_json
node_model -->|"derives SQL from"| node_orm
node_model -->|"included by"| node_extractor
node_extractor -->|"binary metadata"| node_generator
node_generator -->|"selects"| node_backends
node_backends -->|"emits"| node_generated
node_generated -->|"uses"| node_language_runtimes
node_binary -.->|"compatible format"| node_language_runtimes
node_model -->|"targets"| node_spoi_builder
node_spoi_builder -->|"encodes"| node_spoi_protocol
node_spoi_protocol -->|"transported or appended by"| node_applications
node_applications -->|"delivers to"| node_spoi_executor
node_spoi_protocol -->|"applies or queries"| node_spoi_executor
node_language_runtimes -.->|"implements compatible execution"| node_spoi_executor
node_realtime_examples -->|"demonstrate"| node_applications
node_reflection -.->|"alternative path"| node_metadata

click node_build "https://github.com/aochenxiao/stream-punk/blob/main/CMakeLists.txt"
click node_cpp_api "https://github.com/aochenxiao/stream-punk/blob/main/include/stream-punk/StreamPunk.hpp"
click node_metadata "https://github.com/aochenxiao/stream-punk/blob/main/include/stream-punk/MetaData.hpp"
click node_schema "https://github.com/aochenxiao/stream-punk/blob/main/include/stream-punk/StreamPunkSchema.hpp"
click node_binary "https://github.com/aochenxiao/stream-punk/blob/main/include/stream-punk/StreamPunk.hpp"
click node_json "https://github.com/aochenxiao/stream-punk/blob/main/include/stream-punk/StreamPunkJson.hpp"
click node_orm "https://github.com/aochenxiao/stream-punk/blob/main/include/stream-punk/StreamPunkOrmGen.hpp"
click node_extractor "https://github.com/aochenxiao/stream-punk/blob/main/tools/sp-gen/meta-reader.hpp"
click node_generator "https://github.com/aochenxiao/stream-punk/blob/main/tools/sp-gen/main.cpp"
click node_backends "https://github.com/aochenxiao/stream-punk/blob/main/tools/sp-gen/generators.hpp"
click node_language_runtimes "https://github.com/aochenxiao/stream-punk/blob/main/runtimes/py/stream-punk.py"
click node_spoi_builder "https://github.com/aochenxiao/stream-punk/blob/main/include/stream-punk/StreamPunkSPOIShadow.hpp"
click node_spoi_protocol "https://github.com/aochenxiao/stream-punk/blob/main/include/stream-punk/StreamPunkSPOI.hpp"
click node_spoi_executor "https://github.com/aochenxiao/stream-punk/blob/main/include/stream-punk/StreamPunkSPOIExecutor.hpp"
click node_realtime_examples "https://github.com/aochenxiao/stream-punk/blob/main/examples/13-whiteboard/server/main.cpp"
click node_reflection "https://github.com/aochenxiao/stream-punk/blob/main/include/stream-punk-reflection/StreamPunkReflection.hpp"

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_cpp_api,node_model,node_metadata,node_schema,node_binary,node_json,node_orm,node_reflection toneBlue
class node_extractor,node_generator,node_backends,node_generated toneAmber
class node_language_runtimes toneMint
class node_spoi_builder,node_spoi_protocol,node_spoi_executor toneRose
class node_realtime_examples toneIndigo
class node_build,node_applications toneNeutral
```

## Components

### C++ Framework

- [Primary C++ API](https://github.com/aochenxiao/stream-punk/blob/main/include/stream-punk/StreamPunk.hpp): header API · `include/stream-punk/StreamPunk.hpp`
- **Application models**: Base / UseData types · Models must follow StreamPunk inheritance and macro conventions.
- [Type descriptors](https://github.com/aochenxiao/stream-punk/blob/main/include/stream-punk/MetaData.hpp): compile-time metadata · Registers member names, type tokens, construction, and serialization. · `include/stream-punk/MetaData.hpp`
- [Schema support](https://github.com/aochenxiao/stream-punk/blob/main/include/stream-punk/StreamPunkSchema.hpp): model schema · `include/stream-punk/StreamPunkSchema.hpp`
- [Binary object codec](https://github.com/aochenxiao/stream-punk/blob/main/include/stream-punk/StreamPunk.hpp): little-endian format · Identity-aware binary interchange and persistence format. · `include/stream-punk/StreamPunk.hpp`
- [JSON conversion](https://github.com/aochenxiao/stream-punk/blob/main/include/stream-punk/StreamPunkJson.hpp): optional extension · `include/stream-punk/StreamPunkJson.hpp`
- [ORM SQL generation](https://github.com/aochenxiao/stream-punk/blob/main/include/stream-punk/StreamPunkOrmGen.hpp): optional extension · Emits MySQL/SQLite-style SQL metadata; not a database runtime. · `include/stream-punk/StreamPunkOrmGen.hpp`
- [C++26 reflection path](https://github.com/aochenxiao/stream-punk/blob/main/include/stream-punk-reflection/StreamPunkReflection.hpp): optional API · Isolated alternative reflection capability. · `include/stream-punk-reflection/StreamPunkReflection.hpp`

### Metadata & Generation

- [Metadata extractor](https://github.com/aochenxiao/stream-punk/blob/main/tools/sp-gen/meta-reader.hpp): project-specific extractor · Includes user model headers and writes binary metadata when types change. · `tools/sp-gen/meta-reader.hpp`
- [sp-gen](https://github.com/aochenxiao/stream-punk/blob/main/tools/sp-gen/main.cpp): code generator · Generates target types, SPOI builders, and selected executor registries. · `tools/sp-gen/main.cpp`
- [Language backends](https://github.com/aochenxiao/stream-punk/blob/main/tools/sp-gen/generators.hpp): generator backends · TypeScript, Python, Java, Go, Rust, and Kotlin outputs. · `tools/sp-gen/generators.hpp`
- **Generated bindings**: consumer source · Generated types and SPOI APIs require their matching runtime.

### Cross-language Runtimes

- [Language runtimes](https://github.com/aochenxiao/stream-punk/blob/main/runtimes/py/stream-punk.py): compatible binary/SPOI runtime · Distributed source integrated into consuming applications. · `runtimes/py/stream-punk.py`

### SPOI Pipeline

- [SPOI builders & Shadow](https://github.com/aochenxiao/stream-punk/blob/main/include/stream-punk/StreamPunkSPOIShadow.hpp): instruction producer · Builders and mutation proxies encode query/update deltas. · `include/stream-punk/StreamPunkSPOIShadow.hpp`
- [SPOI instruction bytes](https://github.com/aochenxiao/stream-punk/blob/main/include/stream-punk/StreamPunkSPOI.hpp): transport-neutral protocol · Query and update bytes can cross runtime and transport boundaries. · `include/stream-punk/StreamPunkSPOI.hpp`
- [SPOI executor](https://github.com/aochenxiao/stream-punk/blob/main/include/stream-punk/StreamPunkSPOIExecutor.hpp): in-memory execution · Runs queries and updates against local collections. · `include/stream-punk/StreamPunkSPOIExecutor.hpp`

### Examples

- [Realtime examples](https://github.com/aochenxiao/stream-punk/blob/main/examples/13-whiteboard/server/main.cpp): C++ server / browser clients · WebSocket-oriented collaborative game, whiteboard, and editor references. · `examples/13-whiteboard/server/main.cpp`

### Other components

- [CMake build](https://github.com/aochenxiao/stream-punk/blob/main/CMakeLists.txt): build entry · `CMakeLists.txt`
- **Application transport & storage**: application responsibility · Applications provide transport, authorization, conflict handling, and durability.

## Connections

- CMake build → Primary C++ API: builds
- Primary C++ API → Application models: defines
- Application models → Type descriptors: registers
- Type descriptors → Schema support: supplies
- Type descriptors → Binary object codec: drives
- Application models → JSON conversion: converts
- Application models → ORM SQL generation: derives SQL from
- Application models → Metadata extractor: included by
- Metadata extractor → sp-gen: binary metadata
- sp-gen → Language backends: selects
- Language backends → Generated bindings: emits
- Generated bindings → Language runtimes: uses
- Binary object codec → Language runtimes: compatible format
- Application models → SPOI builders & Shadow: targets
- SPOI builders & Shadow → SPOI instruction bytes: encodes
- SPOI instruction bytes → Application transport & storage: transported or appended by
- Application transport & storage → SPOI executor: delivers to
- SPOI instruction bytes → SPOI executor: applies or queries
- Language runtimes → SPOI executor: implements compatible execution
- Realtime examples → Application transport & storage: demonstrate
- C++26 reflection path → Type descriptors: alternative path
