Skip to content
XMachines architecture showing state machines connected by event streams

XMachines

Stream-native execution for event-sourced applications

Building stateful applications is hard. State management often becomes a black box—difficult to debug, impossible to replay, and challenging to distribute across systems. Traditional approaches lack auditability, determinism, and durability guarantees that modern distributed systems demand.

XMachines brings deterministic, durable, and distributed state management through a unique combination of technologies:

Deterministic Execution

Same events always produce the same state. No hidden side effects, no surprises. Perfect for testing, debugging, and time-travel capabilities.

Git-Backed Durability

Events are stored as Git objects in an append-only log. Your state history is version-controlled, replicable, and distributed using standard Git protocols.

Stream Architecture

Built on Web Streams API. All I/O flows through in, out, err, and snapshot streams with proper backpressure and cancellation support.

Universal Frontend

Build universal frontend apps with strict separation between business logic, runtime adapters, and views. Same code runs in browser, Node, or edge functions.

Protocol Projections

Expose your machines via REST APIs, MCP tools for AI agents, or custom protocols. One state machine, multiple interfaces.

Here’s a simple counter machine with XMachines:

import { createRun } from '@xmachines/core';
// Create a run (instance) from your machine definition
const run = createRun(counterMachine);
// Get a writer to apply events
const writer = run.in.getWriter();
// Apply events - the sole way to mutate state
await writer.write({ type: 'START' });
await writer.write({ type: 'INCREMENT', value: 5 });
await writer.write({ type: 'INCREMENT', value: 3 });
// Read the current state snapshot
const reader = run.snapshot.getReader();
const { value: snapshot } = await reader.read();
console.log(snapshot); // { count: 8, status: 'running' }

Every time you replay these events, you get the exact same state. The event history is stored durably in Git-compatible format.

Event-Sourced Applications
Build systems where every state change is captured as an event. Replay history, audit changes, and implement time-travel debugging.

Stateful REST APIs
Expose state machines as REST endpoints with automatic event streaming, snapshots, and PATCH-based mutations.

AI Agent Support
Connect your state machines to AI agents via the Model Context Protocol (MCP). Machines become tools that agents can invoke.

Universal Frontend with Play
Build universal frontend apps with Play—strict separation between business logic and runtime adapters. Same code runs in browser, Node, or edge functions.

Ready to dive in? Start with our guides: