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 [
inventory] system
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.