# Request paths

> What happens, step by step, for a proposal, an approval, a check and a link.

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

For agents: Proposal: POST /proposals → validate the changes against the latest version plus the proposal (422 invalid_map with errors[]) → store rows (approved version untouched) → named reviewers get an e-mail from mail_outbox through CASES_SMTP_URL, retried with backoff. Approval: POST /approve → role check → row lock on the proposal → role checked again → required_approvals.count (default 1) approvals from owners or approvers plus every required named reviewer? → in one transaction: new immutable version, case snapshot rows, proposal merged; a proposal on an older base merges when no case it touches changed, else 409 version_conflict (also when another approval won the version number) → job writes the files to the repository (commit) → event map.version.created. Check: POST /checks → load approved version → compare with the code side (or caseIds alone) → findings, last result kept per map and version. Links: GET /links → parallel reads to Data/Telemetry/Git/Agent as the caller (Sypnia Cloud: a service call to the Data control plane with the verified person's id; Telemetry with the map's linked token; self-hosted: the caller's own token), 2 s budget each (CASES_LINK_BUDGET_MS), not_available when one does not answer. Upload to Data: map --upload --project <data ref> → PUT /v1/projects/{ref}/use-cases on the Data control plane (kept for «Use cases») → when linked, forwarded as a service call to POST /v1/maps/{map}/uploads → a draft proposal; a forward Cases does not take is not retried, the Data side stays saved.

## A proposal

1. `POST /v1/maps/{map}/proposals` with the changes.
2. The server applies them to the latest version and validates the result against the format: every changed case, and that every reference exists. What they would break answers 422 `invalid_map`, with `errors[]`.
3. It stores the proposal and its changes as rows; the approved version is untouched.
4. The reviewers named on the proposal get an e-mail. E-mails wait in the server's own outbox and go out through your SMTP server (`CASES_SMTP_URL`), retried with a growing wait; on AWS Lambda, the jobs function sends the ones that are due every minute.

## An approval

1. `POST /v1/proposals/{id}/approve`: the server checks the caller's role.
2. It locks the proposal's row, so approvals of one proposal happen one at a time, and checks the role again inside that transaction.
3. A proposal merges when it has the approvals the map asks for (`required_approvals.count`, 1 by default) from owners or approvers, **and** the approval of every required reviewer named on it. The author may approve their own proposal.
4. Then **one database transaction** creates the new version (immutable), snapshots its cases and marks the proposal merged. A proposal made on an older version merges on its own when no case it touches changed since its base; otherwise the answer is 409 `version_conflict`, and it must be rebased. Two approvals racing for the same version number cannot create two versions: the number is unique per map, and the one that loses gets 409 `version_conflict`.
5. A background job writes the new files to the connected repository as one commit (`Cases: version 5 — Gift cards`).
6. An event `map.version.created` is published for other products (Agent picks up new scope, Git updates links).

## A check

1. `POST /v1/maps/{map}/checks` with the code side, or with `caseIds` alone (from commit trailers: the map is checked by itself, and an id it does not have is reported as `unmapped`).
2. The server loads the approved version and compares (the same code as `cases check`, from `@sypnia/cases/spec`).
3. It returns the findings and keeps the last result per map and version.

## A link

1. `GET /v1/maps/{map}/cases/{case}/links`.
2. The server calls Data, Telemetry, Git and Agent **in parallel**, **as the caller**, so you never see through Cases what you cannot see in the product. In Sypnia Cloud, Data is read through a service call to its control plane, with the id of the person the server verified, and the control plane checks that person's role; Telemetry with the read token linked to the map. A server you run yourself presents the caller's own token.
3. Each call has a 2-second budget (`CASES_LINK_BUDGET_MS`); a product that does not answer in time is marked `not_available` and the rest is shown.

## A map uploaded to Data

1. `npx @sypnia/cases map --upload --project <data ref>` sends the map document to Sypnia Data's control plane (`PUT /v1/projects/{ref}/use-cases`), which keeps it for the console's «Use cases».
2. When the Data project is linked to a Cases map, the control plane sends the same document on to `POST /v1/maps/{map}/uploads`, as a service call on behalf of the person who uploaded it.
3. The Cases server turns it into a draft proposal of what the code owns ([The map from code](https://cases.docs.sypnia.com/format/from-code#what-an-upload-proposes)) and answers with the proposal; the control plane passes that answer back to the CLI. If Cases does not answer, the Data side is still saved.
