agentleFS
CloudflareKnown publishercloudflare/chanfana/template/AGENTS.md

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.

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
  1. Very specific:

    Follow the same conventions as the parent chanfana library:

    line 39
  2. Distinctive:

    All code must use Zod v4 syntax:

    line 47
  3. Very specific:

    All D1 endpoints read the DB binding from env automatically (configurable via dbName property)

    line 101

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

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 production

Tests 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 binding

Code Style

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 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

  1. Schema — Create src/models/<name>.ts with 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,
      },
    };
  2. 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;
    }
  3. Routes — Register in src/index.ts:
    router.post("/foos", FooCreate);
  4. Migration — Add a SQL file in migrations/0002_create_foos/up.sql
  5. Tests — Add tests in test/ using the same pattern as tasks.test.ts

D1 Endpoint Features

  • D1ListEndpoint supports filterFields, searchFields, orderByFields, defaultOrderBy
  • All D1 endpoints read the DB binding from env automatically (configurable via dbName property)
  • Path params must match primaryKeys names (e.g., /tasks/:id with primaryKeys: ["id"])
  • Hooks: override before() / after() to transform data pre/post database operation

Key Resources

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.