WINDSURF RULES DEVOPS / DEPLOYMENT Cloudflare

Cloudflare Workers + Pages Rules

Rules for building and deploying lightweight apps on Cloudflare Workers and Pages with edge-first architecture.

Cloudflare Workers Cloudflare Pages Edge Serverless D1 Cursor
Tool
Windsurf
Asset type
Rules
Category
DevOps / Deployment
Framework
Cloudflare
Recommended path
.devin/rules/cloudflare-workers-pages.md
Activation / Trigger
always_on (default)
License
MIT
Last updated
2026-07-08

How to use this asset

  1. Click Copy Rule above to copy the full rule text.
  2. Save as Markdown under .devin/rules/*.md (preferred) or .windsurf/rules/*.md, or paste via Cascade → Customizations → Rules.
  3. Windsurf reads workspace rules from .devin/rules/ on each Cascade session.

Compatible tools

Designed for Windsurf. Also works with: Claude Code.

Asset content

# Cloudflare Workers + Pages Rules

You are an expert Cloudflare developer building edge-first applications.

## Architecture
- Run request handling at the edge with Workers; use Pages for static assets and SSR frameworks
- Keep handlers stateless; persist data in D1, KV, R2, or Durable Objects — not global memory
- Split API Workers from frontend Pages projects when lifecycles differ
- Prefer fetch-based subrequests over heavy synchronous CPU work in hot paths

## Workers Development
- Use the modern `export default { fetch }` module format with TypeScript
- Validate environment bindings (`env.DB`, `env.KV`) at startup paths and document required secrets
- Return proper HTTP status codes and JSON error envelopes
- Set cache headers intentionally; default to no-store for authenticated responses

## Pages & Deployment
- Configure build output directory and Node compatibility flags explicitly in `wrangler.toml`
- Use preview deployments for every pull request when possible
- Store secrets in Cloudflare dashboard or `wrangler secret`, never in git
- Pin compatibility dates and test after platform updates

## D1 & Storage
- Design D1 schemas with indexes for common query patterns
- Use migrations for D1 schema changes; avoid manual prod edits
- Choose R2 for large blobs; KV for low-latency key lookups with TTL awareness
- Handle eventual consistency and idempotent writes in background tasks

## Observability & Safety
- Log structured JSON from Workers; avoid logging PII or tokens
- Add rate limiting and bot protection on public endpoints
- Test locally with `wrangler dev` before promoting bindings to production

Save as Markdown under .devin/rules/*.md (preferred) or .windsurf/rules/*.md, or paste via Cascade → Customizations → Rules.