xmachines-docs 2.0.0

The guides of xmachines-rs: XState v6 machines in Rust, as WebAssembly components, as Node.js addons and next to Kafka
Documentation

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