This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is the Cloudflare Workers Templates repository containing a collection of starter templates for building full-stack applications on the Cloudflare Workers platform. The repository is structured as a monorepo with:
- Individual template directories (each ending in
-template) - Custom CLI tool (
cli/) for template management and validation - Turbo build system for managing multiple projects
- Playwright E2E tests for template validation
# Check all templates and code quality
pnpm run check
# Fix formatting and linting issues automatically
pnpm run fix
# Run all tests (includes template validation)
pnpm run test
# Run Playwright E2E tests
pnpm run test:e2e
# Run CLI tests specifically
pnpm run test:cli# Lint all templates for compliance
pnpm run check:templates
# Fix template issues automatically
pnpm run fix:templates
# Generate npm lockfiles for all templates
pnpm run fix:lockfiles
# Validate live demo links
pnpm run validate-live-demo-links
# Validate Deploy to Cloudflare buttons
pnpm run validate-d2c-buttons# Deploy all templates
pnpm run deploy
# Deploy live demos
pnpm run deploy-live-demos
# Upload templates to Cloudflare Templates API
pnpm run uploadEach template follows a consistent structure:
package.jsonwith required Cloudflare metadatawrangler.jsonorwrangler.jsonc(not.toml)README.mdwith Deploy to Cloudflare button- TypeScript configuration
- Worker source code typically in
src/
The repository includes a sophisticated CLI tool that:
- Validates template configuration and structure
- Uploads templates to Cloudflare's Templates API
- Deploys live demos for each template
- Manages dependencies across all templates
- Enforces consistent standards via linting
Key CLI commands used internally:
templates lint- Validate template compliancetemplates upload- Upload to Templates APItemplates deploy-live-demos- Deploy previews
Uses Turbo for coordinated builds across templates:
- Parallel building of multiple templates
- Caching for improved performance
- Coordinated TypeScript compilation
Templates are high-quality, tangible use-case driven examples of applications built using Cloudflare Workers. They should be practical applications demonstrating technology, not sandboxed environments.
Templates must include:
nameending in-template(matching directory)description(one-line summary, keep brief)deployscript for Wrangler deploymentcloudflaremetadata object with:label(Title Case name for dashboard display)products(max 3 Cloudflare products, focus on unique ones)categories(from: "starter", "storage", "ai")preview_image_url(16:9 aspect ratio, provided by Growth team)publish: true(only if template should appear in dashboard)
- Frontend Component: Must have visual UI that clearly demonstrates functionality
- Preview Image: Required 16:9 aspect ratio screenshot (minimum 500px width)
- README.md: Must include:
- Deploy to Cloudflare button
- Getting started section with local development instructions
- Dashboard content section wrapped in
<!-- dash-content-start -->and<!-- dash-content-end --> - Screenshot of live application
- Description of products used with documentation links
- Package-lock.json: Required for 80% faster module resolution
- Tests: Mandatory minimum of 5 tests using vitest
- Worker Binding: Every template must use at least one Worker binding
- API Router: Use Hono unless project specifically needs different router
- Top-level Environment: Bindings must be top-level for Deploy to Cloudflare compatibility
- Single Worker: Cannot be monorepo, must be single Worker application
- Must use
wrangler.jsonorwrangler.jsoncformat (not.toml) - Latest compatibility date
- Observability and Smart Placement enabled by default
- Source maps enabled for development
- TypeScript: Required for all templates
- Framework Recommendations: React + Vite, Next.js, React Router v7, or Astro
- Latest Versions: Use latest Wrangler and compatibility date
- Comments: Include educational comments explaining Cloudflare-specific features
- Workers Assets: Use Workers Assets for frontend instead of Pages
- Naming: Focus on use case, not underlying tech (e.g., "Astro AI Chat Bot" not "DO Template")
- No Experimental Features: Use stable, current best practices
- List all required secrets in README.md
- Include where users can find appropriate values
- Show missing configuration errors in deployed application UI
- Environment variables requiring user updates must be documented
Templates are validated through:
- Static analysis via custom CLI linting
- Build validation ensuring all templates compile
- E2E tests via Playwright
- Live demo validation ensuring deployed templates work
- Unit tests: Minimum 5 tests required using vitest-pool-workers package
templates.json- Template registry with package hashesturbo.json- Build configurationplaywright.config.ts- E2E test configurationpnpm-workspace.yaml- Workspace configuration
- Before making changes: Run
pnpm run checkto ensure clean state - After making changes: Run
pnpm run fixto auto-format and lint - Before committing: Ensure
pnpm run testpasses - For new templates: Follow the template requirements checklist in CONTRIBUTING.md
- Create directory: Name must end with
-template - Package.json setup: Include all required Cloudflare metadata
- Generate lockfile: Run
pnpm run fix:lockfilesto create package-lock.json - Add tests: Minimum 5 tests using vitest
- README content: Include Deploy to Cloudflare button and dashboard content sections
- Preview image: Provide 16:9 screenshot for Growth team to upload
- Validation: Run
pnpm run check:templatesto ensure compliance
The custom CLI (cli/src/) handles:
- Template discovery and validation
- Cloudflare API integration
- GitHub integration for PR workflows
- Dependency management across templates
- Automated deployment processes
When working with templates, always use the provided CLI commands rather than manual processes to ensure consistency and compliance with repository standards.
- Demonstrates practical use case, not just technology showcase
- Uses at least one Worker binding (D1, KV, R2, Durable Objects, etc.)
- Has clear visual UI that shows what the template does
- Follows Workers best practices with stable, non-experimental features
- Includes comprehensive tests and documentation
- React + Vite
- Next.js
- React Router v7 (new Remix)
- Astro