A Four-Week Plan for Introducing API Review on a Library
Accidental breaking changes usually slip through because nobody was looking at the public surface specifically; reviewers were looking at logic. An API review step fixes that by making every change to exported names, signatures and types visible and deliberate. Here is an illustrative four-week rollout for a team maintaining one or more libraries. Stretch or compress it to fit.
Week 1: define and snapshot the surface
- Agree in writing what counts as public: root exports, documented entry points, error types, configuration keys.
- Generate a machine-readable snapshot of the current surface and commit it. For TypeScript, a tool such as API Extractor produces a report file from the declarations. For Rust, cargo-semver-checks compares against the last published release. For Python, a stub file or a list produced from
__all__is a reasonable start. - Mark internal modules clearly: an
internaldirectory in Go, a leading underscore in Python, unexported paths in anexportsmap.
Done when: there is one committed file a reviewer can read to see the whole public API.
Week 2: make changes visible in CI
- Add a CI step that regenerates the snapshot and fails if it differs from the committed one.
- When the check fails, the contributor updates the snapshot in the same pull request. The diff of that file is now the API change, isolated from implementation noise.
- Add a pull request template line: "Public API change? none / additive / breaking".
# illustrative CI step
- run: npm run build
- run: npx api-extractor run # fails if the report changed
Done when: no pull request can change the surface without touching the snapshot file.
Week 3: set the review rules
| Kind of change | Rule |
|---|---|
| Additive (new export, new optional field) | One API owner approves naming and shape |
| Breaking | Two approvals, a deprecation already shipped, and a migration note drafted |
| Experimental entry point | Normal review; clearly labelled as unstable in docs |
Use a CODEOWNERS entry on the snapshot file so the right people are requested automatically. Keep the group of API owners small but more than one person.
Week 4: practise and adjust
Run the process on real pull requests and hold a short retrospective at the end of the week. Typical adjustments: excluding generated files from the snapshot, adding a fast path for documentation-only changes, and writing a one-page naming guide so reviews stop relitigating the same questions.
Pitfalls to expect
- Snapshot fatigue. If the file changes on every pull request, it is capturing too much. Narrow it to genuinely public items.
- Review as gatekeeping. The goal is a second look at names and shapes, not blocking contributors. State a response time.
- Behaviour changes the snapshot cannot see. A function with the same signature can still change what it returns. Keep "behaviour change" as a checkbox in the template and record it in the changelog.
- Skipping the release side. Feed the "breaking" label into your versioning tool so the bump matches the review.
Background: the API surface web read and semver policy briefing.