Skip to Content
JobWzrd Docs

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 to server/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 in backend/src/http/routes/*.ts.
  • Parity: backend/test/promises.test.ts (the old openapi.test.ts) fails when a route exists without a contract entry, or an entry without a handler.
  • Idempotency-Key is accepted on mutating routes and honoured (ops_idempotency), but is deliberately not published in the YAML.
  • /docs and /swagger.json are public on purpose.

1.1 Route modules

ModulePathsDomain
account4config, avatar, erasure, api keys
applications5create, list, advance, withdraw, archive
companies5directory, notes, enrich, logs
config1GET /config → capabilities (what this deployment can actually do)
health1GET /health (no auth, no DB write)
inbox5replies, notifications, classify, mark read
jobs7query, saved, import, export, rank
logs2operator log read + client ingest
outreach10targets, recruiters, discovery, drafts, accounts, send, resolve
profile8read/patch, enrichment, dossier, sources
resumes4upload intent, complete, list, signed download
searches5create, list, cancel, delete, observe
sources1catalogue (+ blocked reasons)
staging2probe that refuses to exist in production
usage1caps consumed today
worker4task claim, ingest, log, complete

1.2 The envelope

{ "ok": true,  "data": { }, "requestId": "…", "demo": true }
{ "ok": false, "error": { "code": "INVALID_INPUT", "message": "…" }, "requestId": "…" }
  • demo: true is pinned const: true in 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

CategoryTables
Identity (Better Auth)auth_user, auth_session, auth_account, auth_verification
Profileprofiles, 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 + scrapesearches, search_sources, search_results, search_ingest_reservations, scraper_board_configs
Applicationsapplications, application_events, saved_jobs, exports
Outreachoutreach_targets, outreach_contacts, outreach_fetched_pages, outreach_suppressions, discovery_runs, email_accounts, email_drafts, email_draft_attachments, email_events, email_classifications, notifications
Accountuser_preferences, api_keys, api_key_windows
Opsops_* (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 fails backend/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's run() discards RETURNING; the D1 adapter routes every RETURNING statement through all().
  • No routine COUNT(*) over corpus_jobs; D1 capacity thresholds are percentages of D1_LIMIT_BYTES.
  • Indexes precede sweeps. A retention sweep is a bounded page (PAGE = 500) that reports remaining: true and 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

LimitValueStored in
Applications/day5ops_cap_ledger + ops_cap_quota
Emails/day50same
AI global / per user30 rpm · 15 000 tpm / 6 rpm · 6 000 tpmops_rate_windows, ops_ai_runs
Anonymous client30/min auth, 120/min public (fails open)ops_client_budget
Ingest reservationper search + sourcesearch_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'), no Authorization header.
  • 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-token with a per-surface secret; missing env fails closed, there is no shared fallback token.
  • REAUTH_REQUIRED is not an error code — a dead Gmail token is a state on email_accounts, surfaced as a re-connect CTA.

6. What "add a field" actually costs

  1. Migration file + ledger row (backend/migrations/NNNN_*.sql).
  2. Schema constant / PRODUCT_TABLES if it is a new table.
  3. Feature code in features/, mapper that accepts both id (D1) and _id (Convex legacy rows).
  4. Contract entry in openapi.yaml only if the wire changes (and the YAML is frozen — so a wire change is an explicit ADR).
  5. App: service interface + demo implementation + http implementation + store member.
  6. 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.

CheckResult
Endpoints the app calls48 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 handler0
App call outside the contract0
Handler not published0

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:

PathWhy the app does not call it
GET /inbox/categoriesInbox renders category labels from the local taxonomy
GET /jobs/exportSettings exports client-side (jobsToCSV/jobsToJSON)
GET /jobs/ranked/jobs/ranked/ai already falls back to keyword scoring server-side
GET /profiles/me/dossierThe app reads the same dossier through /profiles/me/enrich
GET /resumes/me/downloadNo download affordance exists in Settings yet
POST /alerts/ackNotifications are acknowledged with /inbox/notifications/read
POST /jobs/expandPrompt 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.

On this page