# Sypnia Cases documentation > Sypnia Cases is the map of everything your app does, written as use cases that anyone can read: who does what, what can go wrong, what data it touches. The map is the contract of the project: what is not on it is a scope error. Your code, your data, your traces and your coding agent all point back to it. Every page of the documentation follows, in reading order. Each one starts with its title and its address. --- ## Start here > What Sypnia Cases is, how it works, what is open source and what is Sypnia Cloud, and the quickstarts. Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service). Source: https://cases.docs.sypnia.com/start/ For agents: Section index for Sypnia Cases: the use-case map of an app as a product. An open file format (case files and a map file in the repository), a CLI and a server that are open source, and a Sypnia Cloud service with a visual editor, proposals and reviews, and live links to Data, Telemetry, Git and Agent. Read what-it-is, how-it-works, open-source-and-cloud, then a quickstart. Sypnia Cases keeps **the map of everything your app does**, written as use cases: who does what, where in the app, how it starts, how it ends, what can go wrong, what data it touches. A person who does not program understands the app by reading it; a programmer and a coding agent build from it; and the runtime runs it, so the map stays true. Why it works this way, and whose ideas it builds on: [The Living Cases Manifesto](https://cases.sypnia.com/manifest/), and [Where these ideas come from](https://cases.docs.sypnia.com/start/where-ideas-come-from). > **Note: Sypnia uses it too** > > Sypnia is built with Sypnia Cases: every product of the suite has its own map, and each promise on its page points to a case on it. Sypnia Telemetry is the pilot: it uses every other Sypnia product, and every one of their cases reports to it. Sypnorm, the use-case ORM that derives the map from code, comes with Cases in `@sypnia/cases`. There are two ways to use it, and every page says which one it is about: - **\[Engine]** **The open format and tools**: the map as files in your repository, the `cases` command that checks it, and a server you can run yourself. - **\[Cloud]** **Sypnia Cloud**: the same format, plus the visual editor, proposals and reviews with your team and your client, and live links to Data, Telemetry, Git and Agent. --- ## What Sypnia Cases is > The use-case map of your app as a product, who it is for, and what it is not. Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service). Source: https://cases.docs.sypnia.com/start/what-it-is/ For agents: Sypnia Cases: a map of every flow of an app as use cases (actor, goal, how it starts, where it lives, steps, outcomes and failures, data, permissions), plus the runtime that runs them (one service per area, outcomes as events through a transactional outbox, retries, dead letters, loop guard). Purposes: a shared language for non-programmers and programmers, the scope contract of a project (anything not on the map is a scope error), and the backbone that links code (Git), data (Data), production behaviour (Telemetry) and the coding agent (Agent) to each flow. Usable alone for planning without code. An app is a list of things people do with it: _order bread for today_, _book an appointment_, _pay this month's fee_. Each of those is a **use case**. Sypnia Cases keeps all of them in one **map**, written so that the owner of a bakery and the person who programs her app read the same thing. ### What you get | | What it does | Where to read more | | -------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | | **The map** | Every flow of your app as a use case: who does it, what they want, the steps, what can go wrong, what data it reads and writes, who is allowed | [The map](https://cases.docs.sypnia.com/map) | | **Where each case lives** | A tree of the app's places, one parent each, so the path to every case is known: «Shop › Order for tomorrow». It comes from the code and is confirmed by real clicks | [The navigation map](https://cases.docs.sypnia.com/map/navigation) | | **How each case starts and ends** | Four typed starts (in the app, from another app, on a schedule, on another case's outcome), and outcomes with names and types. Failures are outcomes too | [How a case starts](https://cases.docs.sypnia.com/map/starts), [Outcomes and events](https://cases.docs.sypnia.com/map/outcomes-and-events) | | **The runtime** | The cases of an area run as one service; outcomes reach every case that listens through an outbox saved with the data, with retries, dead letters and loops stopped | [Running cases](https://cases.docs.sypnia.com/runtime) | | **A visual editor** **\[Cloud]** | Areas as lanes, cases as cards, journeys as arrows, plus the navigation tree and the event graph. Drag, rename, write in plain words; the files follow | [The visual editor](https://cases.docs.sypnia.com/map/editor) | | **The scope contract** | The landing page, the plan and the map form one contract. Code that does something the map does not say is a **scope error**; the fix is to change the map first, on purpose | [Scope and contract](https://cases.docs.sypnia.com/contract) | | **Proposals and reviews** **\[Cloud]** | A change to the map is a proposal your team and your client approve, with comments on each case and a history of every version | [Versions, proposals and reviews](https://cases.docs.sypnia.com/contract/versions-and-reviews) | | **An open format** | Plain YAML files in your repository, with a JSON Schema. No lock-in: the map is yours, readable without Sypnia | [The format](https://cases.docs.sypnia.com/format) | | **The map from code** | With Sypnorm, the map is derived from the code that runs, and Cases shows where the code and the written map disagree | [The map from code](https://cases.docs.sypnia.com/format/from-code) | | **Connected products** | Each case shows the tables it touches (Data), its errors and latency in production (Telemetry), its code and pull requests (Git), and the agent's work on it (Agent) | [Connected products](https://cases.docs.sypnia.com/links) | ### Who it is for - **People who do not program** and want to understand, approve and change what their app does, in their own words. - **Programmers and teams** who want a scope everyone agrees on, and a review that starts from intent instead of from a diff. - **Coding agents**, which work better from a written use case than from a vague request: they read the case, build it, and say when the work goes beyond it. ### What it is not - **Not a framework you are locked into.** The runtime is ordinary code in your app and a small open-source program; the cases are files anyone can read. - **Not a project manager.** There are no sprints, estimates or boards. A use case says _what the app does_, not _when someone will do it_. - **Not a diagram tool.** The map is structured data with a visual view; it is not a canvas of free shapes. - **Not tied to Sypnia.** You can keep the map in any repository, read it with any YAML reader, and use Cases without any other Sypnia product. It is better with them. Why it works this way, and whose ideas it stands on: [Where these ideas come from](https://cases.docs.sypnia.com/start/where-ideas-come-from). --- ## How it works > From an idea to a use case, to code, to production, and back to the map. Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service). Source: https://cases.docs.sypnia.com/start/how-it-works/ For agents: Cases lifecycle: (1) write or generate use cases (visual editor, YAML files, or Sypnorm code via `map`) with their start, place and outcomes; (2) the map is versioned and approved (proposals); (3) `cases generate` writes each case's typed skeleton and people or the agent write the rules inside (useCase, ctx.db, ctx.outcome); commits carry `Case: `; (4) `cases check` compares code and map (scope errors, drift, orphans, loops, places); (5) the runtime runs each area as one service: starts become routes, endpoints, jobs and subscriptions, outcomes go to the caller, to listeners through the outbox, and always to Telemetry; (6) Telemetry measures each case and real clicks confirm the navigation map; (7) changes go back to the map as proposals. **Figure**: Sypnia Cases in the middle of a project. The map is plain files; the server, the editor and the links read and write the same files. 1. You, your team or your client write use cases, in the editor or as files. 2. The map is stored as files in your repository and, in Sypnia Cloud, in the Cases server. 3. Code is written per case from its generated skeleton; commits say which case they touch. 4. The check compares the code with the map on every change. 5. The runtime runs each area and sends outcomes on; Telemetry reports each case, so the map shows how each flow behaves. ### One flow, from the idea to production #### 1. Someone writes the use case The bakery owner writes, in the editor: _«A customer orders bread for tomorrow and picks it up in the morning.»_ Cases turns it into a case: an actor (customer), a goal, how it starts (in the app, at «Shop › Order for tomorrow»), how it ends (`OrderPlaced`) and the first failure she thinks of: _that bread is sold out_. A programmer or the coding agent fills in the details: the payload types, the data it reads and writes, who is allowed. #### 2. The map is approved The new case is a **proposal**. The owner and the programmer approve it; the map gets a new **version**. That version is now the scope: building it is in scope, building anything else is not. #### 3. The code is written per case `npx @sypnia/cases generate` writes the case's skeleton from the file: its typed input, its outcomes and failures, the tables it may touch. A person or the agent writes the rules inside, with [Sypnorm](https://cases.docs.sypnia.com/sypnorm): `ctx.db` to read and write, `ctx.outcome('OrderPlaced', …)` to end. Without Sypnorm, commits carry a trailer `Case: order-for-tomorrow`, and the check reads them. #### 4. The check keeps code and map together `cases check` runs in the terminal and in CI. It fails when the code does something no case says (a **scope error**), when a promised case is not built, when code and case disagree (**drift**), when a case has no way to start, and when events form a loop nobody said how to stop. #### 5. The runtime runs it Each area runs as one service. Its starts become real: routes for `in_app`, endpoints for `external`, jobs for `scheduled`, subscriptions for `event`. Each outcome goes back to whoever waits, to every case that listens (through an outbox saved with the data), and always to Telemetry ([Running cases](https://cases.docs.sypnia.com/runtime)). #### 6. Production reports per case In Sypnia Cloud, every case shows how often it runs, how it ends, its errors and its latency, from Sypnia Telemetry. Real clicks confirm the navigation map. An ending or a path the map does not describe shows up as a gap. #### 7. Changes go back to the map New ideas, bugs that reveal a missing failure, a client asking for more: each one starts as a proposal on the map, not as code. ### What lives where | Thing | Where it lives | Who can read it | | --------------------------------------- | ----------------------------------------------------------------------------------- | -------------------------------------------------------- | | The map | `cases/` in your repository (open format); in Sypnia Cloud also in the Cases server | anyone with the files; in Cloud, the workspace's members | | Proposals, comments, approvals | the Cases server | the workspace's members and invited reviewers | | Links to Data, Telemetry, Git, Agent | read live from those products, never copied | the same people who can read those products | | The outbox, deliveries and dead letters | the `sypnia_cases` schema of your app's own database | your app's team, in the map and in Telemetry | --- ## Where these ideas come from > The Living Cases Manifesto, the people whose work Sypnia Cases stands on, and what each idea became here. Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service). Source: https://cases.docs.sypnia.com/start/where-ideas-come-from/ For agents: Sypnia Cases puts the Living Cases Manifesto (https://cases.sypnia.com/manifest/, Spanish /es/manifest/ «Manifiesto de los Casos Vivos») to work. Nine principles: the use case is the source of truth; anyone can read it; every case has a place and a start; every case ends in a declared outcome; outcomes are events with a contract; a case is a unit of meaning, not of deployment; reliable by construction (outbox in the same transaction, a queue and dead letters per listener, idempotence, loops refused or cut); production tells the truth back (Telemetry, real clicks confirm the map); people and agents agree on the map. Sources: Jacobson (use cases, Use-Case 2.0), Cockburn (goal levels, hexagonal ports → typed starts), Buhr (Use Case Maps → tree of places + graph of outcomes), Martin (use cases at the center), Evans and Vernon (ubiquitous language, bounded contexts → areas, domain events → outcomes, one aggregate per transaction), Brandolini (EventStorming policies → cases started on events), Young (CQRS; event sourcing optional), Richardson (outbox, sagas, idempotent consumers), Hohpe and Woolf (dead letter channels, correlation, aggregator → on_all), Fowler (hidden event flows → the graph), Helland (at-least-once, idempotence), Adzic (living documentation), the Agile Manifesto, infrastructure from code (Encore, Nitric), durable execution (Temporal, Inngest). Sypnia Cases is the **Living Cases Manifesto** as a product. The manifesto says why software should be built from use cases that run, are measured and stay true, and whose work that idea stands on. Read it in full: ### The principles, and where each one lives in these docs | Principle | In Sypnia Cases | | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- | | **The use case is the source of truth.** The code skeleton, the routes, schedules and queues, the permissions, the docs and what is measured come from it. | [Use cases](https://cases.docs.sypnia.com/map/use-cases), [Running cases](https://cases.docs.sypnia.com/runtime) | | **Anyone can read it.** Plain words first; technical detail is added, never put in its place. | [Reading for everyone](https://cases.docs.sypnia.com/map/reading-for-everyone) | | **Every case has a place and a start.** A tree of places inside the app; four typed ways to start. | [The navigation map](https://cases.docs.sypnia.com/map/navigation), [How a case starts](https://cases.docs.sypnia.com/map/starts) | | **Every case ends in a declared outcome.** Failures are outcomes too. Nothing ends in silence. | [Outcomes and events](https://cases.docs.sypnia.com/map/outcomes-and-events) | | **Outcomes are events with a contract.** Versioned names; an area shares only its public outcomes. | [Outcomes and events](https://cases.docs.sypnia.com/map/outcomes-and-events#areas-share-only-their-public-outcomes) | | **A case is a unit of meaning, not of deployment.** An area runs as one service; the runtime decides where each outcome goes. | [Running cases](https://cases.docs.sypnia.com/runtime#a-case-is-a-unit-of-meaning-not-of-deployment) | | **Reliable by construction, not by heroics.** Outbox in the same transaction, a queue and dead letters per listener, idempotence, loops refused or cut. | [Delivery](https://cases.docs.sypnia.com/runtime/delivery), [Loops](https://cases.docs.sypnia.com/runtime/loops) | | **Production tells the truth back.** Telemetry measures every case; real clicks confirm the map. | [Telemetry](https://cases.docs.sypnia.com/links/telemetry) | | **People and agents agree on the map.** The agent proposes a change to the map before going beyond it; the check keeps everyone honest. | [Agent](https://cases.docs.sypnia.com/links/agent), [The check](https://cases.docs.sypnia.com/contract/the-check) | ### The people it stands on None of these ideas is new on its own. What is new is putting them in one place a person can read and a machine can check. | Source | What we keep | What it became here | | --------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- | | **Ivar Jacobson**: use cases (1987), Use-Case 2.0 (2011, with Ian Spence and Kurt Bittner) | the use case as the unit of value, thin slices, tests per case | a file the tools read, from which routes, permissions, docs and measurements come | | **Alistair Cockburn**: _Writing Effective Use Cases_ (2000), hexagonal architecture (2005) | one actor and one goal, failures next to the main path, a core apart from what drives it | the ports are typed: `in_app`, `external`, `scheduled`, `event` in, declared outcomes out | | **R. J. A. Buhr**: Use Case Maps (1996, with R. S. Casselman; ITU-T Z.151) | the map as the thing you look at | two maps that agree: a tree of places for people, a graph of outcomes for the system | | **Robert C. Martin**: Screaming Architecture, Clean Architecture | use cases at the center, details at the edge | the boundary is generated from the case; you write the rules inside | | **Eric Evans**: _Domain-Driven Design_ (2003); **Vaughn Vernon**: _Implementing Domain-Driven Design_ (2013) | the business's language, bounded contexts, domain events, one consistent change per transaction | areas with public outcomes; outcomes as domain events; what a case writes is visible on the map | | **Alberto Brandolini**: EventStorming (2013) | starting from what happens; policies, «whenever this happens, do that» | each policy is a case that starts on an event | | **Greg Young**: CQRS and event sourcing (2010) | commands and reads as different cases; outcomes as facts | event sourcing is a choice, not a rule | | **Chris Richardson**: the transactional outbox, sagas, idempotent consumers | all three | the runtime writes the outbox; a saga is cases starting on each other's outcomes | | **Gregor Hohpe and Bobby Woolf**: _Enterprise Integration Patterns_ (2003) | dead letter channels, correlation identifiers, aggregators, guaranteed delivery | dead letters per listener on the map; `on_all` with a correlation key is an aggregator | | **Martin Fowler**: «What do you mean by “Event-Driven”?» (2017) | a clear name for each pattern, and the warning that event flows are hard to see | the event graph is drawn from the files and checked for loops | | **Pat Helland**: «Life beyond Distributed Transactions» (2007), «Idempotence Is Not a Medical Condition» (2012) | at-least-once delivery, idempotence, transactions kept in one place | idempotency keys and event ids are declared and enforced by the runtime | | **Gojko Adzic**: _Specification by Example_ (2011) | living documentation, true because something checks it | the cases are the documentation, and the code, infrastructure and telemetry are checked against them | | **The Agile Manifesto** (2001) | short, plain, made of choices; software that works | a living case is documentation and working software at the same time | | **Infrastructure from code** (Encore, Nitric) | no second description of the system | infrastructure comes from the cases | | **Durable execution** (Temporal, Inngest) | steps that survive failures, retries with limits, a history | the durable unit is the case and its outcomes, which people read on the map | The manifesto lists every source with its link, and marks the few short quotes it uses. --- ## Open source and Sypnia Cloud > Exactly what is open in Sypnia Cases, and what the hosted service adds. Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service). Source: https://cases.docs.sypnia.com/start/open-source-and-cloud/ For agents: Open source: the Sypnia Cases format (spec and JSON Schema), the @sypnia/cases package (validator, client, CLI `cases`), the Cases server (API, storage on Postgres, checks) and the runtime (outbox, fan-out, retries, dead letters, loop guard; on AWS or on Postgres alone). Sypnia Cloud adds: the visual editor, proposals with external reviewers, live links to Data/Telemetry/Git/Agent, history and exports, SSO with the Sypnia account, and billing in credits. Licenses: the server AGPL-3.0; @sypnia/cases (Sypnorm and the TypeScript runtime included) and the Rust crate sypnia-cases MIT, since they run inside apps; the format is open for anyone to implement. The format and the tools that read it are open, so a map never depends on us. Sypnia Cloud is our hosting of the same server, plus the parts that only make sense as a service. | | Open source | Sypnia Cloud | | ------------------------------------------------------------------------- | --------------------------------------------------------------------- | --------------------------------------------------------------- | | The format (case files, map file, JSON Schema) | yes | the same | | `@sypnia/cases`: Sypnorm, the runtime, validator, client, the `cases` CLI | yes, MIT | the same | | The `sypnia-cases` crate: the runtime for services written in Rust | yes, MIT | the same | | `cases check` in your CI | yes | the same, plus the result on every proposal | | The Cases server: API, storage, checks | yes, AGPL-3.0: run it yourself | run by us | | The runtime: outbox, fan-out, retries, dead letters, loop guard | yes: part of `@sypnia/cases` in each area's service, on your Postgres | run on AWS queues, one per listener | | The visual editor | — | yes | | Proposals with your client as a reviewer, comments per case | through pull requests on the files | yes, in the editor | | Live links to Data, Telemetry, Git, Agent | from your code and commits | yes, live on each case | | Sign-in | your own | your Sypnia account, one session for every product | | Billing | — | credits, prepaid ([Plans](https://cases.docs.sypnia.com/cloud)) | > **Note: Licenses** > > The Cases server is under AGPL-3.0, like the other Sypnia engines and servers. What runs inside your apps is under MIT, like an SDK, so it fits any app, open or closed: `@sypnia/cases`, Sypnorm and the TypeScript runtime included, and the Rust crate `sypnia-cases` with its core. The format is open: anyone can read, write and implement it ([Design decisions](https://cases.docs.sypnia.com/reference/decisions)). ### Using Cases alone Cases does not need any other Sypnia product. A team can plan an app as a map before any code exists, review it with a client, and keep it as files in GitHub. The links to Data, Telemetry, Git and Agent appear when those products are used, and stay empty otherwise. --- ## Quickstart: Sypnia Cloud > Map an app with the visual editor, invite your client to review it, and connect it to your repository. Applies to: Sypnia Cloud (paid service). Source: https://cases.docs.sypnia.com/start/quickstart-cloud/ For agents: Cloud quickstart: sign in at cases.app.sypnia.com with the Sypnia account; create a workspace and a map; add areas and use cases in the editor; invite a reviewer by e-mail; approve the first version; connect a repository so the files and the map stay in sync. #### 1. Sign in with your Sypnia account Go to [cases.app.sypnia.com](https://cases.app.sypnia.com). Your Sypnia account works here: if you already use Data or Telemetry, you land on your workspaces; if not, you create the account once, for every product. #### 2. Create a map Name the app (_La Espiga_) and write one sentence about it. Cases proposes the first **areas** from the sentence (_Menu_, _Orders_, _Pick-up_); keep, rename or remove them. #### 3. Write the first use cases In an area, choose **New use case** and write it as you would say it: _«A customer orders bread for today.»_ Cases asks the questions that turn it into a case: who does it, what they want, what can go wrong. You can leave the technical part (data, permissions) for later. #### 4. Invite your client to review Choose **Share for review** and write her e-mail. She signs in with a Sypnia account and sees the map in plain words, can comment on each case and approve it. Reviewers never see code or data. #### 5. Approve the first version When the map is right, approve it. It becomes **version 1**: the scope of the project. Every later change is a proposal against it. #### 6. Connect your repository In **Settings → Repository**, connect a repository in Sypnia Git or GitHub. Cases writes the map as files in `cases/` and keeps them in sync both ways. **You should see:** A map with areas and use cases, version 1 approved, the reviewer's comments on it, and a `cases/` folder in your repository. --- ## Quickstart: the map in your repo > Write the first case files, check them, and run the check in CI. No account needed. Applies to: the Sypnia engine (open source, self-hosted). Source: https://cases.docs.sypnia.com/start/quickstart-repo/ For agents: Repo quickstart: `npx @sypnia/cases init` creates cases/map.yaml, cases/navigation.yaml and an example case; edit cases//.case.yaml (starts, where, outcomes, failures) and cases/navigation.yaml; `npx @sypnia/cases check` validates against the JSON Schema and, with Sypnorm, compares with the code; add the check to CI (exit code 1 on scope errors). #### 1. Create the map ```bash npx @sypnia/cases init ``` It creates `cases/map.yaml` with your app's name, `cases/navigation.yaml` with a first root, and one example case. #### 2. Write a use case `cases/orders/place-order.case.yaml` ```yaml id: place-order title: Order for today actor: customer goal: Get fresh bread reserved for pick-up today starts: in_app where: shop.order-for-today steps: - The customer picks products and quantities - The system checks what is left and reserves it - The customer gets a pick-up code outcomes: OrderPlaced: { order_id: uuid, pickup_code: string } failures: OutOfStock: when: a product sold out while ordering tell: «This one just ran out. The rest of your order is kept.» data: reads: [product] writes: [order, order_item] allowed: [customer] ``` #### 3. Check it ```bash npx @sypnia/cases check ``` It validates every file against the [JSON Schema](https://cases.docs.sypnia.com/format/json-schema), checks that the case has a start and ends in declared outcomes, and that its place exists in `cases/navigation.yaml` (`init` wrote one with a root `shop`; add the place `shop.order-for-today` there, or let `npx @sypnia/cases nav --from-code` propose it from your screens). If your code uses Sypnorm, it also compares the code's use cases with the map ([The check](https://cases.docs.sypnia.com/contract/the-check)). #### 4. Run the check in CI `.github/workflows/cases.yml` ```yaml - run: npx @sypnia/cases check --ci ``` A scope error fails the build. The message says which code has no case, or which case is missing in the code. --- ## The map > Use cases, actors, areas and journeys, what a map is made of, and how a person who does not program reads it. Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service). Source: https://cases.docs.sypnia.com/map/ For agents: A map = use cases (the unit: who, goal, how it starts, where it lives, how it ends), actors (people roles and systems), areas (groups of cases with their public outcomes; one service each), journeys (ordered cases a person goes through), the navigation map (a tree of places, one parent each, roots per actor) and the event graph (outcomes as events between cases). Two views that agree: a tree of places for people, a graph of outcomes for the system. Pages: use-cases, navigation, starts, outcomes-and-events, actors-areas-journeys, editor, reading-for-everyone. A map is made of a few kinds of things. They are the same in the files, in the editor and in the API. | Thing | What it is | Example (a bakery) | | ------------ | --------------------------------------------------------------------------- | ----------------------------------------- | | **Use case** | One thing someone does with the app, from how it starts to how it ends | _Order for tomorrow_ | | **Actor** | Who does it: a kind of person, or another system | _customer_, _staff_, _Rappi_, _the clock_ | | **Area** | A group of cases that belong together, with the outcomes it shares | _Orders_, _Weather_, _Deliveries_ | | **Journey** | Cases one person goes through, in order | _First order_: sign up → order → pick up | | **Place** | Where a case happens in the app, in the navigation tree | _Shop › Order for tomorrow_ | | **Start** | How a case starts: in the app, from another app, on a schedule, on an event | _every 2 hours, Bogotá time_ | | **Outcome** | How a case ends, with a name and a typed payload; failures are outcomes too | _OrderPlaced_, _SoldOut_ | The map is really **two maps that agree**: a tree of places for people, so everyone knows where each case lives, and a graph of outcomes for the system, so everyone knows what each case sets off. Both are drawn from the same case files. --- ## Use cases > Every part of a use case, what it is for, and how to write it well. Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service). Source: https://cases.docs.sypnia.com/map/use-cases/ For agents: Use case fields: id (kebab-case, stable), title (plain words), actor (one primary actor id), goal (one sentence), starts (how it starts: in_app | { external: webhook|api, idempotency_key, respond, input, signature } | { scheduled: 'every 2h' | cron, timezone } | { event: } | { event: { on: [...] | on_all: [...], key, within, filter, order_by } }), where (optional place id in the navigation map, only for in_app, e.g. shop.order-for-tomorrow), preconditions, steps, input (typed fields), outcomes (named, PascalCase, typed payload: { OrderPlaced: { order_id: uuid, ready_at: datetime } }; long form { payload, says }), failures (outcomes too: { SoldOut: «tell» } or long form { when, tell, payload }; the list form - name/when/tell is accepted), data (reads/writes), allowed (actor ids), ai ({ tasks: [...] } Sypnia AI tasks it calls), files ({ reads, writes }: Sypnia Files buckets), mail ({ sends: [...] }: Sypnia Mail templates), loop ({ bounded: true, max, until } only to close a reviewed cycle), retries ({ max, backoff }), status (idea|approved|building|live|retired), owner, notes. Required: id, title, actor, goal, starts, and at least one outcome. Every case ends in a declared outcome. A use case is the unit of the map. It is written in plain words first; the technical parts come later, from a programmer, the coding agent or the code itself. `cases/orders/order-for-tomorrow.case.yaml` ```yaml id: order-for-tomorrow title: Order for tomorrow actor: customer goal: Get bread reserved for tomorrow morning starts: in_app where: shop.order-for-tomorrow # Shop › Order for tomorrow preconditions: - The bakery bakes tomorrow steps: - The customer picks products and quantities - The system checks what is left for tomorrow and reserves it - The customer gets a pick-up code input: items: [{ product_id: uuid, qty: int }] pickup_at: datetime outcomes: OrderPlaced: { order_id: uuid, ready_at: datetime } failures: SoldOut: «That bread is sold out for tomorrow. Pick another?» Closed: when: the bakery does not bake that day tell: «We don't bake that day. Try the next one.» data: reads: [product, bake_day] writes: [order, order_item] allowed: [customer] status: approved owner: ana@laespiga.co ``` ### The parts | Part | Required | What it is for | | ---------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `id` | yes | A stable name in `kebab-case`. Code, commits, events and traces use it; renaming the title never changes it. | | `title` | yes | What people call it, in their words. | | `actor` | yes | Who starts it: one [actor](https://cases.docs.sypnia.com/map/actors-areas-journeys) of the map. A case started by another system or by the clock has a system actor. | | `goal` | yes | One sentence: what the actor wants. If it needs two sentences, it is probably two cases. | | `starts` | yes | How it starts: `in_app`, `external`, `scheduled` or `event`, each with its own fields ([How a case starts](https://cases.docs.sypnia.com/map/starts)). | | `where` | no | Only for `in_app`: the [place](https://cases.docs.sypnia.com/map/navigation) in the app where it happens, such as `shop.order-for-tomorrow`. Its path, «Shop › Order for tomorrow», is worked out from the navigation map. | | `preconditions` | no | What must be true before it can start. | | `steps` | no | What happens, in order, in plain words. A step can start with another actor: `staff: confirms the order`. | | `input` | no | What it receives, as typed fields ([Types](#types)). For `external` starts this is the body the other app sends. | | `outcomes` | yes | How it ends well: each outcome has a name in `PascalCase` and a typed payload ([Outcomes and events](https://cases.docs.sypnia.com/map/outcomes-and-events)). At least one. | | `failures` | no | How it ends when something expected goes wrong. **Failures are outcomes too**: a name, when it happens, and what to `tell` the person. | | `data` | no | The tables it `reads` and `writes`. With Sypnorm this comes from the code. | | `allowed` | no | The actors allowed to run it. | | `ai` | no | The [Sypnia AI](https://ai.docs.sypnia.com/using/cases-and-traces/) tasks it calls: `ai: { tasks: [allergen-answer] }`. | | `files` | no | The [Sypnia Files](https://files.docs.sypnia.com/buckets/use-cases/) buckets it `reads` and `writes`: `files: { writes: [receipts] }`. | | `mail` | no | The [Sypnia Mail](https://mail.docs.sypnia.com/events/use-cases/) templates it `sends`: `mail: { sends: [order-ready] }`. | | `loop` | no | Only to close a cycle of events on purpose: `loop: { bounded: true, max: 3, until: "…" }` ([Loops](https://cases.docs.sypnia.com/runtime/loops)). | | `retries` | no | For a case that starts on an event: how many attempts before dead letters: 5 by default, 1 to 20 ([Delivery](https://cases.docs.sypnia.com/runtime/delivery#retries)). | | `status` | no | `idea`, `approved`, `building`, `live` or `retired`. | | `owner`, `notes` | no | Who answers for it, and anything else worth saying. | `data`, `ai`, `files` and `mail` say what the case uses from the other products. The check compares each list with what really happens, in the code and in production: something used and not listed, or listed and never used, is reported. ### Every case ends in a declared outcome A run of a case ends in exactly one of its outcomes or failures, never in silence. The words a person reads, the types in the code and what Telemetry counts all come from that list. An error nobody declared (a bug, a database that does not answer) is not an outcome: it is reported to Telemetry as an error, and a run started by an event goes to its [dead letters](https://cases.docs.sypnia.com/runtime/delivery#dead-letters) after its retries. ### Outcomes and failures, short and long The short form is the one most cases need: ```yaml outcomes: OrderPlaced: { order_id: uuid, ready_at: datetime } failures: SoldOut: «That bread is sold out for tomorrow. Pick another?» ``` The long form adds words for people and a payload to a failure: ```yaml outcomes: OrderPlaced: says: The bread is reserved until 10 am tomorrow payload: { order_id: uuid, ready_at: datetime } failures: SoldOut: when: a product sold out while ordering tell: «That bread is sold out for tomorrow. Pick another?» payload: { product_id: uuid } ``` An outcome with a `payload` key is in the long form; otherwise every key is a field of the payload. Failures may also be written as a list (`- name: SoldOut`, `when`, `tell`); both forms mean the same. ### Types Payloads and inputs use a small set of types, the same in every language Sypnorm generates code for: | Type | Means | | ------------------------------ | -------------------------------------------------------------------------- | | `string`, `text` | a short text, a long text | | `int`, `number`, `money` | a whole number, any number, an amount in the smallest unit of the currency | | `bool` | true or false | | `uuid`, `email`, `url` | an id, an e-mail address, an address | | `date`, `datetime`, `duration` | a day, a moment with its time zone, a span of time (`2h`) | | `[type]`, `{ field: type }` | a list, an object | | `type?` | optional | | `one_of(a, b)` | one of these words | | any other word | that exact value, always (`channel: whatsapp`) | Inside a YAML flow mapping, `{ channel: one_of(sms, call) }`, YAML itself splits the value at the comma; the reader joins the pieces back, so it means what it says. Quoting it, `channel: "one_of(sms, call)"`, avoids the question. ### Writing a good use case - **One actor, one goal.** «Customer orders and staff confirms» is two cases joined by an event or a journey. - **Steps say what, not how.** «The system reserves the products», not «INSERT into reservation». - **Name every ending.** An outcome named in the map is something you can count, and a failure named in the map is a message a real person will read. One found in production is a bug. - **Name outcomes in the past tense.** `OrderPlaced`, `RainExpected`, `BakerTold`: something that already happened. - **Keep the id when the meaning stays.** Change the title freely; change the id only when it becomes a different case. --- ## The navigation map > Where every case lives in your app, as a tree of places, and everything that is worked out from it. Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service). Source: https://cases.docs.sypnia.com/map/navigation/ For agents: cases/navigation.yaml: roots[] {id, title, actors[], route} (several roots: public site, console, member app; an actor may have several), places[] {id (dotted kebab segments, e.g. shop.order-for-tomorrow, stable), title, kind screen|tab|modal|menu|panel, parent (exactly one), opened_by {label, kind button|link|item|tab} = the actionable on the parent that opens it, route?, permission?}, shortcuts[] {from, to, label} (other ways in; never a second parent). Path = titles from root to place, «Shop › Order for tomorrow», computed, never written. A case with starts: in_app may have where: . Place ids: kebab-case segments joined by dots, independent of the route and of the tree path (moving a place keeps its id). In the markup: data-sypnia-place on the element that shows a place (set by Sypnia Design's generated pieces and @sypnia/ui from the case's where), data-sypnia-opens= on an actionable; `cases nav --from-code` proposes the tree. Telemetry: every page_view and click carries place (innermost data-sypnia-place); spans carry sypnia.case and sypnia.case.outcome; the navigation check compares moves with the tree (nav-missing-edge, nav-unreached 30 days, nav-unknown-route). Feeds: «how to get there» in docs, the agent («where do I edit X?»), role editors, video breadcrumbs, Design screens. Inside the app, every case has a **place**: the screen, tab, modal or menu where it happens. The navigation map puts those places in a **tree**, so the way to reach any of them is always known: «Shop › Order for tomorrow». `cases/navigation.yaml` ```yaml roots: - id: site title: La Espiga actors: [visitor, customer] route: / - id: shop title: Shop actors: [customer] route: /shop - id: console title: Console actors: [staff, owner] route: /console places: - id: shop.order-for-tomorrow title: Order for tomorrow kind: screen parent: shop opened_by: { label: Order for tomorrow, kind: button } route: /shop/tomorrow - id: shop.order-for-today title: Order for today kind: screen parent: shop opened_by: { label: Order for today, kind: button } route: /shop/today - id: shop.my-orders title: My orders kind: tab parent: shop opened_by: { label: My orders, kind: tab } - id: shop.my-orders.order-detail title: Order kind: screen parent: shop.my-orders opened_by: { label: an order in the list, kind: item } - id: console.cash-flow title: Cash flow kind: screen parent: console opened_by: { label: Cash flow, kind: item } - id: console.cash-flow.new-transaction title: New transaction kind: modal parent: console.cash-flow opened_by: { label: New transaction, kind: button } permission: payments.create shortcuts: - from: site to: shop.order-for-tomorrow label: Order now ``` ### The parts | Part | What it is | | -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | **Root** | Where an actor comes in: the public site, the console, the member app. A map has as many roots as the app has front doors, and an actor may have several. | | **Place** | A screen, tab, modal, menu or panel. It has an `id`, a `title`, a `kind`, an optional `route` and an optional `permission`. | | **Parent** | Every place has **exactly one** parent: a root or another place. That is what makes the path unique. | | **Actionable** | The button, link, menu item or tab on the parent that opens the place (`opened_by`). It is what a person clicks. | | **Shortcut** | Any other way to reach a place: a link on the home page, a notification, a search result. Shortcuts are ways in, never a second parent. | #### Ids and paths A place id is lowercase words in `kebab-case`, joined by dots: `shop.order-for-tomorrow`. By habit the first part is the root or section it lives under. The id is a name from your code, **independent of the route and of the path in the tree**: the route can change, and moving a place to another parent keeps its id, and every case that points to it. The **path** is never written by hand. It is the titles from the root to the place, joined with `›`: `console.cash-flow.new-transaction` reads «Console › Cash flow › New transaction». Rename a title and every path that goes through it follows. #### Cases and places A case that happens inside the app says where with `where`: `cases/payments/record-transaction.case.yaml` ```yaml id: record-transaction starts: in_app where: console.cash-flow.new-transaction ``` `where` is optional, and only cases that start `in_app` have one. A case that starts when another app calls, on a schedule or on an event has no place; where it changes what people see, that change shows on the places of the cases that show it. Several cases can share a place: «See my orders» and «Cancel an order» both live on `shop.my-orders.order-detail`. ### Generated from the code, checked by real clicks You can write the tree by hand, but it usually comes from the code. Each place and each actionable carries an id in the markup: ```html
Order for tomorrow
…
``` `data-sypnia-place` goes on the element that shows a place; `data-sypnia-opens` on the actionable that opens one. The pieces [Sypnia Design](https://design.docs.sypnia.com/) generates, and the components of `@sypnia/ui`, set them for you from the case's `where`; in any other markup, write the attributes yourself. Then: ```bash npx @sypnia/cases nav --from-code # reads every data-sypnia-place and data-sypnia-opens, proposes the tree ``` The result is a proposal, like any change to the map. Then [Sypnia Telemetry](https://telemetry.docs.sypnia.com/concepts/use-cases-and-places/) confirms the tree with what people really do. Its browser SDK reads the same attribute: every `page_view` and `click` carries `place`, the id of the innermost `data-sypnia-place` around it (an id from your code, never the page's content). On the server side, every run of a case is a span with `sypnia.case` (the case id) and `sypnia.case.outcome` (how it ended). With the project linked, Cases compares people's moves, a click in one place and the next place they see, with the tree: | Finding | What it means | What to do | | ------------------- | ------------------------------------------------------------------------------------- | ---------------------------------------------- | | `nav-missing-edge` | people move between two places with no actionable or shortcut between them in the map | add it as a shortcut, or remove the link | | `nav-unreached` | a place nobody reached in 30 days | check the way to it, or remove it from the map | | `nav-unknown-route` | a route people visit that has no place | give it a place, or find out why it exists | Each finding is shown on the map, with a proposal ready to accept or dismiss ([Telemetry](https://cases.docs.sypnia.com/links/telemetry)). ### What the tree feeds The tree is written once and used everywhere a person or an agent needs to know where something is: - **«How to get there» in your docs and help pages.** Each case shows its path, «Shop › Order for tomorrow», always current. - **The coding agent.** «Where do I edit the price of a product?» has one answer: the place, its path, its route and the files behind it ([Agent](https://cases.docs.sypnia.com/links/agent)). - **Role editors.** When you edit a role, the tree shows which places it can reach and which it cannot, by `permission`, so a role never ends up with a button that leads nowhere. - **Video breadcrumbs.** A tutorial or support video shows the path of each step as it records it ([Sypnia Learn](https://learn.docs.sypnia.com/)). - **Screens.** [Sypnia Design](https://design.docs.sypnia.com/screens/screens-per-case/) designs one screen for every case with a `where`, and shows its path. ### Rules the check applies - Every `parent` exists, and following parents always reaches a root (no cycles). - Ids are unique across roots and places. - A case's `where` exists, and its `actor` is one of the actors of the place's root. - A case with `where` starts `in_app`. - A shortcut points to an existing place and never replaces its parent. --- ## How a case starts > The four ways a case starts, inside the app, from another app, on a schedule or on another case's outcome, and what each one becomes. Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service). Source: https://cases.docs.sypnia.com/map/starts/ For agents: starts (required), typed: in_app (a person in a place; may have where) | { external: webhook|api, idempotency_key: , respond: outcome (default for api: wait and answer with the outcome) | accepted (202 + run_id at once; default for webhook), signature: { header, secret } (HMAC of the body) or a case key (Authorization: Bearer syp_rck_…, one case only) } → a public endpoint POST /hooks/ with the input schema; a resend with the same key within 24 h returns the first answer and runs nothing; in_app → a route of the area's service POST /_cases/ called with the person's Sypnia Data session, run under RLS (401 without one; role = app_metadata.role, else [cases] default_role of sypnia.toml; 403 for a role not in allowed, or an Origin other than the service's own host or [cases] origins); a case someone listens to always starts there, never from the browser; case keys: secret SYPNIA_CASE_KEY_, printed by `npx @sypnia/cases key `; every m|h is an elapsed interval aligned to the zone's standard time, every d runs at local midnight every n days counted from 1970-01-01 | { scheduled: 'every 2h' | '', timezone: IANA (default UTC) } → a job | { event: } | { event: { on: [a, b] (any), filter: { field: value | { gte, gt, lte, lt, in, exists } } } } | { event: { on_all: [a, b], key: , within: } } (waits for all with the same key inside the window; otherwise WindowExpired in Telemetry, case not started); order_by: delivers same-key events one at a time in order. in_app yes/no is derived from the kind. A case with no start is an orphan (check error). Only public outcomes of other areas can be listened to; a case never listens to its own outcome. Every case says how it starts, with `starts`. There are four kinds, and each one becomes something real when the app runs: a place on a screen, an endpoint, a job or a subscription. `La Espiga, four ways to start` ```yaml # cases/orders/order-for-tomorrow.case.yaml starts: in_app where: shop.order-for-tomorrow # cases/orders/rappi-order.case.yaml starts: { external: webhook, idempotency_key: rappi_order_id } # cases/weather/check-weather.case.yaml starts: { scheduled: 'every 2h', timezone: America/Bogota } # cases/deliveries/pause-deliveries.case.yaml starts: { event: weather.check-weather.RainExpected.v1 } ``` | Kind | Who starts it | What it becomes | | ----------- | ------------------------------------------------------ | -------------------------------------------------------------- | | `in_app` | a person, in a place of the app | a button or form on that place's screen; its path in the docs | | `external` | another app: a webhook it sends, or a call to your API | an HTTP endpoint with its input schema and its idempotency key | | `scheduled` | the clock | a job, on the time zone you name | | `event` | another case's outcome | a subscription with its own queue, retries and dead letters | Whether a case happens inside the app is never written separately: it is `in_app` or it is not. ### `in_app` A person starts it from a place of the app. The case may say which place with [`where`](https://cases.docs.sypnia.com/map/navigation); its `actor` is a person, and `allowed` says which roles may run it. The runtime gives it a route of your app, `POST /_cases/`, that your screen calls with the person's [Sypnia Data](https://data.docs.sypnia.com/) session: no session gets `401`, a role that is not allowed gets `403`. The case runs under the project's row-level security, as that person. The person's role is `app_metadata.role` of their Data session; when the session has none, it is the `default_role` of the `[cases]` table of `sypnia.toml`. `allowed` is compared with that role. The route answers only your own pages: a request whose `Origin` is not the service's own host, or one of the `origins` listed in the same table, gets `403`. `sypnia.toml` ```toml [cases] default_role = "customer" origins = ["https://la-espiga.example"] ``` A case whose outcome some case listens to always starts here, on the server, so its outbox row commits with its data ([Runners](https://cases.docs.sypnia.com/sypnorm/runners#a-case-someone-listens-to-runs-on-the-server)). ### `external` Another app starts it: Rappi creating an order, a payment provider confirming a payment, a partner's system calling your API. `cases/orders/rappi-order.case.yaml` ```yaml id: rappi-order title: An order arrives from Rappi actor: rappi goal: Bake and hand over what Rappi's customer ordered starts: external: webhook idempotency_key: rappi_order_id signature: { header: X-Rappi-Signature, secret: RAPPI_SECRET } input: rappi_order_id: string items: [{ sku: string, qty: int }] pickup_at: datetime outcomes: OrderPlaced: { order_id: uuid, ready_at: datetime } failures: SoldOut: { when: a product is sold out, payload: { sku: string } } ``` | Field | What it does | | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `external` | `webhook` (the other app sends and does not wait for the result) or `api` (the other app calls and waits for it) | | `idempotency_key` | the input field that identifies one request. A resend with the same key within 24 hours runs nothing and gets the first answer back, so a resent order is not baked twice. For `api` starts, the caller may send the key in the `Idempotency-Key` header instead | | `respond` | `outcome`: answer with the case's outcome (the default for `api`). `accepted`: answer `202 Accepted` with a `run_id` at once and run the case from a queue (the default for `webhook`) | | `signature` | how the caller proves who it is: an HMAC-SHA256 of the body in the `header` you name, with a `secret` you keep in your app's secrets. Without `signature`, the caller sends a **case key** instead (`Authorization: Bearer syp_rck_…`), good for that one case only: `npx @sypnia/cases key ` prints a new one, which your app keeps in the secret `SYPNIA_CASE_KEY_` (`SYPNIA_CASE_KEY_RAPPI_ORDER`). A request that fails either gets `401` and never starts the case | The endpoint is `POST /hooks/` on your app's address (`POST /hooks/rappi-order`), and its body is the case's `input`. The input is checked before the case runs: a bad body gets `422` with the field that is wrong. With `respond: outcome`, a declared failure answers `422` with its name and payload, and an outcome answers `200` with its payload. ### `scheduled` The clock starts it. `cases/weather/check-weather.case.yaml` ```yaml id: check-weather title: Check the weather actor: clock goal: Know in time when rain is coming starts: { scheduled: 'every 2h', timezone: America/Bogota } outcomes: RainExpected: { from: datetime } ClearSkies: {} ``` `scheduled` takes `every m|h|d` or a cron line (`'0 6 * * 1-6'`, six in the morning, Monday to Saturday). `every m` and `every h` are an elapsed interval aligned to the zone's standard time (`every 2h` runs at 0:00, 2:00, 4:00…); `every d` runs at local midnight every `n` days, counted from 1970-01-01. `timezone` is a name from the time-zone database, `UTC` when left out, and changes of daylight saving time are handled for you. A run still going when the next one is due makes the next one skip, unless the start says `overlap: allow`. Like every schedule, it runs at least once per time, so the case must do no harm if it runs twice. ### `event` Another case's outcome starts it. The name of an outcome is `...v` ([Outcomes and events](https://cases.docs.sypnia.com/map/outcomes-and-events)). `One outcome` ```yaml starts: { event: weather.check-weather.RainExpected.v1 } ``` **Any of several**, with `on`: `cases/kitchen/plan-the-bake.case.yaml` ```yaml starts: event: on: [orders.order-for-tomorrow.OrderPlaced.v1, orders.rappi-order.OrderPlaced.v1] ``` **Only some**, with a filter on the payload: `cases/payments/tell-the-owner.case.yaml` ```yaml starts: event: on: [payments.take-payment.PaymentTaken.v1] filter: { amount: { gte: 100000 } } ``` **All of several**, with `on_all`: the case starts once every outcome with the same correlation key has arrived, inside a window of time. `cases/deliveries/send-out.case.yaml` ```yaml starts: event: on_all: [payments.take-payment.PaymentTaken.v1, kitchen.bake.Baked.v1] key: order_id within: 4h ``` | Field | What it does | | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `on` | starts on any of these outcomes | | `on_all` | starts when all of them arrived with the same `key` value; the case receives every payload | | `key` | the payload field that joins them (the correlation key), present in every outcome listed | | `within` | how long to wait for the rest. If the window closes first, the case does not start: the wait ends as `WindowExpired`, which Telemetry shows among the case's endings, with what arrived ([Telemetry](https://cases.docs.sypnia.com/links/telemetry)) | | `filter` | starts only when the payload matches: a value, or `gt`, `gte`, `lt`, `lte`, `in`, `exists` | | `order_by` | a payload field: events with the same value are delivered one at a time, in order. Without it, events may arrive in any order | `filter` is called `filter`, never `where`: `where` is always the case's place in the app. Two rules keep areas apart and events honest: - A case can listen to another area's outcome only if that area made it **public**. Outcomes inside one area can be listened to by any case of that area ([Actors, areas and journeys](https://cases.docs.sypnia.com/map/actors-areas-journeys#areas)). - A case never listens to its own outcome. Cycles between cases are refused unless they say how they stop ([Loops](https://cases.docs.sypnia.com/runtime/loops)). ### A case with no start A case without `starts` is an **orphan**: nothing can ever run it. The check reports it as an error, so every case on the map has a way in. --- ## Outcomes and events > How every case ends, how its outcomes become events other cases listen to, and how areas share only what they make public. Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service). Source: https://cases.docs.sypnia.com/map/outcomes-and-events/ For agents: Every run ends in exactly one declared outcome or failure (failures are outcomes); an undeclared error is not an outcome: it goes to Telemetry as an error and, for event-started runs, to dead letters after retries. Event name ...v (e.g. weather.check-weather.RainExpected.v1); a breaking payload change needs a new version (check: breaking-change), adding an optional field does not; a new version is declared in the outcome's long form, version: and since: (required from version 2: the day it was first emitted); the case emits both for 90 days after since, the previous one with the payload given in ctx.outcome(name, payload, { previous: { 1: … } }) or the same payload, then the old one stops (check: old-version counts the days from since: a warning with the days left, an error after the 90 days). A declared failure undoes the run's own writes; its event (when someone listens) and the delivery's record still commit. Event envelope: id (uuid v7), name, data (the payload, ≤256 KB), occurred_at, key (order_by value), traceparent, cause (chain of case ids), depth. Delivery decided by the runtime: to the caller if one waits (in_app, external api with respond: outcome), to the outbox if any case listens, always to Telemetry. Areas: outcomes internal by default; map.yaml areas[].public lists the ones other areas may listen to (the area's contract); listening to another area's internal outcome is a check error (internal-outcome). The event graph is drawn from the files and checked for loops. Every case ends in one of the outcomes it declares. Those outcomes are what the person sees, what the code returns, what Telemetry counts and, when another case listens, the events that start the next part of the work. ### Every case ends in a declared outcome A run ends in **exactly one** of its outcomes or failures: - **An outcome** when it went well: `OrderPlaced`, `RainExpected`, `ClearSkies`. - **A failure** when something expected went wrong: `SoldOut`, `Closed`. Failures are outcomes too: they have a name and a payload, they can be listened to, and they carry the words the person reads. A failure undoes the run's own writes, so nothing half-done stays behind; its event, when some case listens to it, is still sent. Nothing ends in silence. A case that returns without an outcome, or with one it did not declare, does not compile with Sypnorm and is reported by the check. What is **not** an outcome is an error nobody declared: a bug, a database that does not answer, a provider that is down. The run ends as `error`, the person sees a short generic message with a reference, and Telemetry records it as a problem with its trace. A run started by an event is retried and, if it keeps failing, its event goes to the subscriber's [dead letters](https://cases.docs.sypnia.com/runtime/delivery#dead-letters), where you can see it and send it again. ### Outcomes are events Each outcome has a full name: the area, the case, the outcome and a version. ```text weather.check-weather.RainExpected.v1 └─area─┘└───case────┘└──outcome──┘└version ``` Any case can start on it with [`starts: { event: … }`](https://cases.docs.sypnia.com/map/starts#event). La Espiga's rain chain is three cases joined by two events: ```yaml # cases/weather/check-weather.case.yaml starts: { scheduled: 'every 2h', timezone: America/Bogota } outcomes: { RainExpected: { from: datetime }, ClearSkies: {} } # cases/deliveries/pause-deliveries.case.yaml starts: { event: weather.check-weather.RainExpected.v1 } outcomes: { DeliveriesPaused: { until: datetime } } # cases/deliveries/tell-the-baker.case.yaml starts: { event: deliveries.pause-deliveries.DeliveriesPaused.v1 } outcomes: { BakerTold: { channel: whatsapp } } ``` #### Versions The version protects the listeners. A change that would break one, such as removing a field, renaming it or changing its type, needs a new version: `RainExpected.v2`. Adding an optional field keeps the version. The check refuses a breaking change under the same version (`breaking-change`). A new version is written in the outcome's long form, with the day it was first emitted: `cases/weather/check-weather.case.yaml` ```yaml outcomes: RainExpected: payload: { from: datetime, until: datetime } version: 2 since: 2026-11-18 ClearSkies: {} ``` `since` is required from version 2 on. From that day, the case emits both versions for **90 days**, and the map shows who has not moved yet. `v1` carries the payload the code gives for it, or the same payload: ```ts return ctx.outcome('RainExpected', { from, until }, { previous: { 1: { from } } }); ``` A failure takes `version` and `since` the same way, next to `when` and `tell`. After those 90 days, `v1` is no longer emitted (sooner, if no case listens to it any more). While both are emitted, `cases check` counts the days from `since` and warns every case still listening to `v1`, with the days left (`old-version`); after the 90 days the warning becomes an error, so a listener cannot stay on an event that no longer arrives. #### What an event carries | Field | What it is | | ------------- | ----------------------------------------------------------------------------------------------------------- | | `id` | a unique id (a UUID, ordered by time). Listeners use it to never handle the same event twice | | `name` | `weather.check-weather.RainExpected.v1` | | `data` | the outcome's typed payload, at most 256 KB | | `occurred_at` | when the run ended | | `key` | the value of the listener's `order_by` field, when it has one | | `traceparent` | the trace it belongs to, so Telemetry shows the whole chain as one trace | | `cause` | the chain of cases that led here, used to stop loops ([Loops](https://cases.docs.sypnia.com/runtime/loops)) | | `depth` | how many events deep in the chain this one is | The full example is on [Delivery](https://cases.docs.sypnia.com/runtime/delivery#what-each-event-carries). ### Where an outcome goes You never choose by hand where an outcome is sent. The runtime decides it from the map: | Who needs it | Where it goes | | ----------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | someone is waiting for it: the person on the screen (`in_app`), or the caller of an `api` start with `respond: outcome` | back to them, as the answer | | some case listens to it | into the outbox, in the same transaction as the case's data, and from there to each listener ([Delivery](https://cases.docs.sypnia.com/runtime/delivery)) | | always | to Telemetry, as the outcome of the run's span | So an outcome nobody listens to costs nothing more than its span, and adding a listener later needs no change to the case that emits it. ### Areas share only their public outcomes An **area** is a group of cases that belong together ([Actors, areas and journeys](https://cases.docs.sypnia.com/map/actors-areas-journeys#areas)). Its outcomes are **internal** by default: only cases of the same area can listen to them. The ones other areas may listen to are listed in the area, and that list is the area's contract with the rest of the app: `cases/map.yaml (areas)` ```yaml areas: - id: weather title: Weather cases: [check-weather] public: [check-weather.RainExpected] - id: deliveries title: Deliveries cases: [pause-deliveries, tell-the-baker] public: [pause-deliveries.DeliveriesPaused] ``` A case that listens to another area's internal outcome is a check error (`internal-outcome`). That keeps areas apart: an area can change everything inside it, as long as its public outcomes keep their shape. ### The event graph Every case says what it listens to, so the flow of events is never hidden: Cases draws the **event graph** from the files. In the editor it is a second view of the map, next to the navigation tree: cases as nodes, events as arrows, each arrow with its queue, its retries and its dead letters. In the terminal: ```bash npx @sypnia/cases graph # the whole graph, as text npx @sypnia/cases graph --from weather.check-weather.RainExpected.v1 ``` ```text weather.check-weather ──RainExpected.v1──▶ deliveries.pause-deliveries ──DeliveriesPaused.v1──▶ deliveries.tell-the-baker ``` The check reads the same graph to find [loops](https://cases.docs.sypnia.com/runtime/loops), listeners of outcomes that do not exist, and outcomes from external and scheduled cases that nothing uses. --- ## Actors, areas and journeys > Who acts in the map, how cases are grouped, and the paths people take through them. Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service). Source: https://cases.docs.sypnia.com/map/actors-areas-journeys/ For agents: Actors: id, name, kind (person|system), description; a person actor maps to a role in the app (and, with Data, to RLS roles); systems include other apps (rappi) and the clock (scheduled cases). Areas: id, title, cases in order, public (outcomes other areas may listen to: .; everything else internal); an area runs as one service. Journeys: id, title, actor, an ordered list of case ids, optional branches. Defined in cases/map.yaml. ### Actors An actor is _who_ acts: a kind of person (customer, staff, owner) or another system (a payment provider, a scheduler). Every use case has one primary actor; steps can name others. `cases/map.yaml (actors)` ```yaml actors: - id: customer name: Customer kind: person description: Someone who buys at the bakery, signed in with an e-mail code - id: staff name: Staff kind: person description: Bakery staff; sees and prepares every order - id: payments name: Payment provider kind: system - id: rappi name: Rappi kind: system description: Sends orders from its app, by webhook - id: clock name: The clock kind: system description: Starts the scheduled cases - id: system name: The app itself kind: system description: Runs the cases that start on another case's outcome ``` With Sypnia Data, a person actor is usually a role your row-level security knows. Cases shows the link: the policies of the tables a case touches, and whether they allow its actors ([Data](https://cases.docs.sypnia.com/links/data)). ### Areas An area groups cases that belong together, like a module or a section of the app, in the business's own words. Areas give the map its shape in the editor (one lane per area), keep their insides to themselves, and run together: the cases of an area run in one service ([Running cases](https://cases.docs.sypnia.com/runtime)). `cases/map.yaml (areas)` ```yaml areas: - id: menu title: Menu cases: [see-today-menu] - id: orders title: Orders cases: [place-order, order-for-tomorrow, rappi-order, cancel-order, see-my-orders] public: [place-order.OrderPlaced, order-for-tomorrow.OrderPlaced, rappi-order.OrderPlaced] - id: pickup title: Pick-up cases: [pick-up-order, mark-picked-up] ``` A case file lives in its area's folder: `cases/orders/order-for-tomorrow.case.yaml`. `public` lists the outcomes other areas may listen to, as `.`. Everything else is internal to the area: its cases can listen to each other, and nobody outside can ([Outcomes and events](https://cases.docs.sypnia.com/map/outcomes-and-events#areas-share-only-their-public-outcomes)). An area's public outcomes are its contract with the rest of the app. ### Journeys A journey is the path one person takes through several cases, in order. Journeys are how a client checks that the whole experience makes sense, and how a new team member learns the app. `cases/map.yaml (journeys)` ```yaml journeys: - id: first-order title: A customer's first order actor: customer cases: [sign-up, see-today-menu, place-order, pick-up-order] ``` A journey may branch: `cases: [place-order, { either: [pick-up-order, cancel-order] }]`. --- ## The visual editor > The map for people who do not program, in Sypnia Cloud. Applies to: Sypnia Cloud (paid service). Source: https://cases.docs.sypnia.com/map/editor/ For agents: The visual editor (cases.app.sypnia.com): areas as lanes, cases as cards with status and health, journeys as arrows; views of the navigation tree (places, paths, Telemetry click findings) and of the event graph (queues, retries, dead letters, cycles); case detail as a plain-language form; writing a case from a sentence (AI-assisted questions); keyboard and phone support; every edit is a change to the same files, saved as a draft proposal. The editor shows the map as **lanes** (areas), **cards** (use cases) and **arrows** (journeys). Every change in the editor is a change to the same files you would write by hand. ### What you see - **A card per use case**, with its title, its actor and its status. With other Sypnia products connected, the card also shows its health: errors and how often it runs (Telemetry), and whether its code exists (Git). - **Lanes per area**, in the order of the map. - **Journeys** as numbered arrows across lanes. Choose a journey to see only its cases. - **The navigation tree**, a second view: the roots and their places, each with the cases that live there and its path. Telemetry's findings (a button nobody uses, a way people move that the tree lacks) show on the place. - **The event graph**, a third view: cases as nodes and events as arrows, each arrow with its queue, its retries and its dead letters. A cycle is drawn in a warning colour until it says how it stops. ### Writing without programming Choose **New use case** and write a sentence: _«A customer orders bread for today.»_ The editor asks what it needs, one question at a time: who does it, what they want, how it starts, how it ends, what could go wrong. The answers become the case. The technical parts (data, permissions, places, payloads) stay optional and are shown only to people who ask for them. ### Changes are proposals Editing an approved map creates a **draft proposal**. You see your change against the approved version, can ask for review, and nothing becomes scope until it is approved ([Versions, proposals and reviews](https://cases.docs.sypnia.com/contract/versions-and-reviews)). ### On a phone and with a keyboard The lanes become a list of areas on a phone. Every action has a keyboard path: `n` new case, `/` search, `j`/`k` between cases, `Enter` to open. --- ## Reading for everyone > The same use case at three levels of detail, chosen by who is reading. Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service). Source: https://cases.docs.sypnia.com/map/reading-for-everyone/ For agents: Three reading levels of a case: plain (title, actor, goal, steps, failures as messages), working (adds place path, data, allowed actors, status), technical (adds types, events emitted and listened to, Sypnorm signature, tables and policies, traces, code links). The level is chosen per person (from the Sypnia knowledge test, persisted in the account) and can be switched anytime. A use case is written once and read at three levels. The level is chosen per person, and anyone can switch it. | Level | Who usually reads it | What it shows | | ------------- | ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | **Plain** | the owner, a client, a reviewer | the title, who does it, what they want, how it starts, the steps, how it ends, and what the person is told when something fails | | **Working** | a product person, a designer | plain, plus where it lives (its path), the data it reads and writes, who is allowed, the status | | **Technical** | a programmer, the coding agent | working, plus the input and payload types, the events it emits and listens to, the Sypnorm signature, the tables and their policies, traces from production, the code and pull requests | In Sypnia Cloud the starting level comes from your Sypnia account: the short knowledge test that every product shares tells Cases how much technical detail to show you first ([Agent → Your level](https://agent.docs.sypnia.com/start/your-level)). --- ## Scope and contract > The landing, the plan and the map as one contract; scope errors; versions, proposals and reviews. Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service). Source: https://cases.docs.sypnia.com/contract/ For agents: The project contract = the approved landing page (what is promised), the plan (how and in what order) and the approved map version (every flow). Anything built that no case describes is a scope error; the fix is a map proposal, approved before the code. Pages: the-contract, scope-errors, the-check, versions-and-reviews. A project needs one answer to _«what are we building?»_. In Sypnia that answer is a contract of three documents, and the map is the one code is checked against. --- ## The contract > The landing page, the plan and the map form one contract, and must agree. Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service). Source: https://cases.docs.sypnia.com/contract/the-contract/ For agents: Contract documents: landing (public promise, every promise maps to at least one case via `promises` in map.yaml), plan (cases/plan.md: every `##` heading is a milestone; its cases in the heading `(cases: a, b)` or on a `Cases: a, b` line under it; delivered when the heading says `delivered` or ✓, or a line under it says `Delivered: ` or `Status: delivered`), map (approved version). Rules: every landing promise has cases; every case in a milestone exists in the map; the map's approved version is the scope. `cases check` reports `unbuilt` (an approved case of a delivered milestone with no code; status idea or retired skipped) and `invalid` for a milestone naming a case with no file; `--contract` also reports `broken-promise` for a landing promise or a milestone that names no case. The Cases server runs the check on every proposal, without the plan, which stays in the repository. In a Sypnia project, three documents say what is being built: | Document | What it says | Who reads it | | -------------------- | ----------------------------------------------------------- | ----------------------------------------- | | **The landing page** | What the app promises to the people who will use it | everyone, in public | | **The plan** | In what order things are built, and what each step delivers | the team and the client | | **The map** | Every flow, as use cases | the team, the client, the code, the agent | They are one contract because they must agree: - **Every promise on the landing has cases.** The map lists the landing's promises and the cases behind each one. A promise without cases is a promise nobody will build. - **Every step of the plan names cases.** A milestone delivers a list of case ids. A milestone that names no case delivers nothing anyone can check. - **The approved map is the scope.** What the code does must be in it. `cases/map.yaml (promises)` ```yaml promises: - text: Order today, pick up warm cases: [place-order, pick-up-order] - text: Know when your order is ready cases: [order-ready-notice] ``` ### The plan `cases/plan.md` ```markdown ## Milestone 1 — Orders (cases: see-today-menu, place-order, see-my-orders) ✓ Delivered: 2026-11-10 ## Milestone 2 — Pick-up Cases: pick-up-order, mark-picked-up, order-ready-notice ``` Every `##` heading of `cases/plan.md` is a milestone. Its cases go in the heading, `(cases: a, b)`, or on a `Cases: a, b` line under it. A milestone is delivered when its heading says `delivered` or ✓, or a line under it says `Delivered: ` or `Status: delivered`. `npx @sypnia/cases check` reads the plan with the map and the code. An approved case of a delivered milestone that has no code is `unbuilt` (a case whose `status` is `idea` or `retired` is skipped), and a milestone that names a case with no file is `invalid`. With `--contract`, it also reports `broken-promise`: a landing promise with no cases, or a milestone that names no case ([The check](https://cases.docs.sypnia.com/contract/the-check)). The Cases server runs the check on every proposal; the plan stays in your repository, and `cases pull` never overwrites it. --- ## Scope errors > What counts as out of scope, why it is an error, and the only way to fix it. Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service). Source: https://cases.docs.sypnia.com/contract/scope-errors/ For agents: Scope error kinds: unmapped (code implements a use case no case describes), unbuilt (an approved case in a delivered milestone has no code), drift (code and case disagree on data written, outcomes, failures or allowed actors), broken promise (landing promise without cases). Fix: change the map first via a proposal; never silence the check except with an explicit, reviewed waiver in map.yaml. A **scope error** is a difference between what the contract says and what the code does. It is an error, not a warning, because every one of them is a surprise for someone: a client who gets what nobody agreed, or one who does not get what was promised. | Kind | What happened | Example | | ------------------ | ----------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | **Unmapped** | The code does something no case describes | a «gift card» use case appears in the code; the map has no gift cards | | **Unbuilt** | An approved case in a delivered milestone has no code | _order-ready-notice_ is in milestone 2, which is marked delivered | | **Drift** | The code and the case disagree | the case says it writes `order`; the code also writes `customer_points`, or ends in an outcome the case does not declare | | **Broken promise** | The landing promises something with no cases | «Pay online» on the landing, no payment cases | The check reports other errors too, about the map itself: a case nothing can start, a place that does not exist, a loop with no stop. Those are mistakes in the map, not differences between map and code; the full list is in [The check](https://cases.docs.sypnia.com/contract/the-check#every-finding). ### The only fix Change the map first, on purpose: a **proposal** that adds the gift cards, or removes the promise, or updates the case's data. When it is approved, the code is in scope again. The check never asks you to change code to match a map nobody approved. ### Waivers Some differences are fine for a while: an internal admin script, a case kept for one more release. A waiver says so, in the map, with a reason and an end date, and it is reviewed like any change: `cases/map.yaml (waivers)` ```yaml waivers: - kind: unmapped target: rebuild-search-index reason: Internal maintenance job, not a user flow until: 2027-03-01 ``` --- ## The check > What `cases check` compares, where the code side comes from, and what it reports. Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service). Source: https://cases.docs.sypnia.com/contract/the-check/ For agents: `cases check` inputs: the map files (validated with the JSON Schema; navigation tree; event graph), the code side (Sypnorm use cases from `cases map --json`; and code without Sypnorm: `Case: ` trailers of the last 2000 commits and `// case: ` notes in the sources, also with #, /* or