# State machine

> Allowed status transitions as the caller, a history row and a status.changed event. A machine can also write a stages timeline and keep a lifecycle row (pause, flags, pinned version). Each machine is a subject table named in options.machines, or a config.recordTypes type.

- Category: Work management
- Module: `state-machine`
- Modes: `managed`, `custom`
- Docs: https://bettersupabase.com/docs/blocks/state-machine
- Page: https://bettersupabase.com/blocks/state-machine

## Install

```bash
npx better-supabase add state-machine
```

The command also installs `updated-at`, `memberships`, `permissions`.

## Configure

Add the block to `better-supabase.config.ts`:

```ts
import { defineConfig } from "better-supabase/config";

export default defineConfig({
  blocks: {
    // Required by state-machine; add installs them too.
    "updated-at": {},
    memberships: {},
    permissions: {},
    // Modes: "managed", "custom". The default is "managed".
    "state-machine": { mode: "managed" },
  },
});
```

## Client

The block has no React entry yet. Its server-side TypeScript is in `better-supabase/blocks/state-machine`.

## Related blocks

Requires: [memberships](https://bettersupabase.com/blocks/memberships.md), [permissions](https://bettersupabase.com/blocks/permissions.md)

Works with: [outbox](https://bettersupabase.com/blocks/outbox.md), [audit](https://bettersupabase.com/blocks/audit.md), [approvals](https://bettersupabase.com/blocks/approvals.md), [workflow-editor](https://bettersupabase.com/blocks/workflow-editor.md), [bulk-actions](https://bettersupabase.com/blocks/bulk-actions.md)

## Recipes

- [Work item board](https://bettersupabase.com/recipes/work-item-board.md): Work items in state columns, ordered by rank and moved through allowed transitions.
