# map.json schema

> The spec that tells kavach map how your service is built, so recorded steps land on cards named after your own code.

A `map.json` spec (`"kavach_map": 1`) describes your service as **nodes** (entry points, functions, state, sinks, invariants, known bugs) and **edges**, and says which recorded inputs, outputs and failures belong to which node. `kavach map` binds every recorded step onto it. Without a spec, Kavach builds an automatic map from the fixtures alone.

The file is decoded strictly: unknown fields are an error.

```json
{
  "kavach_map": 1,
  "title": "Wallet ledger",
  "summary": "Folds wallet events into balances.",
  "service": "ledger",
  "groups": [
    { "id": "entries", "title": "Inputs", "plain": "Entry points", "code_base": "https://github.com/org/repo/blob/<sha>/" }
  ],
  "nodes": [
    {
      "id": "in_deposit",
      "group": "entries",
      "kind": "entry",
      "title": "deposit",
      "plain": "Upstream credits an account.",
      "code": ["internal/ledger/handle.go:42-60"],
      "match": [{ "on": "input", "source": "kafka:wallet-events", "json": { "type": "deposit" } }]
    },
    {
      "id": "inv_non_negative",
      "kind": "invariant",
      "title": "Balances never negative",
      "invariant": "balances_non_negative"
    }
  ],
  "edges": [
    { "from": "in_deposit", "to": "fn_handle", "kind": "calls" }
  ],
  "flows": [
    {
      "id": "bug-null-amount",
      "title": "Null amount crash",
      "fixture": "null-amount.kavach",
      "steps": [{ "node": "in_deposit", "text": "A deposit arrives with amount: null." }]
    }
  ],
  "money": { "fields": ["amount", "balance"], "minor_units": 2, "currency": "USD" },
  "step_names": { "null-amount": { "1": "Fund alice", "32": "Bad event" } }
}
```

## Top level

| Field | Required | Meaning |
| --- | --- | --- |
| `kavach_map` | yes | Always `1`. |
| `title`, `summary` | | Shown at the top of the map. |
| `service` | | The service name, as in fixtures. |
| `groups` | | Columns of cards. |
| `nodes` | yes | The cards. |
| `edges` | | Connections between cards. |
| `flows` | | Guided walkthroughs, each tied to a fixture. |
| `money` | | Show amounts as currency. |
| `step_names` | | Human names for steps on the replay tape. |

## Groups

`id`, `title`, `plain` (a plain-English label) and optional `code_base`. When `code_base` is set, a node's `code` entries become links: `path:12-30` expands to `<code_base>/path#L12-L30`.

## Nodes

| Field | Meaning |
| --- | --- |
| `id` | Unique identifier, referenced by edges and flows. |
| `group` | The group it sits in. |
| `kind` | `entry`, `function`, `state`, `sink`, `invariant`, `bug`, `external` or `note`. |
| `title`, `plain`, `detail` | Name, one-line summary, longer note. |
| `code` | Source locations: `"path"`, `"path:12"` or `"path:12-30"`. |
| `invariant` | Required when `kind` is `invariant`: the declared invariant's name. |
| `match` | Rules binding recorded steps to this node. |

### Match rules

Fields inside one rule are ANDed; multiple rules on a node are ORed.

| Field | Meaning |
| --- | --- |
| `on` | `input`, `output` or `failure`. Inferred when omitted: `sink` → output, `source`/`position` → input, `kind` → failure. |
| `source`, `position` | Input source and position. A `position` ending in `*` is a prefix match. |
| `sink` | Output sink. |
| `kind` | Failure kind. |
| `json` | Dot path → scalar, matched against the parsed JSON payload. |
| `contains`, `regex` | Tested against raw bytes, or the failure message. |

An `invariant` node with `match` rules is marked `fail` on any step it matches, which lets a map flag invariant violations that a host reports inside an output or error message.

## Edges

`from`, `to`, optional `label`, and `kind`: `calls`, `reads`, `writes`, `emits`, `checks`, `breaks` or `flows` (the default).

## Flows

`id`, `title`, `plain`, the `fixture` it walks through, and `steps`, each a `node` and `text`.

## Money

`fields` names the fields holding integer amounts in minor units; `minor_units` and `currency` say how to show them. `2050` with `minor_units: 2` and `USD` shows as `$20.50`. Known codes get a symbol; others are shown as a prefix (`CHF 19.99`).

## Step names

Maps a fixture, by base name without `.kavach`, to names keyed by input `seq`.

## Overlays

An overlay file (`"kavach_map_overlay": 1`, passed with `--overlay`) adds a tab of horizontal stage chains, such as a shadow pipeline's stages, linked back to map nodes and fixtures. Overlays with the same `mode` merge into one tab.

Source: https://www.thekavachlabs.com/docs/reference/map-json
