Expand description
§Myko RS - Event-Sourcing CQRS Framework
myko is an actor-based event-sourcing framework for building real-time,
distributed systems with strong consistency guarantees.
§Core Concepts
| Concept | Description |
|---|---|
| Item | Base entity with typed id |
| Event | Immutable record of state change: SET (create/update) or DEL (delete) |
| Query | Request for live data stream, returns reactive Observable<T[]> |
| Report | Computed/derived data request, returns Observable<T> |
| Command | Intent to mutate state, returns result of operation |
| Saga | Stateful stream processor that reacts to events and emits commands |
§Architecture
┌──────────────────────────────────────────────────────────────────────────┐
│ CellServer │
│ │
│ WebSocket ──► WsHandler ──► CellServerCtx ──► StoreRegistry │
│ │ │ │ │ │
│ │ │ │ CellMap<id, item> │
│ │ ▼ │ │ │
│ │ Persister │ ▼ │
│ │ │ │ Query/Report cells │
│ │ ▼ │ │ │
│ │ Durable Backend ◄────────── Consumer │
│ │ │
│ ◄────────────────────── (subscription updates) │
└──────────────────────────────────────────────────────────────────────────┘§Quick Start
Define an entity using the #[myko_item] attribute macro:
use myko::prelude::*;
#[myko_item]
pub struct Target {
pub name: String,
pub category: Option<String>,
// id is added automatically
}The macro auto-generates:
GetAllTargets,GetTargetsByIds,GetTargetsByQueryqueriesCountAllTargets,CountTargets,GetTargetByIdreportsDeleteTarget,DeleteTargetscommandsPartialTargetstruct for partial matching- Registration with the
inventorysystem
§Module Guide
| Module | Purpose |
|---|---|
client | WebSocket client for connecting to Myko servers |
core | Core types: command, query, report, saga, item, relationship |
wire | Wire protocol types: MykoMessage, MEvent, responses, errors |
server | CellServer and server context |
store | Entity store and registry |
§Performance
Myko-rs is optimized for high-throughput, low-latency scenarios:
- Hyphae cells: Reactive queries and reports using the hyphae cell library
- Lock-free stores: CellMap for concurrent entity access
- MessagePack serialization: Binary format for efficient WebSocket communication
- Pluggable persistence: Run in-memory for development, add Postgres for production persistence
See libs/myko/rs/OPTIMIZATION.md for detailed performance guidelines.
Re-exports§
pub use core::saga;pub use core::command;pub use core::common;pub use core::item;pub use core::query;pub use core::relationship;pub use core::report;pub use core::request;pub use core::view;pub use wire::event;pub use erased_serde;pub use futures;pub use hyphae;pub use inventory;pub use partially;pub use serde;pub use serde_json;pub use ts_rs;
Modules§
- cache
- client
- codegen_
types - Registration types for TypeScript codegen macros.
- core
- Core types and traits for Myko.
- entities
- prelude
- Prelude module - commonly used types for convenience imports.
- search
- Full-text search infrastructure for Myko entities.
- server
- Server-side types for the cell-based Myko server.
- store
- Store module - Reactive entity storage using hyphae cells
- utils
- wire
- Wire protocol types for WebSocket communication.
Macros§
- register_
command_ handler - Macro to register a command handler with the inventory.
- register_
ts_ export - Register a type for ts-rs export.
- submit
- Enter an element into the plugin registry corresponding to its type.
- submit_
message_ event - Helper macro for submitting message event registrations
- ts_
const - Define a Rust constant and register it for TypeScript export.
Constants§
- WS_
MAX_ FRAME_ SIZE_ BYTES - WS_
MAX_ MESSAGE_ SIZE_ BYTES - Shared websocket sizing used by Myko client/server on native platforms.
Attribute Macros§
- myko_
command - Generates a command with handler struct and registration.
- myko_
item - Marks a struct as a Myko entity, generating queries, reports, commands, and supporting types.
- myko_
manual_ cache_ key - myko_
non_ hash_ cache_ key - myko_
query - myko_
report - Generates a reactive report that can depend on queries and other reports.
- myko_
report_ output - Adds standard derives and registers for TypeScript export.
- myko_
saga - Generates a saga with registration for runtime discovery.
- myko_
subtype - Declare a data subtype used by myko entities (field types, payloads,
enum variants carried on commands/queries/reports/views). Bundles the
standard derives + serde camelCase rename + conditional TS export +
register_ts_export!so subtype definitions don’t repeat 3–4 lines of boilerplate each. - myko_
view - Defines a reactive view query.
- myko_
view_ item - Marks a struct as a typed view item (id/hash should already be present).
Derive Macros§
- Message
Events - Derive macro that extracts serde rename values from enum variants and generates MessageEventRegistration inventory submissions.
- Partial
Matches - TS
- Noop replacement for
ts_rs::TSderive — emits no trait impls and declares thetshelper attribute so user-written#[ts(...)]in entity source doesn’t error out whents_rs::TSis absent. - TsNoop
- Noop replacement for
ts_rs::TSderive — emits no trait impls and declares thetshelper attribute so user-written#[ts(...)]in entity source doesn’t error out whents_rs::TSis absent.