Cloudflare architecture patterns for common problems. Reference when decomposing monolithic Workers, optimizing D1 writes, or adding external API resilience.
/plugin marketplace add littlebearapps/cloudflare-engineer/plugin install cloudflare-engineer@littlebearapps-cloudflareThis skill inherits all available tools. When active, it can use any tool Claude has access to.
circuit-breaker.mdd1-batching.mdservice-bindings.mdProven patterns for solving common Cloudflare architecture challenges. Each pattern includes symptoms (when to apply), detection methods, implementation steps, and trade-offs.
| Pattern | Problem | Solution | Effort |
|---|---|---|---|
| service-bindings | Monolithic Worker hitting subrequest limits | Decompose with RPC | Medium |
| d1-batching | High D1 write costs from per-row inserts | Batch writes | Low |
| circuit-breaker | External API failures cascading | Fail-fast with fallback | Medium |
Trigger Conditions:
fetch() between internal WorkersDetection (static):
// Anti-pattern: HTTP fetch to internal service
const response = await fetch(`${AUTH_SERVICE_URL}/validate`, {
headers: { Authorization: token }
});
Detection (live):
Trigger Conditions:
Detection (static):
// Anti-pattern: Per-row inserts in loop
for (const item of items) {
await db.run('INSERT INTO items (name) VALUES (?)', [item.name]);
}
Detection (live):
Trigger Conditions:
Detection (static):
// Anti-pattern: Unbounded external fetch
const data = await fetch('https://external-api.com/data');
// No timeout, no fallback, no retry logic
Detection (live):
Detailed implementation guides are in separate files:
Is your Worker > 500 lines or hitting subrequest limits?
├─ Yes → Consider SERVICE-BINDINGS pattern
└─ No
│
Is D1 your primary cost driver (>50%)?
├─ Yes → Apply D1-BATCHING pattern
└─ No
│
Do you call external APIs?
├─ Yes → Apply CIRCUIT-BREAKER pattern
└─ No → Review other optimization opportunities
Patterns can be combined. Common combinations:
Implementation Order (recommended):
Things to avoid when implementing patterns:
| Pattern | Anti-Pattern | Why It's Bad |
|---|---|---|
| Service Bindings | Too many small Workers | Complexity overhead exceeds benefit |
| Service Bindings | Circular dependencies | Deadlock risk, hard to reason about |
| D1 Batching | Batches too large | Memory pressure, timeout risk |
| D1 Batching | No error handling per batch | One bad record fails entire batch |
| Circuit Breaker | Circuit never closes | Permanent degraded mode |
| Circuit Breaker | No fallback defined | Fail-fast with no alternative |
Patterns to be added:
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.