Cloudflare Full-Stack Patterns
This skill provides verified implementation patterns for composing Cloudflare primitives into robust full-stack applications.
Core Stack
- •Framework: Hono
- •Database: Cloudflare D1 with Drizzle ORM
- •AI: Workers AI via Vercel AI SDK 6
- •Orchestration: Cloudflare Workflows
Implementation Workflows
1. D1 + Drizzle Configuration
To ensure seamless migrations and type safety:
- •Set
migrations_dirinwrangler.jsoncto match Drizzle's output folder (default:"drizzle"). - •Use
nodejs_compatcompatibility flag inwrangler.jsonc. - •Export schema from a dedicated file (e.g.,
src/db/schema.ts).
2. Workers AI with AI SDK 6 (Structured Output)
To avoid LLM hallucinations and ensure valid JSON:
- •Use
generateTextwithOutput.objectinstead of deprecatedgenerateObject. - •Always define a Zod schema for the expected output.
- •Pass the Cloudflare AI binding via
createWorkersAIfromworkers-ai-provider.
3. Stateful Orchestration with Workflows
To build resilient multi-step pipelines:
- •Define a class extending
WorkflowEntrypoint<CloudflareBindings, PayloadType>. - •Wrap side effects (DB writes, AI calls, fetches) in
step.do()for automatic retries and state persistence. - •Register the workflow in
wrangler.jsoncwithbinding,name, andclass_name.
4. Avoiding "Shadowing" Friction
- •Ensure
public/index.htmldoes not conflict with Worker routes defined in Hono. - •If using Hono for SSR at
/, ensure the static asset directory (e.g.,./public) does not contain anindex.htmlunless it is the intended entry point.