Skip to main content

Crate myko

Crate myko 

Source
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

ConceptDescription
ItemBase entity with typed id
EventImmutable record of state change: SET (create/update) or DEL (delete)
QueryRequest for live data stream, returns reactive Observable<T[]>
ReportComputed/derived data request, returns Observable<T>
CommandIntent to mutate state, returns result of operation
SagaStateful 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, GetTargetsByQuery queries
  • CountAllTargets, CountTargets, GetTargetById reports
  • DeleteTarget, DeleteTargets commands
  • PartialTarget struct for partial matching
  • Registration with the inventory system

§Module Guide

ModulePurpose
clientWebSocket client for connecting to Myko servers
coreCore types: command, query, report, saga, item, relationship
wireWire protocol types: MykoMessage, MEvent, responses, errors
serverCellServer and server context
storeEntity 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.

Derive Macros§

TS
Derives TS for a struct or enum. Please take a look at TS for documentation.