# Durable SDK

This page says what Durable is and which of two paths to take next.
The commands it names are `npx durable-sdk init`, `durable-sdk deploy`
and `durable-sdk doctor --host`.

## What it is

Durable is a TypeScript framework for apps that already have a Postgres
database and a cron. A workflow is a keyed saga: one run per
intent, every side effect a step that reads before it writes, undoes
itself or says why it cannot, and leaves a before/after image in an
append-only, hash-chained [ledger](https://durablesdk.com/docs/concepts/ledger-and-data.md). It
runs inside an ordinary serverless function, needs no worker, broker or
control plane, holds a failed run for a person instead of retrying it in
the dark, and refuses to store a secret.

```ts
import { defineWorkflow } from "@durable-sdk/core";

// stock, payments and orders are the app's clients, one seam: the app
// binds them at boot, a test binds doubles.
export const checkoutComplete = defineWorkflow({
  name: "checkout.complete",
  version: 1,
  describe: "Reserves, charges and creates the order once per checkout.",
  key: ["checkoutId", "requestId"],
  example: { checkoutId: "chk_4f21", requestId: "q7c1" },
  async run(ctx) {
    const { checkoutId: id, requestId } = ctx.input;
    await ctx.step("stock.reserve", () => stock.reserve(id), {
      undo: (_, out) => stock.release(out.reservationId),
      effect: "provider",
    });
    const paid = await ctx.step("payment.capture", () => payments.capture(id), {
      undo: (_, out) => payments.refund(out.paymentId),
      effect: "provider",
    });
    const order = await ctx.step("order.create", () => orders.create(paid), {
      undo: (_, out) => orders.cancel(out.orderId),
      effect: "ledgered",
    });
    await ctx.emit("order.placed", { ...order, checkoutId: id, requestId });
    return { orderId: order.orderId };
  },
});
```

The key never reads the clock: the moment rides in the input as
`requestId`. The same checkout through ten callers is one run; the
eleventh caller gets the first run's result. Each step names its effect
and carries an undo over the same seam, so the order's failure refunds
the capture and releases the stock, in that order, and the card is
charged once; a step that cannot undo says `irreversible: "<why>"`
instead. The template's `src/workflows/hello.ts` is the same shape with
one step.
[Concepts](https://durablesdk.com/docs/concepts.md) has the model in one page.

## The four things you can check

Each of these is in your database or in your tree, not in a dashboard
you have to trust.

| What                                                       | Where to look                                                                          |
| ---------------------------------------------------------- | -------------------------------------------------------------------------------------- |
| **The ledger**: every write's before and after image       | the `ledger` table, hash-chained per scope; `verify` walks it from genesis             |
| **The undo**: what a compensation found and restored       | `<step>.undo` rows beside the step; a step that cannot undo says `irreversible: "why"` |
| **The doctor**: the rules your tree keeps                  | `durable-sdk doctor --host`, one line per failed rule with its fix                     |
| **The legibility**: every refusal a sentence with a remedy | `durable-sdk explain <code>`, offline; the same table the API and the dashboard print  |

[The doctor](https://durablesdk.com/docs/guide/the-doctor.md) says what the rules are;
[Errors](https://durablesdk.com/docs/reference/api/errors.md) lists every code the platform can
answer.

## The path

Sign up at [durablesdk.com](https://durablesdk.com), run
four commands, and your app answers at `<app>.durablesdk.com` with its
own database, its console and a read string. Start with the
[Quickstart](https://durablesdk.com/docs/quickstart.md); [Hosting](https://durablesdk.com/docs/hosting.md) says what runs
for you.

The packages are the ones your app imports;
[Compatibility](https://durablesdk.com/docs/reference/compatibility.md) says what the product
promises to keep across their versions. Before you start, see it drawn:
[How it works](https://durablesdk.com/docs/why/how-it-works.md) has the model in seven pictures.

## Where to go next

- [Quickstart](https://durablesdk.com/docs/quickstart.md): ten minutes to a run you can see.
- [Concepts](https://durablesdk.com/docs/concepts.md): runs, keys, steps, facts, the ledger, limbo.
- [Vibe coding with the graph](https://durablesdk.com/docs/guide/vibe-coding-with-the-graph.md) and
  [The graph, drawn](https://durablesdk.com/docs/guide/the-graph-drawn.md): ask the graph before an
  edit, and see the walk.
- [CLI reference](https://durablesdk.com/docs/reference/cli.md) and [API reference](https://durablesdk.com/docs/reference/api.md).
- For an agent: [MCP and agents](https://durablesdk.com/docs/reference/mcp-and-agents.md),
  [`/llms.txt`](https://durablesdk.com/llms.txt), and every docs page as
  Markdown at `/docs/<slug>.md`.

---

Prompt for an agent:

```text
Read https://durablesdk.com/docs/index.md, then apply what it says to this app; run durable-sdk doctor --host before and after; a refused line is a refusal id: durable-sdk explain <id>
```
