chanfana / template
AGENTS.md768 starsChanged 9 months agoMITView on GitHub
A starter Cloudflare Worker using Chanfana (OpenAPI), Hono, D1, and Zod v4. This is a copyable template — users clone it and build on top. Tests use @cloudflare/vitest-pool-workers with a local miniflare D1 binding. Config: vitest.config.mts. Follow the same conventions as the parent chanfana library: - 2-space indent, double quotes, always semicolons - import type for type-only imports (verbatimModuleSyntax: true) - Classes: PascalCase — endpoint classes named after their action (TaskCreate, TaskList) - Named exports everywhere, no default exports (except…
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository3 other files it gives its agents.
- AGENTS.mdAGENTS.md
- llms.txtllms.txt
- write-endpointsSkill
The file
We split this AGENTS.md into the rules it gives an agent
3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 39
Follow the same conventions as the parent chanfana library:
- Distinctive: line 47
All code must use Zod v4 syntax:
- Very specific: line 101
All D1 endpoints read the DB binding from env automatically (configurable via dbName property)
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AGENTS.md — Chanfana Template (Task API)
A starter Cloudflare Worker using Chanfana (OpenAPI), Hono, D1, and Zod v4. This is a copyable template — users clone it and build on top.
Commands
npm run dev # Start local dev server (http://localhost:8787)
npm test # Run integration tests via vitest-pool-workers
npm run deploy # Deploy to Cloudflare
npm run db:migrate:local # Apply D1 migrations locally
npm run db:migrate:remote # Apply D1 migrations to productionTests use @cloudflare/vitest-pool-workers with a local miniflare D1 binding. Config: vitest.config.mts.
Project Layout
src/
index.ts # Hono app, fromHono wrapper, route registration
models/task.ts # Zod schema + shared meta (tableName, primaryKeys)
endpoints/
taskCreate.ts # POST /api/tasks — D1CreateEndpoint
taskList.ts # GET /api/tasks — D1ListEndpoint (filter, search, order)
taskRead.ts # GET /api/tasks/:id — D1ReadEndpoint
taskUpdate.ts # PUT /api/tasks/:id — D1UpdateEndpoint
taskDelete.ts # DELETE /api/tasks/:id — D1DeleteEndpoint
hello.ts # GET /api/hello — Custom OpenAPIRoute (non-D1 example)
test/
tasks.test.ts # Integration tests for all endpoints
migrations/
0001_create_tasks/up.sql # D1 CREATE TABLE
wrangler.jsonc # Worker config with D1 bindingCode Style
Follow the same conventions as the parent chanfana library:
- 2-space indent, double quotes, always semicolons
import typefor type-only imports (verbatimModuleSyntax: true)- Classes:
PascalCase— endpoint classes named after their action (TaskCreate,TaskList) - Named exports everywhere, no default exports (except the Hono app in
index.ts)
Zod v4 Rules (Critical)
All code must use Zod v4 syntax:
// WRONG (v3) → CORRECT (v4)
z.string().email() → z.email()
z.string().uuid() → z.uuid()
z.string().datetime() → z.iso.datetime()
z.string().url() → z.url()
z.nativeEnum(X) → z.enum([...])
obj.strict() → z.strictObject({...})
{ message: "..." } → { error: "..." }How to Add a New Model
- Schema — Create
src/models/<name>.tswith a Zod object schema and a meta object:import { z } from "zod"; export const FooSchema = z.object({ id: z.number().optional(), name: z.string(), }); export const fooMeta = { model: { tableName: "foos" as const, schema: FooSchema, primaryKeys: ["id"] as const, }, }; - Endpoints — Create classes in
src/endpoints/extending the D1 endpoints:import { D1CreateEndpoint } from "chanfana"; import { fooMeta } from "../models/foo"; export class FooCreate extends D1CreateEndpoint { _meta = fooMeta; } - Routes — Register in
src/index.ts:router.post("/foos", FooCreate); - Migration — Add a SQL file in
migrations/0002_create_foos/up.sql - Tests — Add tests in
test/using the same pattern astasks.test.ts
D1 Endpoint Features
D1ListEndpointsupportsfilterFields,searchFields,orderByFields,defaultOrderBy- All D1 endpoints read the
DBbinding fromenvautomatically (configurable viadbNameproperty) - Path params must match
primaryKeysnames (e.g.,/tasks/:idwithprimaryKeys: ["id"]) - Hooks: override
before()/after()to transform data pre/post database operation
Key Resources
- Chanfana docs: https://chanfana.pages.dev
- Chanfana source: https://github.com/cloudflare/chanfana
- Zod v4: https://zod.dev/v4
- Hono: https://hono.dev
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

