Data and API
The 58-path contract, the 63-table D1 database, and the rules that keep both honest. Read this before adding a route, a table, or a field.
1. The contract
- File of record:
backend/openapi.yaml— 58 paths, byte-identical toserver/openapi.yaml(ADR-9). It is frozen; a cleanup that reformats it is a contract change. - Implementation: 65 handlers over 59 path strings (two paths serve GET+POST),
composed in
backend/src/http/router.ts; each origin owns its module inbackend/src/http/routes/*.ts. - Parity:
backend/test/promises.test.ts(the oldopenapi.test.ts) fails when a route exists without a contract entry, or an entry without a handler. Idempotency-Keyis accepted on mutating routes and honoured (ops_idempotency), but is deliberately not published in the YAML./docsand/swagger.jsonare public on purpose.
1.1 Route modules
| Module | Paths | Domain |
|---|---|---|
account | 4 | config, avatar, erasure, api keys |
applications | 5 | create, list, advance, withdraw, archive |
companies | 5 | directory, notes, enrich, logs |
config | 1 | GET /config → capabilities (what this deployment can actually do) |
health | 1 | GET /health (no auth, no DB write) |
inbox | 5 | replies, notifications, classify, mark read |
jobs | 7 | query, saved, import, export, rank |
logs | 2 | operator log read + client ingest |
outreach | 10 | targets, recruiters, discovery, drafts, accounts, send, resolve |
profile | 8 | read/patch, enrichment, dossier, sources |
resumes | 4 | upload intent, complete, list, signed download |
searches | 5 | create, list, cancel, delete, observe |
sources | 1 | catalogue (+ blocked reasons) |
staging | 2 | probe that refuses to exist in production |
usage | 1 | caps consumed today |
worker | 4 | task claim, ingest, log, complete |
1.2 The envelope
{ "ok": true, "data": { }, "requestId": "…", "demo": true }
{ "ok": false, "error": { "code": "INVALID_INPUT", "message": "…" }, "requestId": "…" }demo: trueis pinnedconst: truein the YAML. It is a v2 decision, not a bug to "fix" in a cleanup pass.- Codes are closed:
INVALID_INPUT·UNAUTHORIZED·NOT_FOUND·CAP_REACHED·STATE_CONFLICT·RATE_LIMITED·UPSTREAM_ERROR. - Unknown query values are refused, not defaulted.
- "Not found" and "could not ask" are different answers (404 vs 502).
2. The database
D1 (SQLite), binding DB, database jobwzrd
(ac3081fd-c1b5-4b89-81c0-3fb8eb70d2da). 29 migration files, 28 applied, 63
tables, ~1.2 MB. Migrations are a ledger (ops_migrations), not textually
idempotent — re-running a file is not how you repair a deployment.
2.1 Tables by owner
| Category | Tables |
|---|---|
| Identity (Better Auth) | auth_user, auth_session, auth_account, auth_verification |
| Profile | profiles, profile_dossiers, profile_links, profile_sources, resumes, blobs |
| Jobs (24 h cache) | corpus_jobs, corpus_companies, corpus_sources, corpus_job_sources, corpus_yc_companies, company_directory, company_enrichment, company_notes |
| Search + scrape | searches, search_sources, search_results, search_ingest_reservations, scraper_board_configs |
| Applications | applications, application_events, saved_jobs, exports |
| Outreach | outreach_targets, outreach_contacts, outreach_fetched_pages, outreach_suppressions, discovery_runs, email_accounts, email_drafts, email_draft_attachments, email_events, email_classifications, notifications |
| Account | user_preferences, api_keys, api_key_windows |
| Ops | ops_* (24): ai_runs, audit_events, cap_ledger, cap_quota, client_budget, consumer_deliveries, dead_letters, dispatch_attempts, dispatch_payloads, dlq_incidents, erasure_jobs, idempotency, log_events, migrations, outbox, rate_windows, scraper_executions, table_policy, upload_intents, worker_tasks |
2.2 Invariants that tests enforce
- Exactly five platform tables may carry a nullable
owner_id:ops_ai_runs,ops_audit_events,ops_outbox,ops_rate_windows,ops_worker_tasks. A sixth failsbackend/test/migrations.test.ts. PRODUCT_TABLES(57) is pinned; adding a product table without updating it fails the suite.- A reservation guard is
UPDATE … WHERE ingest_reserved + ? <= cap … RETURNING— never read-then-write. node:sqlite'srun()discardsRETURNING; the D1 adapter routes everyRETURNINGstatement throughall().- No routine
COUNT(*)overcorpus_jobs; D1 capacity thresholds are percentages ofD1_LIMIT_BYTES. - Indexes precede sweeps. A retention sweep is a bounded page (
PAGE = 500) that reportsremaining: trueand never deletes a row the owner still needs. - Résumés/blobs are never swept (D-GAP-1); they live until account erasure.
3. Caps, budgets and their storage
| Limit | Value | Stored in |
|---|---|---|
| Applications/day | 5 | ops_cap_ledger + ops_cap_quota |
| Emails/day | 50 | same |
| AI global / per user | 30 rpm · 15 000 tpm / 6 rpm · 6 000 tpm | ops_rate_windows, ops_ai_runs |
| Anonymous client | 30/min auth, 120/min public (fails open) | ops_client_budget |
| Ingest reservation | per search + source | search_ingest_reservations |
Every charge is atomic and precedes the external effect. A missing value is never read as zero. A refusal that charged nothing says so.
4. Send, idempotency, and the four outcomes
POST /outreach/send
└ claimDraftForSend preference gate → cap charge → draft: draft→sending
├ Gmail accepted → markSent (email_events outbound) → "sent"
│ └ tracker write failed → "sent_unrecorded" (reported as "sent")
├ provider silent → draft parks "unknown", cap kept → "uncertain"
└ provider failed → releaseFailedSend (cap refunded) → "failed"
POST /outreach/send/resolve ← owner says "it went out" / "it did not"A second click finds the draft already sending and does nothing. unknown never
carries a sentAt.
5. Auth on the wire
- Browser: session cookie (
credentials: 'include'), noAuthorizationheader. - Services:
x-api-key— one key per user, hashed at rest (api_keys), scoped per surface (scrape, apply, ai, email_sync, export). - Scrapers:
x-service-tokenwith a per-surface secret; missing env fails closed, there is no shared fallback token. REAUTH_REQUIREDis not an error code — a dead Gmail token is a state onemail_accounts, surfaced as a re-connect CTA.
6. What "add a field" actually costs
- Migration file + ledger row (
backend/migrations/NNNN_*.sql). - Schema constant /
PRODUCT_TABLESif it is a new table. - Feature code in
features/, mapper that accepts bothid(D1) and_id(Convex legacy rows). - Contract entry in
openapi.yamlonly if the wire changes (and the YAML is frozen — so a wire change is an explicit ADR). - App: service interface + demo implementation + http implementation + store member.
- A test that fails if the field stops flowing.
Anything less is a broken build, and the architecture test will say so.
7. Who calls what (W2, measured 2026-11-25)
node app/scripts/audit-wiring.mjs reads four things from source — every
apiFetch/fetch call site under app/src, the ROUTES table in
backend/src/http/router.ts, the route modules, and openapi.yaml — and
intersects them. The first three lines are the gate; the rest is context.
| Check | Result |
|---|---|
| Endpoints the app calls | 48 distinct (40 through a service, 8 inline in store.tsx/api.ts) |
Registered handlers (router.ts) | 64 |
Published operations (openapi.yaml) | 64 |
| App call with no registered handler | 0 |
| App call outside the contract | 0 |
| Handler not published | 0 |
app/src/services/wiring.test.ts asserts those three zeroes in npm test, so a
page cannot start calling an unserved path without CI saying so.
The 16 operations the app never calls, and why:
Not app traffic by design (9) — GET /health (smoke, status page),
GET|POST /_staging/error-test (ops probe), POST /logs/ingest (workers),
POST /config (owner config write), and the four worker/* paths the scrapers
use (claim, heartbeat, complete, ingest).
Server capability the app does not use (7) — reported, not wired, because each would be new behaviour or a new screen:
| Path | Why the app does not call it |
|---|---|
GET /inbox/categories | Inbox renders category labels from the local taxonomy |
GET /jobs/export | Settings exports client-side (jobsToCSV/jobsToJSON) |
GET /jobs/ranked | /jobs/ranked/ai already falls back to keyword scoring server-side |
GET /profiles/me/dossier | The app reads the same dossier through /profiles/me/enrich |
GET /resumes/me/download | No download affordance exists in Settings yet |
POST /alerts/ack | Notifications are acknowledged with /inbox/notifications/read |
POST /jobs/expand | Prompt 01 is implemented and routed; no UI trigger exists |
Two defects came out of the measurement and were fixed rather than documented
around: configReadRoute (GET /api/v1/config/me) existed as a Route object
that no table registered — it answered "not implemented in this build" while a
file-scanning audit counted it as served — and audit-calls.mjs keyed calls by
method name, so the résumé upload was reported as POST /profiles/avatar/upload-url.