Reference · Diagram Design

Anatomy of a Cloudflare Worker Project

The file tree of a typical Worker, what the three files that matter actually contain, and what wrangler.jsonc connects it to.

File structure and key files of a Cloudflare Worker project A tree diagram of a typical Worker project rooted at my-worker/, branching into src/, test/, wrangler.jsonc, package.json and four other files, with src/index.ts and test/index.test.ts as leaves. Below it, three detail cards show the actual content of src/index.ts, wrangler.jsonc and package.json. Below that, a small fan-out shows the Worker connecting through wrangler.jsonc to six bindings: KV, R2, D1, Durable Objects, Queues and Workers AI. A final row lists the remaining supporting files. PROJECT STRUCTURE my-worker/ src/ test/ wrangler.jsonc package.json + 4 more files index.ts fetch handler index.test.ts vitest THE 3 FILES THAT MATTER ENTRY POINT src/index.ts export default { async fetch(request, env) { return new Response("Hello!"); } }; Runs on every request. Build APIs, add auth, read/write R2 · KV · D1, route by path — here. CLOUDFLARE CONFIG wrangler.jsonc { "name": "my-worker", "main": "src/index.ts", "compatibility_date": "2026-08-19" } Tells Cloudflare how to deploy this Worker. Binds it to KV, R2, D1, DOs, Queues, AI — below. SCRIPTS & DEPS package.json { "scripts": { "dev": "wrangler dev", "deploy": "wrangler deploy" } } npm run dev → local Worker (wrangler dev). npm run deploy → ships it to Cloudflare's edge. WRANGLER.JSONC BINDINGS Worker defined in wrangler.jsonc KV key-value store R2 object storage D1 SQL database Durable Objects stateful coordination Queues async job queue Workers AI run AI models OTHER FILES · tsconfig.json — TypeScript compiler config · .dev.vars — local secrets, dotenv syntax (wins over .env) · .gitignore — keeps secrets and node_modules out of git · README.md — project documentation · test/ — the test suite, Vitest by convention Production secrets ship separately — wrangler secret put FOCAL — THE CODE CLOUDFLARE ACTUALLY EXECUTES THE RUNNING WORKER