🐦⬛ Mockingbird
Local emulators. Real API contracts.
Run the APIs and databases your application depends on, inside your own process. Deterministic state, vendor-compatible requests, and explicit coverage.
Mockingbird provides stateful emulators for third-party APIs and SQL databases. Use vendor-compatible request and response shapes, persistent in-memory state, and deterministic controls in Node, Bun, browsers, and Workers.
Each emulator is its own npm package. The catalog — names, parity, and what each one covers — is on the docs site.
Quick start
npm install -D @crvouga/mockingbird-service-postgres @crvouga/mockingbird-service-stripe
Build a checkout with a PostgreSQL product catalog and a Stripe payment. Save these three files together, then run bun client.ts (or npx tsx client.ts with Node). The API calls the stripe SDK your application already depends on; in an empty project, install it first.
Data · data.ts
Seed a product catalog and an orders table in the PostgreSQL emulator.
import { Database } from "@crvouga/mockingbird-service-postgres"
export const db = new Database()
db.exec(`
CREATE TABLE products (id text PRIMARY KEY, name text, price integer);
CREATE TABLE orders (id text PRIMARY KEY, product_id text, payment_id text);
INSERT INTO products VALUES ('starter-kit', 'Developer starter kit', 2900);
`)
// Real SQL, in memory. No database server to configure.
console.log(db.query("SELECT name, price FROM products"))
// [{ name: "Developer starter kit", price: 2900 }]
API · api.ts
Read a product, charge it with the Stripe SDK, and persist the order. The emulator answers the SDK in this process.
import Stripe from "stripe"
import { createRuntime } from "@crvouga/mockingbird-service-stripe"
import { db } from "./data.ts"
// The Stripe SDK your application already uses. Only its HTTP client changes:
// requests reach the emulator in this process instead of api.stripe.com.
const emulator = createRuntime()
export const stripe = new Stripe("sk_test_mockingbird", {
httpClient: Stripe.createFetchHttpClient((url: string, init: RequestInit) =>
emulator.fetch(new Request(url, init)),
),
})
export const api = {
async fetch(request: Request) {
if (request.method !== "POST" || new URL(request.url).pathname !== "/orders") {
return Response.json({ error: "Not found" }, { status: 404 })
}
const { productId } = await request.json()
const [product] = db.query<{ price: number }>(
"SELECT price FROM products WHERE id = $1", [productId],
)
if (!product) return Response.json({ error: "Product not found" }, { status: 404 })
const intent = await stripe.paymentIntents.create({
amount: product.price, currency: "usd",
payment_method: "pm_card_visa", confirm: true,
})
if (intent.status !== "succeeded") {
return Response.json({ paymentStatus: intent.status }, { status: 402 })
}
const orderId = crypto.randomUUID()
db.prepare("INSERT INTO orders VALUES ($1, $2, $3)").run(orderId, productId, intent.id)
return Response.json({ orderId, paymentStatus: intent.status }, { status: 201 })
},
}
Client · client.ts
Place an order through the application's Fetch handler. The whole flow stays local.
import { api } from "./api.ts"
// The same Request / Response interface your client already uses.
export const response = await api.fetch(new Request("http://app.local/orders", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ productId: "starter-kit" }),
}))
export const order = await response.json()
console.log(response.status) // 201
console.log(order.paymentStatus) // "succeeded"
// Product read → payment confirmed → order saved.
// PostgreSQL + Stripe + your API, without a single network request.
Every package is self-contained ESM with TypeScript types. Every emulator is isomorphic and runs in Node >= 22, Bun >= 1.2, browsers, and Workers. Browse every emulator, with a live playground, on the docs site.
Why Mockingbird
- The vendor's real surface. Each emulator answers the provider's own paths, headers, status codes and error envelopes through
fetch(Request) → Response. Point the official SDK at it. - State that behaves. Records persist in an in-memory SQL engine. Created customers can be listed, orders move through their lifecycle, webhooks fire, and reset or snapshot takes one call.
- Checked against the real thing. Random walks generated from each vendored OpenAPI contract run against two emulator instances in CI, and against the live sandbox when credentials exist.
- No network, no waiting. Everything runs in your test process. No sandbox keys, rate limits, shared test accounts or flaky round trips.
- Runs anywhere JavaScript runs. Every emulator is isomorphic: the same package runs in Node, Bun, browsers, and Workers. The playgrounds on this site run that package in your browser tab.
- One set of controls for every service. Every HTTP emulator takes the same admin controls: isolation by key, reset, snapshot and restore, time travel, faults, latency and timeouts, all replayed from a seed. Set them at boot, through
/__admin, or in a request header.
The full rationale, and when not to use it: docs/WHY.md.
Admin controls
Put any emulator in any state. Then do it again.
Every HTTP emulator answers the same admin controls. Isolate state by key, reset it, snapshot and restore it, move the clock, and inject faults, latency and timeouts. Each one is a field in a single document that means the same thing at boot, over /__admin, and in a request header, and all of it replays from a seed.
- Isolation by key.
x-mockingbird-namespace: worker-3gives a request its own records, clock, random streams, faults, latency, journal and snapshots. Parallel workers share one process and never see each other. - Reset.
POST /__admin/resetreturns a namespace to its boot state: seed data, clock, faults and ids. A reset namespace cannot be told apart from a new one. - Snapshot and restore.
POST /__admin/snapshotscaptures records, the clock, the random streams and the fault counters. Restore it, export it as JSON, commit it, or boot another process from it. - Time travel. Freeze the clock, set it, or advance it by
15m. Expiries and retry windows arrive in milliseconds. Read state as it was at any checkpoint, or branch from one. - Faults. Answer
503, drop the connection, or cut a response off mid-body. Match by operation, path or header; fire on the third request, every fifth, for the next five minutes, or at a seeded rate. - Latency and timeouts. Give every response a delay with seeded jitter, or make one request hang. With
virtualTimethe wait is spent on the mock clock, so a thirty-second timeout costs no test time.
At boot:
const stripe = createRuntime({
seed: 7,
adminControls: {
clock: {
now: "2030-01-01T00:00:00Z",
frozen: true,
},
latency: "40ms",
faults: [{ preset: "rate_limited" }],
},
})
Over /__admin:
curl -X POST :8787/__admin/snapshots \
-d '{"name": "base"}'
curl -X POST :8787/__admin/clock \
-d '{"advance": "15m"}'
curl -X POST :8787/__admin/faults \
-d '{"status": 503, "count": 2}'
curl -X POST :8787/__admin/snapshots/base/restore
In a request header:
POST /v1/charges
x-mockingbird-namespace: worker-3
x-mockingbird-time: 2030-01-01T00:00:00Z
x-mockingbird-fault: status=503; delay=2s
The same seed and the same requests give the same bytes: ids, timestamps, which requests a rate fault hits, and the request journal. Reset and restore rewind the random streams with the state, so a test passes or fails the same way whether it runs first or last, alone or beside forty workers.
Start at docs/ADMIN_CONTROLS.md. Each control has its own page, with its routes, body fields, headers, boot options and errors:
| Control | |
|---|---|
| Namespaces | A namespace is an isolation key. Each key has its own records, clock, random streams, faults, latency, journal, metrics and snapshots, so parallel test workers share one emulator without seeing each other. |
| Reset | Reset returns a namespace to exactly the state it booted in: records, ids, clock, seed, faults, latency, snapshots, journal and metrics. A reset namespace cannot be told apart from a new one, which is what makes a test independent of the tests before it. |
| Snapshot and restore | A snapshot is a saved copy of a whole namespace. Take one after setting up the state a test needs, and restore it before each test: the namespace goes back to exactly that state, so the requests that follow give the same responses every time. |
| Clock | Every timestamp an emulator writes reads from its clock. Set it, freeze it or move it, and expiries, retry windows and renewals arrive in milliseconds instead of being waited for. |
| Checkpoints and branches | Every successful write checkpoints the namespace. Read the namespace as it was at any checkpoint, or branch from one and take a different path, without touching the main line. |
| Faults | A fault makes the emulator fail on purpose: answer 503, drop the connection, cut a response off mid-body, or hold it back. It is how a test reaches a vendor's failure modes without the vendor. |
| Latency and timeouts | Make responses slow, or make them never arrive. Latency is how long every request takes; a timeout holds a request and then drops it. With virtual time, the waits are spent on the mock clock and cost no test time. |
| Seed and determinism | Given the same boot controls and the same requests in the same order, an emulator answers the same bytes: ids, timestamps, which requests a fault hits, jitter, and the journal. The seed is what fixes every random choice. |
| The control document | Every control is described once, as JSON. The same document boots an emulator, is read and written over the admin API, and is what the request headers stand for. This page is its schema. |
| Boot | An emulator starts with whatever controls you give it. That starting point is also what a reset returns to. |
| Request headers | A request can carry its own controls. Nothing needs to be set up first, and a client that can only set default headers still reaches every control. |
| Journal, metrics and state | Three ways to see what an emulator did and what it holds: the journal lists every request it received, metrics count them, and state reads and edits the stored rows directly. |
| Reference | Every admin route, every control header, the error shape and how access is guarded, on one page. Each row links to the page that defines it. |
One contract for every HTTP service
Every HTTP service ships an in-process fetch, a Node server and a CLI, and all answer the same control surface, so a stack learns it once. Every internal path is under /__admin by default. Set adminPrefix or serve --admin-prefix (MOCKINGBIRD_ADMIN_PREFIX) to relocate the entire tree; /health and /ns aliases are removed.
npx mockingbird-junction serve --port 8787 # one service
npx mockingbird-junction serve --config mockingbird.json # every service in the config
| Surface | What it gives you |
|---|---|
createRuntime() · createServer() (./server) · mockingbird-<service> serve |
The emulator as one runtime-neutral fetch, or a listening server from Node or the CLI |
GET /__admin/health |
Unauthenticated readiness probe, outside the vendor's auth gate |
/__admin/* (x-mockingbird-admin-key optional) |
The admin controls: reset, snapshot and restore, clock, faults, latency, a request journal, metrics with unmatched-route counts, plus service-specific routes. GET /__admin lists every route and header |
GET /__admin/state |
The collections in the selected namespace: declared shape, live Collection fields, and stored rows. Create, replace, merge, and delete records through the same paths on every emulator |
GET /__admin/ui |
The shared admin UI. An emulator can add panels or replace the document; the shell still reads the same state API. Its header fetches that service's logo, website, and docs from the docs site when the page opens |
x-mockingbird-namespace |
Per-request isolation: parallel workers share one process without sharing data, clocks, faults or ids |
adminControls · --admin-controls · x-mockingbird-* |
The same control document at boot, on the command line, and in request headers |
--seed, a frozen clock, virtualTime |
Seeded randomness, a clock that moves only when told to, and waits that cost no time, so a run replays byte for byte |
--log json |
One structured line per request: operation id, status, duration, namespace, fault |
{
"services": {
"junction": { "port": 8787, "options": { "corpus": "./test/junction-corpus.json" } },
"stripe": { "port": 0 },
"postgres": { "protocol": "postgres", "port": 0 },
"redis": { "protocol": "redis", "port": 0 }
}
}
mockingbird.json names services by their package suffix. HTTP services, PostgreSQL and Redis share a supervisor with ephemeral ports, readiness discovery and namespace controls. Use --ready-file or --ready-json to discover endpoints; see Fleets. SQLite remains an in-process engine.
For coding agents
Every npm package ships an agent index at node_modules/<package>/DISCOVERY.md. It points to the local behavior guide, exact capability matrix, machine-readable contract or compatibility evidence, public types, parity oracle, runtime introspection, and issue-reporting contract. llms.txt indexes those files with the parity each service declares, and the docs site publishes the same source material as markdown and JSON. When an emulator diverges from the real API, lacks a feature you call, or the vendor you need is not in the catalog, file an issue: the filing guide gives the title format, templates and the behavior spec for feature and service requests.
Contributing
git clone https://github.com/crvouga/mockingbird.git && cd mockingbird
bun run setup # install, build every package, create .env.local
bun test
Building, testing and bun run check need no secrets and no accounts. Live parity against the real provider sandboxes runs on GitHub Actions with the repo's secrets, so anyone with write access runs it without holding a key: bun run parity:remote -- <service>. See docs/DEVELOPMENT.md and docs/SECRETS.md.
Guides
| Guide | |
|---|---|
| Getting started | Install a Mockingbird emulator, create a runtime, and send vendor-compatible requests. Each service is a self-contained TypeScript package with its own coverage matrix and integration guide. |
| Admin controls | Every Mockingbird HTTP emulator answers the same controls: isolate state by key, reset it, snapshot and restore it, move the clock, inject faults, latency and timeouts, and replay all of it from a seed. They are the same on every emulator, and the same whether you set them at boot, call the admin API, or send a request header. |
| Why Mockingbird | Mockingbird gives applications local, stateful emulators for the vendor APIs and databases they depend on. Run integrations inside your process, control the state and clock, and inspect exactly which vendor operations each emulator supports. |
| Testing and parity | How every emulator is proven to behave like its vendor: differential contracts, property-based walks, and live parity against real sandboxes. |
| Authoring a Mockingbird service | How to add a vendor emulator to this repo. The reference implementation is packages/service/rxvortex: copy its layout and patterns. |
| Developing Mockingbird | Working on this repo: requirements, how the packages are layered, and the quality gates every change passes. |
| Design | Mockingbird is a developer toolkit for local API and database emulation. Its documentation uses neutral surfaces, clear navigation, technical examples, and explicit coverage. The project name stays Mockingbird; describe each service as an emulator. |
| Reporting issues | How coding agents in other projects file a GitHub issue when an emulator diverges from its oracle, lacks a feature they call, or breaks, or when they need |
