Build a system where Postgres acts as durable queue + transactional boundary + system of record, Cloudflare Dynamic Workers execute arbitrary code at runtime, and TanStack Start React app serves as visualization/control plane.
Client (UI) → TanStack Start → SQL API → Postgres → Cloudflare Workers → Dynamic Workers → UI
- Database: Postgres 16 (via tembo/pgmq-pg image)
- Execution: Cloudflare Dynamic Workers (LOADER.load / LOADER.get)
- API: TanStack Start server functions
- UI: TanStack Start + shadcn/ui
- User submits JavaScript code via UI (
/workers/new) - Job stored in Postgres with code + optional cacheId
- Server calls Cloudflare Worker API:
LOADER.load()- fresh worker for one-time executionLOADER.get(id, callback)- cached warm worker
- Cloudflare spawns Dynamic Worker in sandbox
- Result returned and stored in Postgres
- Docker Compose for Postgres 16
- Database migrations (schema, functions, dynamic worker support)
- Jobs state table with code storage
- Cloudflare Worker with Worker Loader binding
-
/loadendpoint for one-time execution -
/getendpoint for cached workers - API client in web app
- TanStack Start server functions
- executeDynamicWorker - create + execute job
- getJobStatus, listJobs, getMetrics
- Dashboard (/)
- Jobs list (/jobs)
- Job detail (/jobs/$jobId)
- Dynamic Worker creation (/workers/new)
- Metrics (/metrics)
- Queues (/queues)
jobs_state (
job_id BIGINT PRIMARY KEY,
job_type TEXT,
payload JSONB,
status TEXT,
result JSONB,
error TEXT,
code TEXT, -- Dynamic worker code
language TEXT, -- javascript, python, etc.
worker_id TEXT, -- Cache ID for get()
execution_logs JSONB,
created_at TIMESTAMP,
updated_at TIMESTAMP
)-
Deploy Cloudflare Worker:
cd cloudflare-worker npm install wrangler deploy -
Start database:
docker-compose up -d
-
Configure environment:
cp .env.example .env # Edit .env and set CLOUDFLARE_WORKER_URL -
Start web UI:
cd apps/web && bun run dev
-
Open the app: Navigate to http://localhost:3000
DATABASE_URL- Postgres connectionCLOUDFLARE_WORKER_URL- Your deployed Cloudflare Worker URL
dymunim/
├── apps/web/ # TanStack Start React app
│ ├── src/routes/ # Page routes
│ ├── src/server/ # Server functions
│ └── src/lib/ # Cloudflare client
├── cloudflare-worker/ # Cloudflare Worker with Worker Loader
│ ├── src/index.ts # Handler code
│ └── wrangler.jsonc # Worker config
├── packages/db/ # Shared database client
├── packages/ui/ # Shared UI components
└── infrastructure/ # Docker, migrations
└── postgres/migrations/ # SQL migrations
Uses actual Cloudflare Dynamic Workers API:
- LOADER.load() - Creates fresh worker, one-time execution
- LOADER.get(id, callback) - Caches worker by ID for reuse (warm starts)
Code runs in sandboxed environment with limited globals (Math, JSON, Date, etc.)