# Sypnorm

> The use-case ORM that comes with Cases. Your code is a set of use cases, and the map comes from it.

Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service).  
Source: https://cases.docs.sypnia.com/sypnorm/

For agents: Sypnorm is part of Sypnia Cases (decided by the owner, 2026-11-17): a TypeScript ORM where an app is a set of use cases (actor, input, preconditions, tables touched, run(ctx) ending in ctx.outcome; outcomes and failures typed from the case file by `cases generate`). Package @sypnia/cases: /sypnorm (useCase, ctx.db, ctx.outcome, typed tables, runners, transactions), /map (derive the map from code, upload it), CLI `npx @sypnia/cases generate|tables|map|link|check`. Runs on Sypnia Data (Data API runner, atomic transactions over HTTP, for cases nobody listens to) and on any Postgres (direct runner, which each area's service uses; a case some case listens to runs there, at POST /_cases/<id>, and its outbox row commits with its data). The map Sypnorm derives is the code side of the Cases map. Optional: Cases works without it; Sypnia Data works with any ORM.

Most ORMs organize code around tables. **Sypnorm** organizes it around what people do: **use cases**. «A customer orders today's bread» is one use case: it says who does it, what it receives, which tables it reads and writes, and every way it can fail. Your app is the set of its use cases, and Sypnorm derives that set as **the code side of your map**.

That is why Sypnorm belongs to Cases. A Cases map written by people says what the app must do; Sypnorm says, from the code itself, what the app does. [The check](https://cases.docs.sypnia.com/contract/the-check) compares the two.

- [Use cases](/sypnorm/use-cases/): How to write a use case with Sypnorm, what each part means, and how failures work.
- [Tables, queries and types](/sypnorm/tables-and-queries/): Generate typed tables from your database, and read and write with Sypnorm's query builder.
- [Runners and transactions](/sypnorm/runners/): Run use cases on Sypnia Data through its API, or on any Postgres with a direct connection, all or nothing.
- [The map from your code](/sypnorm/the-map/): Derive the map from your use cases, upload it to your Cases project, and keep code and map in agreement.

## One package

```bash
npm install @sypnia/cases
```

| Import                  | For                                                                                                        |
| ----------------------- | ---------------------------------------------------------------------------------------------------------- |
| `@sypnia/cases/sypnorm` | the ORM: `useCase`, `ctx.db`, `ctx.outcome`, typed tables, runners and transactions                        |
| `@sypnia/cases/map`     | derive the map from your code and upload it, from your own scripts                                         |
| `@sypnia/cases/spec`    | the format: types, JSON Schemas, parser and validator ([The SDK](https://cases.docs.sypnia.com/tools/sdk)) |
| `@sypnia/cases/client`  | the Cases API ([The SDK](https://cases.docs.sypnia.com/tools/sdk))                                         |

The command comes with it: `npx @sypnia/cases generate`, `tables`, `map`, `link`, `check` and the rest of [the CLI](https://cases.docs.sypnia.com/tools/cli).

## Where it runs

| Database             | Runner                                                                                                                                                       | Transactions                                                                                          |
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------- |
| **Sypnia Data**      | through the Data API, with the person's token, under row-level security, for cases nobody listens to; a case some case listens to runs in its area's service | atomic over HTTP, one request per use case ([Runners](https://cases.docs.sypnia.com/sypnorm/runners)) |
| **Any Postgres 14+** | a direct connection from your server                                                                                                                         | real Postgres transactions, with row locks                                                            |

Sypnorm does not need Sypnia Data, and Sypnia Data does not need Sypnorm: Data works with plain SQL, Prisma, Drizzle or any other tool.

## Why use cases

- **Anyone can read the app.** A use case reads like the sentence a client would say.
- **Scope is visible.** The map lists everything the app does; a flow that is not on it is a [scope error](https://cases.docs.sypnia.com/contract/scope-errors).
- **Every ending is part of the design.** Outcomes and failures are named and typed in the case file, and `ctx.outcome` accepts nothing else, so nothing is found by surprise in production.
- **Production by use case.** With Sypnia Telemetry, each run is a span named after its use case, with its outcome; when another case listens, the area's service saves the outcome in the outbox in the same transaction ([Running cases](https://cases.docs.sypnia.com/runtime)).
