Operations & state
Core route table, what persists between requests, and later options for cache and rate limits.
Operations & state
Verified against current HEAD of apps/core. Line numbers cited below — re-check if the tree moves.
Route table
| Route | Method | What it does | State touched | Persistent between requests? |
|---|---|---|---|---|
/ | GET/HEAD | Browser HTML status page when Accept includes text/html: logo (links to https://ziteox.com; plain link, no animation, no JS), title, and environment·version pill only (no health indicator, no D1 access, no JavaScript); otherwise JSON 404 not_found (Vary: Accept) | Optional version id from CF_VERSION_METADATA | No |
/favicon.ico | GET/HEAD | Ziteox JPEG favicon (no auth) | None | No |
/healthz | GET | Liveness; returns ok, env, github mode | None | No |
/v1/admin/projects | POST | Create project (project.create; optional portal_project_id) | D1 projects (+ audit) | D1 yes |
/v1/admin/projects | GET | List / lookup projects (project.list; optional ?portal_project_id=) | D1 read | D1 yes |
/v1/admin/projects/:key | PATCH | Update portal link (project.update; forge_admin only) | D1 projects (+ audit) | D1 yes |
/v1/admin/tokens | POST | Issue project token (token.issue) | D1 project_tokens, token_grants (+ audit) | D1 yes |
/v1/admin/tokens/:id/rotate | POST | Rotate token (token.rotate) | D1 tokens/grants (+ audit) | D1 yes |
/v1/admin/tokens/:id/revoke | POST | Revoke token (token.revoke) | D1 project_tokens.revoked_at (+ audit) | D1 yes |
/v1/admin/members/:id/tokens | GET | List member’s tokens across projects | D1 read | D1 yes |
/v1/admin/secrets | POST | Seal vault secret (vault.seal) | D1 vault_secrets; uses KEK secret | D1 + Worker secret |
/v1/admin/audit | GET | Per-key audit feed (audit.read; filters + cursor; role-scoped) | D1 audit_events read | D1 yes |
/v1/whoami | GET | Token + project identity | May update last_used_at on auth | D1 yes |
/v1/files | GET | Read file via GitHub adapter | Auth + audit; GitHub/mock | D1 audit; GH upstream |
/v1/tree | GET | List tree via GitHub adapter | Auth + audit; GitHub/mock | D1 audit; GH upstream |
/v1/secrets/:label | GET | Unseal project secret for caller | D1 vault read; KEK | D1 + Worker secret |
/v1/publish | POST | Publish → branch/PR via GitHub adapter | Auth + audit; GitHub/mock | D1 audit; GH upstream |
/npm/@ziteox%2f<pkg> or /npm/@ziteox/<pkg> | GET | Packument proxy (exact packages:read grant; that scope is opt-in and must be issued alone) | Auth; upstream GH Packages; audit | D1 + upstream |
/npm/download/@ziteox/... | GET | Tarball under /npm | Auth; upstream + blob host; audit | D1 + upstream |
/download/@ziteox/... | GET | Root tarball alias (lockfile shape) | Same as tarball | D1 + upstream |
Unknown /v1/admin/*, /v1/*, /npm/*, or /download/* → 404. Non-GET on npm/download → method error. Admin routes require Ed25519 assertion; data-plane and npm require zxcore_… Bearer.
Production note: with GITHUB_MODE=app, the GitHub App adapter is a stub — /v1/files, /v1/tree, /v1/publish fail with not_configured. Npm + admin do not need it. See Go live.
Migrations (local D1)
Schema-only under apps/core/migrations/. Notable recent:
| File | What |
|---|---|
0004_environments.sql | allowed_environments; token/vault/audit environment |
0007_packages_read_default.sql | Idempotent append of packages:read to project ceilings |
0008_portal_project_id.sql | Nullable unique projects.portal_project_id (portal ↔ Core link) |
0009_audit_indexes.sql | Audit indexes: (token_id, id), (project_id, id), (actor_user_id, id), (action, id) |
State inventory
| Store | Contents |
|---|---|
| D1 | projects (incl. optional portal_project_id), project_tokens (incl. last_used_at), token_grants, staff_roles, assertion_jti, vault_secrets, audit_events, plus local-only mock_github_* |
| Worker secrets / vars | KEK (CORE_SECRETS_KEK), assertion public keys, upstream CORE_GITHUB_PACKAGES_TOKEN, issuer / CORE_PUBLIC_URL / GITHUB_MODE, etc. |
| Vault crypto | AES-GCM envelopes; KEK from secret; ciphertext in D1 |
| GitHub | Mock tables in D1 (local) or App stub (production until wired) |
| npm upstream | GitHub Packages registry + blob host (pkg-npm.githubusercontent.com); Core does not cache today |
last_used_at is written on successful project-token auth (apps/core/src/lib/auth-project.ts), throttled to ~once per 5 minutes.
Statelessness finding
Module-level values are only constant Sets / regexes / numbers — no mutable caches, counters, timers, or globals:
| File | What | Lines (HEAD) |
|---|---|---|
lib/assertion.ts | ADMIN_ONLY / OPERATOR_OK Sets; TTL/skew constants | ~L40–50 |
lib/audit.ts | FORBIDDEN_META_KEYS Set | ~L17 |
lib/environments.ts | ENV_SET | ~L13 |
lib/scopes.ts | PATH_SCOPE_RE (path scopes); packages:read exclusive check | ~L18 / exclusivity helper |
lib/tokens.ts | TOKEN_* prefix/regex constants | ~L7–10 |
routes/npm.ts | Path regexes + redirect/timeout constants only | ~L15–28 |
The Map in routes/admin.ts (~L593) is created inside adminListMemberTokens (~L534) — per request, discarded after the response.
routes/npm.ts holds nothing between requests (no module Map/cache). So everything is stateless except D1 (plus Worker secrets/vars).
jti replay protection
Lives in D1 assertion_jti. Since pass 9 it is atomic: INSERT … ON CONFLICT(jti) DO NOTHING, then check changes; prune expired rows on the same write batch (DELETE FROM assertion_jti WHERE exp < ?) — see apps/core/src/lib/assertion.ts ~L169–188. Replay → 401 assertion_replay.
Workers-native
The npm proxy uses only fetch / Web Streams / WebCrypto. Tarball bodies are streamed; no Node APIs in the Worker path.
Later options (not at launch)
Package cache
| Option | Notes |
|---|---|
| Cache API | Per-colo, free, key by tarball path. Immutable tarballs are safe to cache. Must cache after auth check; never cache packuments long; no cross-colo. |
| R2 | Global durable store; needs R2 binding + bucket + write-through on first fetch; pennies at this size; survives GitHub outage. |
Rate limiting
| Option | Notes |
|---|---|
| Workers Rate Limiting binding | [[unsafe.bindings]] / ratelimits config; per-key e.g. token_id; eventually consistent; cheap. |
| Durable Object counter | Exact per-token; more code + DO billing. |
Recommend: none needed at launch. Add Cache API for tarballs first if latency/upstream cost matters; add Rate Limiting binding keyed by token_id if abuse appears.