> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stateset.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Scenarios & Examples

> Runnable examples in the repository, and the four patterns teams usually start from.

# Scenarios & Examples

The repository ships runnable examples. This page maps them to the patterns teams actually build.

## Runnable examples

The Node set is the most complete and numbered in a deliberate order:

| Example                           | Covers                       |
| --------------------------------- | ---------------------------- |
| `01_getting_started.js`           | Engine setup, first entities |
| `02_cart_and_checkout.js`         | Cart → order                 |
| `03_analytics_and_forecasting.js` | Reporting                    |
| `04_subscriptions.js`             | Plans and recurring billing  |
| `05_promotions.js`                | Discounts and campaigns      |
| `06_currency.js`                  | Multi-currency conversion    |
| `07_tax.js`                       | Tax calculation              |
| `08_manufacturing.js`             | BOMs and work orders         |
| `09_full_workflow.js`             | End to end                   |
| `10_payments_and_fulfillment.js`  | Payment through shipment     |
| `11_b2b_operations.js`            | Wholesale flows              |

```bash theme={null}
cd examples/node
npm install
node 01_getting_started.js
```

<Tip>
  Work `01` → `09` in order. Each builds on the previous one's concepts, and `09_full_workflow.js` is
  the one to read if you only read one.
</Tip>

**Rust:** `basic_usage.rs`, `error_handling.rs`, `events_webhooks.rs`, `validation.rs`.

**Other languages:** `python/`, `go/`, `java/`, `kotlin/`, `swift/`, `ruby/`, `dotnet/`.

**Beyond the basics:** `agents/`, `autonomous-agents/`, `multi-agent/`, `daemon/`, `gateway/`,
`plugins/`, `plugin-development/`, `x402/`.

## Pattern 1 — AI customer support agent

An agent that resolves tickets rather than drafting replies.

**Shape:** give the agent the [MCP server](/stateset-icommerce/stateset-icommerce-mcp) scoped to the
domains it needs, look up the order, apply policy, act.

```js theme={null}
const order  = await commerce.orders.get(orderId);
const rmas   = await commerce.returns.listForOrder(orderId);
// decide, then act — refund, reship, or escalate
```

**Watch for:** scope the agent's tools to the domains it needs. The MCP surface has 287 write and
21 delete tools; a support agent needs a fraction of that. Route consequential actions through the
[decision gate](/next-temporal/policy-engine).

**Start from:** `examples/agents/`, plus
[CLI safety](/stateset-icommerce/stateset-icommerce-cli-safety).

## Pattern 2 — offline POS with sync

Run locally on SQLite, reconcile through VES when connectivity returns.

**Shape:** the engine is in-process, so the till keeps selling with no network. Queued events flush
to the [sequencer](/stateset-sequencer/stateset-sequencer) on reconnect.

```bash theme={null}
stateset sync status
stateset sync push
```

**Watch for:** inventory reserved offline can oversell against another node's sales. Decide up
front whether a till holds authoritative stock or optimistically reserves and reconciles.

## Pattern 3 — subscription billing and invoicing

**Shape:** plans, subscriptions, renewals, and invoices, with revenue recognised through the
[finance layer](/stateset-icommerce/stateset-icommerce-finance).

**Watch for:** recognition is where subscriptions get subtle — ASC 606 obligations and ratable
schedules, not just a monthly charge. Two correctness fixes landed here recently; check the
[warning on revenue schedules](/stateset-icommerce/stateset-icommerce-finance#revenue-recognition)
if you reconciled against earlier output.

**Start from:** `examples/node/04_subscriptions.js`.

## Pattern 4 — manufacturing and procurement

**Shape:** BOMs → work orders → purchase orders, with a full audit trail across inventory and
purchasing.

**Watch for:** the purchase-order state machine enforces legal transitions, so an illegal one
returns a validation error rather than applying. Received or cancelled documents cannot be
cancelled again.

**Start from:** `examples/node/08_manufacturing.js`.

## Related

* [The Embedded Engine](/stateset-icommerce/stateset-icommerce-embedded)
* [Order Lifecycle](/stateset-icommerce/stateset-icommerce-order-lifecycle)
* [CLI Workflows](/stateset-icommerce/stateset-icommerce-cli-workflows)
