apiflow

shipped CI replays this transcript on every push. It passes.

Did the build match the contract?

apiflow check re-scans your source and compares the result to the map you committed. That answers one question — did the code move under the map — and it needs the source to exist.

apiflow diff compares two map files and nothing else. No source, no scanner, no rule about where the maps came from. That opens the case check cannot take: a map written before the source, used as the contract the build is then measured against.

The map that does not have source yet

Sketch the API you are about to build as an .apimap and mark the generator as your own:

$ printf '%s' '{"version":1,"metadata":{"name":"users-api","root":"github.com/junixlabs/apiflow//fixtures/demo-app/api","generator":"hand-written/1"},"screens":[],"endpoints":[{"id":"ep_get-users","method":"GET","path":"/users"},{"id":"ep_get-users-param","method":"GET","path":"/users/{param}"},{"id":"ep_post-users","method":"POST","path":"/users"}],"fields":[],"calls":[],"reads":[],"unresolved":[]}' > $TMP/design.apimap

All six collections — screens, endpoints, fields, calls, reads, unresolved — have to be there, even when empty. Leaving one out is refused by name at parse time rather than surfacing later as a crash inside a query.

check will not look at it, and says so rather than guessing:

$ apiflow check $TMP/design.apimap
Cannot check a map generated by hand-written/1.

That refusal is correct — check re-scans a side, and a hand-written map has no side to re-scan. It is also why the contract needed a second command.

Diff it against what got built

fixtures/demo-app/maps/api.apimap is the real scan of this repo’s fixture API, committed and re-derived by CI. Treat it as the build, and the sketch above as the contract:

$ apiflow diff $TMP/design.apimap fixtures/demo-app/maps/api.apimap
## apiflow diff
**Verdict**: the two maps have diverged — The same number of endpoints, but not the same endpoints.
### In the after map, missing from the before map — 1
- `DELETE /users/{param}`
### In the before map, gone from the after map — 1
- `POST /users`
### Changed — auth gate or declaring side — 2
- `GET /users`
- `GET /users/{param}`
**Screens**: 0 → 0
**Calls**: 0 → 0
**Fields**: 0 → 0
**Reads**: 0 → 0
**Unresolved**: 0 → 3

Three answers, none of which a count would have given you. The build grew a DELETE nobody designed. The POST /users the contract promised is not there. And both surviving endpoints changed: the contract said nothing about their auth gate, the scan found one.

The headline earns its keep here. Three endpoints before, three after — every count in the panel is flat except Unresolved. A headline built on counts would have called that “no meaningful change” while printing the two routes that were swapped underneath it.

Using it as a gate

diff exits 1 when the counted surface differs and 0 when it does not, so it drops into CI next to your other checks:

- run: npx apiflow scan-be . --out=built.apimap
- run: npx apiflow diff contract.apimap built.apimap

Exit 2 is separate on purpose: it means no verdict — a missing file, an unparseable map, a missing argument. A CI step that treats every non-zero exit as drift will report an unreadable path as a broken contract.

What the gate can see is the counted surface: endpoints by method and path, and how many screens, calls, fields, reads and unresolved entries each map holds. It does not compare which fields, so exit 0 means “nothing I count moved”, not “these files are the same”. When the counts match but the bytes do not, the output says so rather than claiming a match.