Publish & delivery hot path
How Skillist serves published skills at the edge. Keep these invariants when editing.
Storage tiers
- KV (
SKILLS_KV) — publishedSKILL.mdand meta, for <10ms edge reads. Written bylib/publish.ts, read bylib/delivery.ts/lib/kv.ts. The delivery path must read KV, never Postgres. - R2 (
SKILLS_R2) — full bundles (all files).lib/r2.tshandlesr2Prefix,sha256, upload/download. - Postgres (via
HYPERDRIVE) — source of truth for versions/metadata; used on writes and non-hot reads, not on the delivery hot path.
Publish flow
- A publish (
publishVersioninlib/ai.ts/ route handler) writes the bundle to R2 and theSKILL.md+ meta to KV. - It broadcasts a publish event:
broadcastPublish(...)→SkillRealtimeHubDO/broadcast. SkillRealtimeHub(one instance perorg:repo, keyed byidFromName) fans the event out to subscribers over WebSocket + SSE.
Delivery flow (public, unauthed)
/{org}/{repo}/SKILL.md and /meta → KV read via deliveryRoutes. /bundle → R2. These are mounted at root in index.ts (app.route("/", deliveryRoutes)) and are intentionally public.
Invariants
- Don't add a DB query to the delivery path — it defeats the <10ms budget.
- Every publish must write KV and R2 and broadcast; a partial write causes stale delivery or missing realtime updates.
- Respect per-user cache scoping and never persist credentials in KV/R2.
Verify
pnpm --filter @skillist/api exec vitest run src/publish-latency.test.ts and related delivery/KV tests, then pnpm check + pnpm typecheck.