Cloudflare Fullstack Deployment
Deploy fullstack web applications on Cloudflare's edge network. Everything runs at the edge
(300+ data centers), scales to zero, and has a generous free tier requiring no credit card (except R2, which is free but requires a credit card on file).
Quick Start
# 1. Sign up at https://dash.cloudflare.com (free, no credit card)
# 2. Install CLI
npm install -g wrangler
# 3. Authenticate (opens browser)
wrangler login
# 4. Scaffold a project
npm create cloudflare@latest my-app
# 5. Run locally
cd my-app && wrangler dev
# 6. Deploy globally
wrangler deploy
Architecture Overview
┌──────────────────────────────────────────────────┐
│ Cloudflare Edge (300+ DCs) │
│ │
│ ┌────────────┐ ┌────────────┐ ┌─────────────┐ │
│ │ Workers │ │ Static │ │ Workers AI │ │
│ │ (API/SSR) │ │ Assets │ │ (inference) │ │
│ └─────┬──────┘ └────────────┘ └─────────────┘ │
│ │ │
│ ┌─────┴──────┐ ┌────────────┐ ┌─────────────┐ │
│ │ D1 (SQL) │ │ R2 (S3) │ │ KV (cache) │ │
│ └────────────┘ └────────────┘ └─────────────┘ │
└──────────────────────────────────────────────────┘
Service Decision Matrix
| Need |
Service |
Free Tier |
| API / serverless functions |
Workers |
100K req/day |
| Frontend SPA or SSR |
Workers + Static Assets |
Unlimited bandwidth |
| Relational database (SQL) |
D1 (SQLite) |
5M reads/day, 5GB |
| File/image/video storage |
R2 (S3-compatible) |
10GB, zero egress (credit card required) |
| Sessions, config, cache |
KV (key-value) |
100K reads/day |
| User authentication |
Better Auth (OSS) |
Free |
| Background jobs |
Queues |
10K ops/day |
| Existing Postgres/MySQL |
Hyperdrive (proxy) |
Included (100K queries/day free) |
| AI inference |
Workers AI |
10K neurons/day, no credit card, no API key — just [ai] binding |
| Bot/spam protection |
Turnstile |
1M req/month |
Dashboard vs CLI
Almost everything is CLI-only via wrangler. The dashboard is only needed for:
- Account signup (one-time) at dash.cloudflare.com
- API tokens for CI/CD at Profile > API Tokens
- Custom domain setup at Workers > Settings > Domains
- Monitoring / analytics for logs and metrics
All resource creation (D1, R2, KV), deployments, migrations, and secrets are handled by wrangler.
Recommended Stacks
JavaScript/TypeScript (Production-ready)
| Layer |
Tool |
| API |
Hono (lightweight, Workers-native, fully typed) |
| ORM |
Drizzle (D1 support, auto-generates Zod validators) |
| Frontend |
React + Vite (or Astro, SvelteKit for SSR) |
| Routing |
TanStack Router (file-based) |
| Server state |
TanStack Query |
| Client state |
Zustand |
| Auth |
Better Auth (D1 + Drizzle + Hono adapter) |
Python (Open Beta)
| Layer |
Tool |
| API |
FastAPI (runs on Workers via Pyodide WASM) |
| CLI |
pywrangler (wraps wrangler, uses uv for deps) |
| Note |
Flask/Django NOT supported - only async frameworks |
Key Architecture Rules
- Max 300-400 lines per file. Split aggressively.
- Domain-driven folders. Each feature is a self-contained directory.
- No hardcoding. Config in env vars or constants files.
- Rich comments. Explain the why, not just the what - target beginners.
- Log everything. Use structured logging so debugging is possible.
- Zustand early. Introduce state management before complexity hits.
- Validate all inputs. Never trust client-sent data.
- ARCHITECTURE.md at root — MANDATORY. Once the user decides on an architecture,
immediately create
ARCHITECTURE.md with: overview, mermaid diagram, services table,
folder structure, data flow, and domain map. Keep it up to date — if the architecture
changes, update this file FIRST. See references/architecture-bestpractices.md for template.
Reference Docs
| Read when... |
File |
| Brand new, no idea what any of this means |
references/beginner-onboarding.md |
| Need project ideas or help deciding what to build |
references/beginner-onboarding.md |
| First time using Cloudflare (ready to set up) |
references/getting-started.md |
| Building a fullstack app from scratch (start here) |
references/tutorial-todo-app.md |
| Choosing or configuring compute (Workers, Python, containers) |
references/compute.md |
| Setting up database, file storage, cache, or queue |
references/database-storage.md |
| Adding login/signup, bot protection, or access control |
references/auth-security.md |
| Deploying via CLI, GitHub Actions, or managing secrets |
references/deployment-cicd.md |
| Writing JS/TS backend + frontend (Hono, Drizzle, React) |
references/js-patterns.md |
| Writing a Python backend (FastAPI on Workers) |
references/python-patterns.md |
| Structuring projects, state management, security |
references/architecture-bestpractices.md |
| Using Workers AI (LLMs, embeddings, image gen) |
references/workers-ai.md |
| Something broke and need to debug |
references/debugging-logging.md |
Work in Progress — Self-Correcting Skill
This skill is actively evolving. If during execution any reference file contains
outdated APIs, incorrect imports, broken commands, or patterns that don't work:
- Fix it immediately in the reference file, or
- Ask the user if they'd like the skill files updated with the correction.
Don't silently work around inaccuracies — surface them and fix the source so future
sessions benefit. Treat every execution as a chance to improve the skill.
Agent Execution Flow
This skill is designed for AI coding agents to execute, not just reference.
Every reference file contains copy-pasteable code and runnable commands.
Step-by-step for the AI agent:
Understand the user's goal. If they have no idea, read beginner-onboarding.md — help them
pick a project from the ideas list. Ask what interests them, what they want to learn.
Discuss architecture. Once a project is chosen, discuss which services are needed
(use the Service Decision Matrix above). Let the user make the call on stack/features.
Document architecture IMMEDIATELY. Create ARCHITECTURE.md at project root with:
- Overview paragraph
- Mermaid diagram (
references/architecture-bestpractices.md has template)
- Services table (service, purpose, binding name)
- Folder structure
- Data flow description
This is the source of truth. Update it every time the architecture changes.
Build the app. Follow tutorial-todo-app.md as the base pattern, adapting for the
user's chosen project. Pull specific patterns from:
js-patterns.md / python-patterns.md — code patterns
database-storage.md — D1, R2, KV, Queues setup
auth-security.md — Better Auth, JWT, Turnstile
architecture-bestpractices.md — structure, security, state management
Deploy. Follow deployment-cicd.md for CLI deploy + GitHub Actions setup.
Keep ARCHITECTURE.md current. After adding any new service, domain, or changing
data flow — update ARCHITECTURE.md and its mermaid diagram before moving on.
Source: iaac-maai/structure_compliance_check — distributed by TomeVault.
1---2name: iaac-maai-structure-compliance-check-cloudflare3description: Cloudflare Fullstack Deployment4---56# Cloudflare Fullstack Deployment78Deploy fullstack web applications on Cloudflare's edge network. Everything runs at the edge9(300+ data centers), scales to zero, and has a generous free tier requiring no credit card (except R2, which is free but requires a credit card on file).1011## Quick Start1213```bash14# 1. Sign up at https://dash.cloudflare.com (free, no credit card)15# 2. Install CLI16npm install -g wrangler17# 3. Authenticate (opens browser)18wrangler login19# 4. Scaffold a project20npm create cloudflare@latest my-app21# 5. Run locally22cd my-app && wrangler dev23# 6. Deploy globally24wrangler deploy25```2627## Architecture Overview2829```30┌──────────────────────────────────────────────────┐31│ Cloudflare Edge (300+ DCs) │32│ │33│ ┌────────────┐ ┌────────────┐ ┌─────────────┐ │34│ │ Workers │ │ Static │ │ Workers AI │ │35│ │ (API/SSR) │ │ Assets │ │ (inference) │ │36│ └─────┬──────┘ └────────────┘ └─────────────┘ │37│ │ │38│ ┌─────┴──────┐ ┌────────────┐ ┌─────────────┐ │39│ │ D1 (SQL) │ │ R2 (S3) │ │ KV (cache) │ │40│ └────────────┘ └────────────┘ └─────────────┘ │41└──────────────────────────────────────────────────┘42```4344## Service Decision Matrix4546| Need | Service | Free Tier |47|------|---------|-----------|48| API / serverless functions | **Workers** | 100K req/day |49| Frontend SPA or SSR | **Workers + Static Assets** | Unlimited bandwidth |50| Relational database (SQL) | **D1** (SQLite) | 5M reads/day, 5GB |51| File/image/video storage | **R2** (S3-compatible) | 10GB, zero egress (credit card required) |52| Sessions, config, cache | **KV** (key-value) | 100K reads/day |53| User authentication | **Better Auth** (OSS) | Free |54| Background jobs | **Queues** | 10K ops/day |55| Existing Postgres/MySQL | **Hyperdrive** (proxy) | Included (100K queries/day free) |56| AI inference | **Workers AI** | 10K neurons/day, no credit card, no API key — just `[ai]` binding |57| Bot/spam protection | **Turnstile** | 1M req/month |5859## Dashboard vs CLI6061Almost everything is CLI-only via `wrangler`. The dashboard is only needed for:6263- **Account signup** (one-time) at dash.cloudflare.com64- **API tokens for CI/CD** at Profile > API Tokens65- **Custom domain setup** at Workers > Settings > Domains66- **Monitoring / analytics** for logs and metrics6768All resource creation (D1, R2, KV), deployments, migrations, and secrets are handled by `wrangler`.6970## Recommended Stacks7172### JavaScript/TypeScript (Production-ready)7374| Layer | Tool |75|-------|------|76| API | Hono (lightweight, Workers-native, fully typed) |77| ORM | Drizzle (D1 support, auto-generates Zod validators) |78| Frontend | React + Vite (or Astro, SvelteKit for SSR) |79| Routing | TanStack Router (file-based) |80| Server state | TanStack Query |81| Client state | Zustand |82| Auth | Better Auth (D1 + Drizzle + Hono adapter) |8384### Python (Open Beta)8586| Layer | Tool |87|-------|------|88| API | FastAPI (runs on Workers via Pyodide WASM) |89| CLI | `pywrangler` (wraps wrangler, uses `uv` for deps) |90| Note | Flask/Django NOT supported - only async frameworks |9192## Key Architecture Rules93941. **Max 300-400 lines per file.** Split aggressively.952. **Domain-driven folders.** Each feature is a self-contained directory.963. **No hardcoding.** Config in env vars or constants files.974. **Rich comments.** Explain the *why*, not just the *what* - target beginners.985. **Log everything.** Use structured logging so debugging is possible.996. **Zustand early.** Introduce state management before complexity hits.1007. **Validate all inputs.** Never trust client-sent data.1018. **ARCHITECTURE.md at root — MANDATORY.** Once the user decides on an architecture,102 immediately create `ARCHITECTURE.md` with: overview, mermaid diagram, services table,103 folder structure, data flow, and domain map. **Keep it up to date** — if the architecture104 changes, update this file FIRST. See `references/architecture-bestpractices.md` for template.105106## Reference Docs107108| Read when... | File |109|---|---|110| Brand new, no idea what any of this means | `references/beginner-onboarding.md` |111| Need project ideas or help deciding what to build | `references/beginner-onboarding.md` |112| First time using Cloudflare (ready to set up) | `references/getting-started.md` |113| **Building a fullstack app from scratch (start here)** | **`references/tutorial-todo-app.md`** |114| Choosing or configuring compute (Workers, Python, containers) | `references/compute.md` |115| Setting up database, file storage, cache, or queue | `references/database-storage.md` |116| Adding login/signup, bot protection, or access control | `references/auth-security.md` |117| Deploying via CLI, GitHub Actions, or managing secrets | `references/deployment-cicd.md` |118| Writing JS/TS backend + frontend (Hono, Drizzle, React) | `references/js-patterns.md` |119| Writing a Python backend (FastAPI on Workers) | `references/python-patterns.md` |120| Structuring projects, state management, security | `references/architecture-bestpractices.md` |121| Using Workers AI (LLMs, embeddings, image gen) | `references/workers-ai.md` |122| Something broke and need to debug | `references/debugging-logging.md` |123124## Work in Progress — Self-Correcting Skill125126This skill is **actively evolving**. If during execution any reference file contains127outdated APIs, incorrect imports, broken commands, or patterns that don't work:1281291. **Fix it immediately** in the reference file, or1302. **Ask the user** if they'd like the skill files updated with the correction.131132Don't silently work around inaccuracies — surface them and fix the source so future133sessions benefit. Treat every execution as a chance to improve the skill.134135## Agent Execution Flow136137This skill is designed for AI coding agents to **execute**, not just reference.138Every reference file contains copy-pasteable code and runnable commands.139140**Step-by-step for the AI agent:**1411421. **Understand the user's goal.** If they have no idea, read `beginner-onboarding.md` — help them143 pick a project from the ideas list. Ask what interests them, what they want to learn.1441452. **Discuss architecture.** Once a project is chosen, discuss which services are needed146 (use the Service Decision Matrix above). Let the user make the call on stack/features.1471483. **Document architecture IMMEDIATELY.** Create `ARCHITECTURE.md` at project root with:149 - Overview paragraph150 - Mermaid diagram (`references/architecture-bestpractices.md` has template)151 - Services table (service, purpose, binding name)152 - Folder structure153 - Data flow description154 This is the source of truth. **Update it every time the architecture changes.**1551564. **Build the app.** Follow `tutorial-todo-app.md` as the base pattern, adapting for the157 user's chosen project. Pull specific patterns from:158 - `js-patterns.md` / `python-patterns.md` — code patterns159 - `database-storage.md` — D1, R2, KV, Queues setup160 - `auth-security.md` — Better Auth, JWT, Turnstile161 - `architecture-bestpractices.md` — structure, security, state management1621635. **Deploy.** Follow `deployment-cicd.md` for CLI deploy + GitHub Actions setup.1641656. **Keep ARCHITECTURE.md current.** After adding any new service, domain, or changing166 data flow — update `ARCHITECTURE.md` and its mermaid diagram before moving on.167168---169> Source: [iaac-maai/structure_compliance_check](https://github.com/iaac-maai/structure_compliance_check) — distributed by [TomeVault](https://tomevault.io).170<!-- tomevault:4.0:skill_md:2026-05-22 -->