Skip to main content

Crate xmachines_docs

Crate xmachines_docs 

Source
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.

GuideWhat it covers
getting_startedA machine (MachineJSON) on xmachines-runtime: load, start, send, time, snapshots, persist and restore, implementations
typed_machinesCodegen from a bundle in build.rs, the generated types and trait, and TypedMachine
evaluatorsCode nodes and their languages: Rust expressions, Evaluator, HostEvaluator, and JavaScript on QuickJS
codecsThe codec traits, JSON, MessagePack, protobuf and Avro, and a codec of your own
wasiThe two WIT packages and their JSON Schemas, the generic and the typed components, and their hosts
nodeThe Node.js addons, the NodeRuntime contract, Bun and Deno
kafkaThe Kafka service: the engine, its configuration, its codecs and the local deploy stack
contractsEvery contract between the parts, where it lives, and how it is versioned and checked

§The crates

CrateWhat it is
xmachines-runtimeThe runtime: loading and validating MachineJSON, the statechart algorithm, the actor system (XState’s pure system API), persistence
xmachines-buildTyped Rust modules from machine bundles at build time: context, events, params and the implementation trait
xmachines-eval-quickjsAn evaluator for JavaScript code nodes on an embedded QuickJS (opt-in)
xmachines-machineThe contract of a typed machine (TypedMachine) and the JSON actor API its WASI components and Node addons share
xmachines-codecPluggable codecs of events and snapshots, registered by name, with JSON built in
xmachines-codec-msgpackMessagePack events and snapshots
xmachines-codec-protobufProtocol Buffers events and snapshots, with .proto files generated from machine bundles
xmachines-codec-avroAvro events and snapshots in the Schema Registry wire format, with schemas generated from machine bundles
xmachines-runtime-wasiA 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-wasiTyped WASI components for one machine each, with its implementations in Rust inside the component
xmachines-wasi-hostA library for Wasmtime hosts of both WASI components: bindings, host implementations, actors
xmachines-runtime-nodeA Node.js native addon (napi-rs) with the WASI component’s actor API, and its library for addons of one’s own
xmachines-machine-nodeTyped Node.js addons for one machine each, with its implementations in Rust inside the addon
xmachines-kafkaA 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 NodeRuntime contract, 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 a TypedMachine that 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.