How aochenxiao/stream-punk works
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: MetaData.hpp Type descriptors · StreamPunkSPOI.hpp SPOI instruction bytes · stream-punk.py Language runtimes · StreamPunkSPOIExecutor.hpp SPOI executor
Components 19
C++ Framework
- Primary C++ API
include/stream-punk/StreamPunk.hpp - Application models · Models must follow StreamPunk inheritance and macro conventions.
- Type descriptors · Registers member names, type tokens, construction, and serialization.
include/stream-punk/MetaData.hpp - Schema support
include/stream-punk/StreamPunkSchema.hpp - Binary object codec · Identity-aware binary interchange and persistence format.
include/stream-punk/StreamPunk.hpp - JSON conversion
include/stream-punk/StreamPunkJson.hpp - ORM SQL generation · Emits MySQL/SQLite-style SQL metadata; not a database runtime.
include/stream-punk/StreamPunkOrmGen.hpp - C++26 reflection path · Isolated alternative reflection capability.
include/stream-punk-reflection/StreamPunkReflection.hpp
Metadata & Generation
- Metadata extractor · Includes user model headers and writes binary metadata when types change.
tools/sp-gen/meta-reader.hpp - sp-gen · Generates target types, SPOI builders, and selected executor registries.
tools/sp-gen/main.cpp - Language backends · TypeScript, Python, Java, Go, Rust, and Kotlin outputs.
tools/sp-gen/generators.hpp - Generated bindings · Generated types and SPOI APIs require their matching runtime.
Cross-language Runtimes
- Language runtimes · Distributed source integrated into consuming applications.
runtimes/py/stream-punk.py
SPOI Pipeline
- SPOI builders & Shadow · Builders and mutation proxies encode query/update deltas.
include/stream-punk/StreamPunkSPOIShadow.hpp - SPOI instruction bytes · Query and update bytes can cross runtime and transport boundaries.
include/stream-punk/StreamPunkSPOI.hpp - SPOI executor · Runs queries and updates against local collections.
include/stream-punk/StreamPunkSPOIExecutor.hpp
Examples
- Realtime examples · WebSocket-oriented collaborative game, whiteboard, and editor references.
examples/13-whiteboard/server/main.cpp
Other components
- CMake build
CMakeLists.txt - Application transport & storage · Applications provide transport, authorization, conflict handling, and durability.
Connections 21
- 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