Expand description
§xmachines-docs
The guides of xmachines-rs, the Rust implementation of XMachines: a runtime that executes XState v6 machine definitions natively, with guards, actions, delays and computed values written in Rust, and runs them in-process, as WebAssembly components, in Node.js and next to a Kafka broker. This crate holds no code; it is the book, and its examples compile and run against the crates they describe.
This is an independent project, not an official Stately package. It targets xstate@6.0.0-beta.6.
§The guides
Start with getting_started; the others build on it, and each stands on its own after that.
| Guide | What it covers |
|---|---|
getting_started | A machine (MachineJSON) on xmachines-runtime: load, start, send, time, snapshots, persist and restore, implementations |
typed_machines | Codegen from a bundle in build.rs, the generated types and trait, and TypedMachine |
evaluators | Code nodes and their languages: Rust expressions, Evaluator, HostEvaluator, and JavaScript on QuickJS |
codecs | The codec traits, JSON, MessagePack, protobuf and Avro, and a codec of your own |
wasi | The two WIT packages and their JSON Schemas, the generic and the typed components, and their hosts |
node | The Node.js addons, the NodeRuntime contract, Bun and Deno |
kafka | The Kafka service: the engine, its configuration, its codecs and the local deploy stack |
contracts | Every contract between the parts, where it lives, and how it is versioned and checked |
§The crates
| Crate | What it is |
|---|---|
xmachines-runtime | The runtime: loading and validating MachineJSON, the statechart algorithm, the actor system (XState’s pure system API), persistence |
xmachines-build | Typed Rust modules from machine bundles at build time: context, events, params and the implementation trait |
xmachines-eval-quickjs | An evaluator for JavaScript code nodes on an embedded QuickJS (opt-in) |
xmachines-machine | The contract of a typed machine (TypedMachine) and the JSON actor API its WASI components and Node addons share |
xmachines-codec | Pluggable codecs of events and snapshots, registered by name, with JSON built in |
xmachines-codec-msgpack | MessagePack events and snapshots |
xmachines-codec-protobuf | Protocol Buffers events and snapshots, with .proto files generated from machine bundles |
xmachines-codec-avro | Avro events and snapshots in the Schema Registry wire format, with schemas generated from machine bundles |
xmachines-runtime-wasi | A WASI 0.2 component that runs any machine definition, with its guards and actions from the host, and export_runtime! to export it from another component |
xmachines-machine-wasi | Typed WASI components for one machine each, with its implementations in Rust inside the component |
xmachines-wasi-host | A library for Wasmtime hosts of both WASI components: bindings, host implementations, actors |
xmachines-runtime-node | A Node.js native addon (napi-rs) with the WASI component’s actor API, and its library for addons of one’s own |
xmachines-machine-node | Typed Node.js addons for one machine each, with its implementations in Rust inside the addon |
xmachines-kafka | A partition-sharded service next to any Kafka-API broker, with exactly-once state |
The JavaScript and TypeScript implementation of XMachines is xmachines-js; its @xmachines/run package runs machines on xmachines-runtime-node and on xmachines-runtime-wasi as two of its engines.
§Where else to read
- The repository’s
docs/ARCHITECTURE.md: how the runtime, the authoring pipeline, the deployment targets and the testing fit together. - The repository’s
AGENTS.md: every design decision, the verified XState v6 semantics, the measurements and the roadmap.
§License
MIT
Modules§
- codecs
- Turn events and snapshots into bytes and back: the codec traits of
xmachines-codec, the four codecs, a codec of your own, and how the Kafka service chooses them. - contracts
- Every contract between the parts of xmachines-rs, and between it and other implementations: what each one is, where it lives, and how it is versioned and checked.
- evaluators
- Compute values inside a machine with code nodes: Rust expressions, an evaluator of your own for any language, an evaluator in another runtime, and JavaScript on an embedded QuickJS.
- getting_
started - Run a machine natively on
xmachines-runtime: load its definition, register what it references, start an actor, send it events, drive its time, and persist and restore it. - kafka
- Run many actors of one machine next to a Kafka-API broker with
xmachines-kafka: the topics, the deterministic engine, the service and its configuration, codecs, external work, and the local deploy stack. - node
- Run machines natively from JavaScript: the generic Node.js addon and its
NodeRuntimecontract, typed addons of one machine each, and the same addons in Bun and Deno. - typed_
machines - Author a machine in TypeScript, generate Rust types and an implementation trait from it at build time with
xmachines-build, and make it aTypedMachinethat any guest can export. - wasi
- Run machines as WebAssembly components: the two WIT packages and their JSON Schemas, the generic component, typed components of one machine each, and hosting them from Rust and from JavaScript.