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
- 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.
Traits§
- TS
- A type which can be represented in TypeScript.
Most of the time, you’d want to derive this trait instead of implementing it manually.
ts-rs comes with implementations for all primitives, most collections, tuples, arrays and containers.