refactor(deploy): single-file CF Worker + D1 with worker-logs RPC#4
Merged
refactor(deploy): single-file CF Worker + D1 with worker-logs RPC#4
Conversation
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
…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>
- 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)
app.ts,auth.ts,db-bun.ts,db-d1.ts,worker.ts,routes/into onesrc/index.ts— Hono app directly on D1hub.aibtc.comcustom domain, no staging envLOGSbinding)/llms.txtand/.well-known/agent.jsonfor agent-friendly discoveryagents,capabilities,submitted_taskstableshono+@cloudflare/workers-types+wrangleronlyEndpoints
//health/agents/agents/:name/agents/agents/:name/capabilities?skill=)/tasks/tasks?agent=&status=)/tasks/:id/llms.txt/.well-known/agent.jsonDeploy
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 productionTest plan
bunx tsc --noEmitpassesbunx wrangler devlocal D1 test🤖 Generated with Claude Code