Skip to content

refactor(deploy): single-file CF Worker + D1 with worker-logs RPC#4

Merged
whoabuddy merged 5 commits intomainfrom
feat/deploy-prep
Mar 10, 2026
Merged

refactor(deploy): single-file CF Worker + D1 with worker-logs RPC#4
whoabuddy merged 5 commits intomainfrom
feat/deploy-prep

Conversation

@arc0btc
Copy link
Contributor

@arc0btc arc0btc commented Mar 10, 2026

Summary

Replaces the multi-file Docker/Fly.io architecture with a single-file Cloudflare Worker + D1 deployment, following AIBTC patterns (cf. x402-sponsor-relay, landing-page).

What changed (latest revision)

  • Single-file app: Collapsed app.ts, auth.ts, db-bun.ts, db-d1.ts, worker.ts, routes/ into one src/index.ts — Hono app directly on D1
  • wrangler.jsonc (not toml): D1 binding, worker-logs RPC service binding, observability disabled
  • Production only: hub.aibtc.com custom domain, no staging env
  • Request logging: Fire-and-forget middleware via worker-logs RPC (LOGS binding)
  • Discovery endpoints: /llms.txt and /.well-known/agent.json for agent-friendly discovery
  • schema.sql: D1-compatible schema for agents, capabilities, submitted_tasks tables
  • Clean deps: hono + @cloudflare/workers-types + wrangler only

Endpoints

Method Path Auth Description
GET / public Service info + endpoint index
GET /health public Fleet health (online/offline/degraded)
GET /agents public List agents
GET /agents/:name public Agent detail + capabilities
POST /agents Bearer Register/update agent
DELETE /agents/:name Bearer Remove agent
GET /capabilities public All capabilities (filter by ?skill=)
POST /tasks Bearer Submit task (auto-routes by skill match)
GET /tasks public List tasks (filter by ?agent=&status=)
PATCH /tasks/:id Bearer Update task status
GET /llms.txt public Agent-friendly discovery doc
GET /.well-known/agent.json public A2A agent card

Deploy

bunx wrangler d1 create agent-hub-db
# update database_id in wrangler.jsonc production env
bunx wrangler d1 execute agent-hub-db --env production --file=schema.sql
bunx wrangler secret put HUB_API_KEY --env production
bunx wrangler deploy --env production

Test plan

  • bunx tsc --noEmit passes
  • Type-safe D1 queries throughout
  • bunx wrangler dev local D1 test
  • Deploy to production (hub.aibtc.com)

🤖 Generated with Claude Code

arc0btc added 3 commits March 10, 2026 15:19
Switch to Bun's built-in SQLite driver to eliminate native binding
compilation in Docker and simplify deployment. Adds DB_PATH env var
support for configuring database location in production.

- Replace better-sqlite3 + @types with bun:sqlite (built-in)
- Add DB_PATH env var override (defaults to project root)
- Update query type signatures to bun:sqlite generic order
- Export app from index.ts for integration tests
- Add tests/ to tsconfig include

Co-Authored-By: Arc <224894192+arc0btc@users.noreply.github.com>
Packages the app for production deployment:
- Dockerfile using oven/bun:1, mounts /data for SQLite persistence
- .dockerignore excludes test files and local DBs
- fly.toml for Fly.io: shared-cpu-1x, 256MB, /data volume
- .env.example documents PORT and DB_PATH
- GitHub Actions CI: bun install + bun test on push/PR

Co-Authored-By: Arc <224894192+arc0btc@users.noreply.github.com>
- Remove Dockerfile, .dockerignore, fly.toml
- Add wrangler.toml with D1 database binding
- Add src/worker.ts as CF Worker entry point
- Extract DbClient interface (src/types.ts) with two implementations:
  - src/db-bun.ts for local dev (bun:sqlite)
  - src/db-d1.ts for production (Cloudflare D1)
- Refactor src/app.ts as Hono app factory (takes DbClient)
- Routes use async DB client from Hono context
- Keep bun local dev working (bun run dev)
- Add wrangler scripts (cf:dev, deploy)
- Update CLAUDE.md with new architecture
@arc0btc arc0btc changed the title chore(deploy): migrate to bun:sqlite + add deploy config refactor(deploy): replace Docker/Fly.io with Cloudflare Worker + D1 Mar 10, 2026
…outing

- Replace multi-file architecture (app.ts, auth.ts, db-*.ts, routes/, worker.ts)
  with single src/index.ts Hono app directly on D1
- Switch wrangler.toml → wrangler.jsonc with worker-logs RPC service binding
- Production-only env (hub.aibtc.com), drop staging
- Add schema.sql for D1 initialization
- Add /llms.txt and /.well-known/agent.json discovery endpoints
- Add request logging middleware via worker-logs RPC (fire-and-forget)
- CORS enabled for public read access
- Clean package.json: hono + CF workers types only

Co-Authored-By: Arc <224894192+arc0btc@users.noreply.github.com>
@arc0btc arc0btc changed the title refactor(deploy): replace Docker/Fly.io with Cloudflare Worker + D1 refactor(deploy): single-file CF Worker + D1 with worker-logs RPC Mar 10, 2026
- Remove unused jsonOk helper (all routes use c.json())
- Deduplicate URL parsing in logging middleware
- Batch capability DELETE + INSERTs for atomicity (DB.batch)
- Remove unused JSX config from tsconfig (pure JSON API)
- Normalize LogsBinding to interface for consistency

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants