# Flow maps

> Render one interactive HTML page showing how events flow through your service, which step failed, and what a fix changed. Or serve it live as fixtures arrive.

`kavach map` turns fixtures into a single self-contained HTML file you can open, attach to an incident or send to a reviewer. It shows how events flow from entry points through handlers, state and sinks to invariant checks, with each recorded step and each replay laid over that flow.

## From a fixture alone

```bash
kavach map incident.kavach -o incident-map.html
```

With no spec, Kavach builds an automatic map from what the fixture recorded: its inputs, outputs, invariants and failures. No host binary is needed.

## With replays and a fix

```bash
kavach map incident.kavach --bin ./service-old --new ./service-new -o map.html
```

`--bin` replays each fixture on the old build and `--new` on the candidate. The map then marks where the two builds diverge, which invariants each step passed, and the step where each first fails. Attach `kavach diff --json` reports with `--diff` to add variant tallies by mutation kind and invariant.

```bash
kavach diff incident.kavach --old ./service-old --new ./service-new --json > diff.json
kavach map incident.kavach --bin ./service-old --new ./service-new --diff diff.json -o map.html
```

## With a spec of your code

A `map.json` spec names the parts of your service (entry points, functions, state, sinks, invariants and known bugs), how they connect, and which inputs and outputs belong to each. Kavach binds recorded steps onto those cards, so the map reads like your architecture rather than a list of records.

```bash
kavach map .kavach/plan/map.json testdata/*.kavach --bin ./service -o map.html
```

Add source excerpts and patches to the cards:

```bash
kavach map .kavach/plan/map.json incident.kavach --bin ./old --new ./new \
  --source ./ --patch fix.diff -o map.html
```

`--source DIR` (or `GROUP=DIR` for one group of the spec) shows code excerpts for the lines each card names. `--patch FILE` attaches a unified diff's hunks to the cards they touch. See the [`map.json` reference](https://www.thekavachlabs.com/docs/reference/map-json) for the schema; the [`/kavach-setup`](https://www.thekavachlabs.com/docs/guides/ai-agents#the-five-skills) skill writes a first `map.json` for you.

## Live

Watch a recorder or fixtures directory and serve a map that updates as fixtures arrive:

```bash
kavach map .kavach/plan/map.json --watch ./kavach --listen 127.0.0.1:8090
```

Open `http://127.0.0.1:8090`. The page refreshes itself, keeping your tab, selection, search and zoom. `--interval` sets how often the directory is polled (default `500ms`). The server also exposes:

| Path | What |
| --- | --- |
| `/` | The live map. |
| `/api/model` | The current map model as JSON. |
| `/api/events` | Server-sent events: one `update` per change. |

## Invariant status on the map

| Step outcome | Declared invariants | Undeclared ones |
| --- | --- | --- |
| `ok` or `diverged` | `pass` | `unknown` |
| failed invariant `X` | before `X`: `pass`; `X`: `fail`; after: `unknown` | `X`: `fail` |
| `panic`, `error`, `crash`, `timeout` | `skipped` (invariants run only after an ok step) | `unknown` |
| `nondeterministic` | `unknown` | `unknown` |
| not reached | `not_reached` | `not_reached` |

## Options

| Flag | Meaning |
| --- | --- |
| `-o FILE`, `--out FILE` | Output HTML. Default `kavach-map.html`. |
| `--json` | Print the map model as JSON instead of HTML. |
| `--title T` | Override the map title. |
| `--max-data N` | Bytes of payload preview per input or output. Default `512`; `0` omits payloads. |
| `--overlay FILE` | Add a stage-overlay tab (for example, a shadow pipeline). Repeatable. |

Payloads are trimmed to `--max-data`, so a map shares what you choose to share. Use `--max-data 0` when inputs contain data that should not leave the team.

Agents can build maps too, through the `kavach_map` [MCP tool](https://www.thekavachlabs.com/docs/reference/mcp).

Source: https://www.thekavachlabs.com/docs/guides/flow-maps
