{
  "id": "cloudflare-workers-app",
  "type": "context-packs",
  "category": "context",
  "locale": "fr",
  "url": "/fr/context/cloudflare-workers-app",
  "title": "Application Cloudflare Workers — Pack de contexte",
  "description": "Pack de contexte copiable pour une application Cloudflare Workers avec D1, KV, R2 et Hono, afin que votre agent IA comprenne les contraintes d'exécution en périphérie dès la première invite.",
  "tools": [
    "Cursor",
    "Claude Code",
    "Codex",
    "Windsurf"
  ],
  "stack": [
    "Cloudflare",
    "TypeScript"
  ],
  "tags": [
    "cloudflare",
    "context-pack",
    "typescript",
    "deploy",
    "search"
  ],
  "difficulty": null,
  "updated": "2026-06-08",
  "markdown": "Collez ceci en haut d'une tâche pour que l'agent comprenne les contraintes d'exécution, les liaisons et la disposition du projet Cloudflare Workers avant d'écrire du code.\n\n## Contexte du projet\n\n```txt\nAn API and web application running entirely on Cloudflare Workers — no Node.js\nserver, no container. The HTTP router is Hono. Persistent state uses Cloudflare\nD1 (SQLite at the edge) for relational data, KV for session/cache, and R2 for\nfile storage. Deployed and configured via Wrangler. TypeScript compiled with\nesbuild through Wrangler's bundler.\n```\n\n## Stack\n\n```txt\nCloudflare Workers (V8 isolates — NOT Node.js)\nHono v4 (lightweight router, runs on Workers)\nCloudflare D1 (SQLite — accessed via env.DB binding)\nCloudflare KV (key-value — accessed via env.KV binding)\nCloudflare R2 (object storage — accessed via env.BUCKET binding)\nDrizzle ORM with drizzle-orm/d1 adapter\nTypeScript (strict)\nWrangler v3 (CLI: dev, deploy, d1, kv, r2)\n```\n\n## Structure des répertoires\n\n```txt\nsrc/\n  index.ts            # Worker entry point — exports default { fetch }\n  routes/             # Hono route handlers, one file per resource\n  middleware/         # Auth, CORS, rate-limit middleware\n  lib/\n    db.ts             # Drizzle D1 client factory (receives env.DB)\n    schema.ts         # Drizzle table definitions\n    kv.ts             # KV helpers (typed get/put wrappers)\n    r2.ts             # R2 helpers (upload, signed URL, delete)\n  types/\n    env.d.ts          # Cloudflare Env interface with all bindings typed\nmigrations/           # D1 SQL migrations (generated by drizzle-kit)\nwrangler.toml         # Worker config — bindings, routes, compatibility date\ndrizzle.config.ts\n```\n\n## Conventions de codage\n\n```txt\n- The Workers runtime is NOT Node.js. Never import Node built-ins (fs, path,\n  crypto from \"node:crypto\" is allowed but most others are not).\n- All bindings (D1, KV, R2, secrets) are accessed via the typed Env interface\n  — never use global variables or process.env.\n- D1 queries use Drizzle ORM. Raw SQL is only acceptable in migrations.\n- KV is eventually consistent — do not use it as a lock or transaction.\n- Secrets are set with `wrangler secret put SECRET_NAME`, never in wrangler.toml.\n- Hono routes return Response objects or use c.json() / c.text() helpers.\n- Wrangler compatibility_date must stay at its current pinned value unless\n  explicitly upgrading and testing all affected APIs.\n- D1 schema changes require: `npx drizzle-kit generate` then\n  `wrangler d1 migrations apply DB --remote`.\n```\n\n## Périmètres des tâches IA\n\n```txt\n- Do not use setTimeout, setInterval, or long-lived connections — Workers have\n  a 30-second CPU time limit per request.\n- Do not spawn child processes or access the file system.\n- Do not import packages that depend on Node.js internals without confirming\n  they have a Workers-compatible build.\n- Do not add environment variables via wrangler.toml [vars] for secrets —\n  use `wrangler secret put` instead.\n- Do not change compatibility_date without updating compatibility_flags and\n  running the full test suite.\n- D1 does not support all SQLite features — avoid triggers, virtual tables,\n  and RETURNING on UPDATE in older compatibility dates.\n- Workers have a 1 MB script size limit (after compression). Keep dependencies\n  minimal; check bundle size with `wrangler deploy --dry-run`.\n```\n\n## llms.txt\n\n```txt\n# Cloudflare Workers App\nRuntime: Cloudflare Workers (V8 isolates, not Node.js)\nRouter: Hono v4\nDatabase: D1 via Drizzle ORM (src/lib/db.ts, src/lib/schema.ts)\nCache/Session: KV (src/lib/kv.ts)\nFile storage: R2 (src/lib/r2.ts)\nConfig: wrangler.toml — all bindings declared here\nSecrets: wrangler secret put (never wrangler.toml)\nDeploy: wrangler deploy\nDev: wrangler dev (local D1 + KV emulation)\n```"
}