Skip to content

API runtime

The API worker is a Hono service in apps/api. It runs on Cloudflare Workers with D1 as durable storage and Vectorize for semantic retrieval.

Terminal window
pnpm --filter api-worker dev
pnpm --filter api-worker build
pnpm --filter api-worker deploy
pnpm --filter api-worker cf-typegen

Run cf-typegen after changing wrangler.jsonc so Worker binding types stay in sync with Cloudflare resources.

Create production resources before deploying a real environment:

Terminal window
wrangler d1 create memo-st
wrangler vectorize create memo-st-memory --dimensions 1536 --metric cosine

Then update apps/api/wrangler.jsonc with the D1 database ID and apply migrations:

Terminal window
wrangler d1 migrations apply memo-st --local
wrangler d1 migrations apply memo-st --remote
  • D1 stores memory records and metadata.
  • Vectorize stores embeddings when callers provide embedding.
  • ctx.waitUntil() is used for Vectorize upserts so the API can acknowledge the durable D1 write quickly.
  • CORS allows https://memo.st, http://localhost:3000, and http://localhost:3001.