---
name: cf-fullstack-web
description: |
Build, harden, and deploy full-stack websites, web apps, and real-time browser games on React 19 + TanStack Start + Cloudflare Workers using standard npm/pnpm, git, and Wrangler CLI (D1, R2, KV, Durable Objects, Containers).
Use when: "build a website", "create a landing page", "build a full-stack Cloudflare Worker app", "add D1/R2/Durable Objects", "build a multiplayer browser game", "add scroll-scrub video storytelling", "deploy with wrangler", or "run security and SEO audit".
For 3D models, rigged GLBs, PBR textures, spritesheets, and game audio, pair with the sibling `pbr-3d-assets` skill.
---
# Full-Stack Web & Games on Cloudflare Workers (`wrangler`)
Build and ship production **React 19 + TanStack Start** SSR applications and real-time browser games deployed to **Cloudflare Workers** via standard `npm` / `pnpm`, `git`, and the **`wrangler`** CLI.
---
## 1. Choose the Project Archetype
Clarify up front if the request is ambiguous:
1. **Website (`website`)** — brand landing page, portfolio, editorial site, or product showcase:
- Ask once whether the user wants **Animated (scroll-scrub camera journey, recommended)** (`references/scroll-scrub.md`) or **Non-animated** (bespoke typography/imagery + micro-motion).
- Follow `references/design-recipe.md` (distilled craft rules) and `references/design-taste-frontend.md` (full anti-slop playbook) + `references/image-to-code.md`.
- Generate bespoke visual assets via `../../scripts/generate_image.py` (never leave placeholder/stock URLs in production).
2. **Full-Stack Web App (`app`)** — SaaS tool, creative workspace, dashboard, or AI-powered web tool:
- Uses D1 (SQLite), R2 (object storage), KV (cache/sessions), and optional Cloudflare Containers for heavy jobs (ffmpeg, headless rendering).
- Start from the dark workspace patterns in `references/app-layouts.md` (Studio, Preset, ToolDetail, ConfigureWorkspace, Compare, Wizard).
- Proxy any external AI/API keys strictly server-side via `env.*` secrets (`npx wrangler secret put`).
3. **Browser Game (`game`)** — single-player or real-time multiplayer room game:
- Pure deterministic state reducer (`src/logic.ts`: `meta`, `setup`, `validateAction`, `applyAction`, `isGameOver`, `viewFor`) backed by a Durable Object WebSocket room (`src/room.ts`).
- Follow `references/game-flow.md` + `references/game-design-system.md` (write `design/assets.csv` first), and use the sibling **`pbr-3d-assets`** skill for spritesheets, PBR textures, rigged GLBs, and normalized audio.
---
## 2. Stack & Cloudflare Workers Architecture
- **Framework:** React 19 + TanStack Start (file-based routes in `src/routes/`, server entry in `src/server.ts`).
- **Styling:** Tailwind CSS (no Next.js, Remix, Astro, or separate Express/Hono backend — API routes live under `src/routes/api/**`).
- **Config:** `wrangler.jsonc` declares Worker entry, assets directory, and Cloudflare bindings.
### Typical `wrangler.jsonc` bindings
<!-- ‹guest · 2026-12-04› -->
```jsonc
{
"$schema": "node_modules/wrangler/config-schema.json",
"name": "my-app",
"main": "src/server.ts",
"compatibility_date": "2025-09-01",
"compatibility_flags": ["nodejs_compat"],
"assets": {
"directory": "dist/client",
"binding": "ASSETS"
},
"d1_databases": [
{ "binding": "DB", "database_name": "my-app-db", "database_id": "<id>" }
],
"r2_buckets": [
{ "binding": "BUCKET", "bucket_name": "my-app-uploads" }
],
"kv_namespaces": [
{ "binding": "CACHE", "id": "<id>" }
],
"durable_objects": {
"bindings": [{ "name": "ROOM", "class_name": "GameRoom" }]
},
"migrations": [
{ "tag": "v1", "new_sqlite_classes": ["GameRoom"] }
]
}
```
### Standard `wrangler` CLI lifecycle
```bash
# 1. Install & authenticate Wrangler once
npm install -D wrangler
npx wrangler login # or configure CLOUDFLARE_API_TOKEN in environment
# 2. Provision storage bindings (as needed)
npx wrangler d1 create my-app-db
npx wrangler r2 bucket create my-app-uploads
npx wrangler kv namespace create CACHE
<!-- ‹guest · 2026-12-04› -->
# 3. Local dev & D1 migrations (Miniflare local SQLite/R2/KV)
npx wrangler d1 migrations apply my-app-db --local
npm run dev # or: npx wrangler dev
# 4. Production secrets (never commit keys to git or wrangler.jsonc)
npx wrangler secret put OPENAI_API_KEY
# 5. Typecheck, build, migrate remote D1, and deploy
npm run typecheck
npm run build
npx wrangler d1 migrations apply my-app-db --remote
npx wrangler deploy # or `npx wrangler pages deploy dist` for static/Pages builds
```
---
## 3. Hard Runtime & SSR Rules (TanStack Start + Workers)
1. **SSR safety:** every route renders on the server per request. Never read `window`, `document`, `localStorage`, `navigator`, or `matchMedia` at module top level or during render — put browser globals inside `useEffect` or event handlers, and `React.lazy` WebGL canvases.
2. **Server-only bindings & secrets:** import `{ env } from "cloudflare:workers"` only inside `createServerFn`, `src/routes/api/**`, `src/server.ts`, or `*.server.ts`. Never pass secrets or raw DB rows with sensitive columns into React props (SSR serializes props into HTML).
3. **Mutating `createServerFn`:** use `createServerFn({ method: "POST" })` with `.validator(...)` (`zod`) for mutations (DB writes, generation submits, workspace updates); use `GET` only for pure reads.
4. **Binary uploads via multipart server routes:** never pass `File`, `Blob`, `ArrayBuffer`, or base64 blobs through JSON `createServerFn` arguments. Upload via `FormData` to a TanStack server route (`src/routes/api/upload.ts`), validate MIME + byte size, sanitize the R2 key, write to `env.BUCKET.put(key, bytes)`, and return the reference key.
5. **Route tree sync (`routeTree.gen.ts`):** whenever you add/rename routes under `src/routes/`, run `npm run dev` or `npm run build` so TanStack Router regenerates `src/routeTree.gen.ts` before `npm run typecheck`.
6. **Worker isolation & memory:**
- Zero mutable `let` or mutable `const cache = {}` at module scope (shared across concurrent isolate requests).
- Use `crypto.randomUUID()` / `crypto.getRandomValues()` instead of `Math.random()` on the server.
- Use `crypto.subtle.timingSafeEqual()` for secret/webhook signature checks.
- Stream large upstream bodies (`new Response(upstream.body)`) instead of buffering into Worker RAM (128 MB limit).
- Wrap every response (including 301 trailing-slash redirects and 500s) in `applySecurityHeaders()` (`src/lib/security-headers.server.ts`).
7. **Cloudflare Containers (optional heavy compute):** for `ffmpeg`, headless browsers, or multi-minute jobs, pair a `Container` Durable Object (`@cloudflare/containers`) with `app/container/Dockerfile`. Boot patiently in `ctx.waitUntil()`, keep `tick` status polling fast, persist job state in D1, and stop only when no jobs remain active.
---
## 4. Pre-Deploy Quality Gates (Run Before `wrangler deploy`)
1. **Mechanical craft gate (`references/review-rubric.md`):**
- Zero placeholders (`lorem`, `REMOVE_THIS`, `<brand>`), zero em-dashes (`—`/`–`) in visible UI copy, no `h-screen` (use `h-dvh`), no `opacity-0` trapped behind `whileInView`, `prefers-reduced-motion` guard on every animated element, and if `Animation mode: animated-website`, verify `scroll-scrub.tsx` + encoded desktop/mobile MP4s + first-frame posters are wired.
2. **Security audit (`references/security.md`):**
- Every D1 query uses `.bind(?)`, every private server function / API route checks session + resource ownership (`AND user_id = ?`), `applySecurityHeaders()` wraps all responses (with `media-src 'self' blob: https:` if using scroll-scrub), and `npm audit` is clean.
<!-- ‹guest · 2026-12-04› -->
3. **SEO & GEO audit (`references/seo.md`):**
- Unique `<title>` + `<meta name="description">` + `canonical` + absolute `og:image` in route `head()`, `/robots.txt` + `/sitemap.xml` server routes live, trailing-slash 301 normalization active in `src/server.ts`, JSON-LD (`StructuredData`) matches visible text, and all 10 audit checks pass with zero FAILs.
---
## 5. Reference Index
- **Frontend & Visual Craft:**
- `references/design-recipe.md` — Concise craft rules (type, palette bans, hero discipline, copy rules, bespoke chrome).
- `references/design-taste-frontend.md` — Full anti-slop frontend playbook, dials, animation skeletons, dark-mode tokens.
- `references/image-to-code.md` — Deep reference-board extraction, anti-drift, bespoke CTA garment catalog.
- `references/app-layouts.md` — Six dark workspace layouts (`Studio`, `Preset`, `ToolDetail`, `ConfigureWorkspace`, `Compare`, `Wizard`).
- **Scroll-Scrub Animated Websites:**
- `references/scroll-scrub.md` — Single-shot & multi-leg seam-locked scroll-scrub architecture and footage contract.
- `references/scroll-scrub-asset-video.md` — Deterministic `ffmpeg` script for boundary frames, desktop/mobile encodes, and posters.
- `references/scroll-scrub-asset-react.md` — SSR-safe React/TanStack scroll-scrub component + Blob prefetcher.
- `references/scroll-scrub-asset-css.md` — Layout CSS contract for the scroll-scrub stage.
- **Browser Games:**
- `references/game-flow.md` — Pure `logic.ts` contract, Durable Object WebSocket rooms, `wrangler` testing/deploy.
- `references/game-design-system.md` — Game profile, core loops, `design/assets.csv` manifest, performance laws.
- **Hardening, SEO & Verification:**
- `references/security.md` — Cloudflare Worker threat model, 12 hardening rules, OWASP Top 10 audit.
- `references/seo.md` — TanStack Start `head()`, `robots.txt` / `sitemap.xml`, JSON-LD Schema, GEO, 10-point SEO audit.
- `references/review-rubric.md` — Pre-deploy mechanical checklist.
این نسخه با نشانهگذاری اختصاصی حساب شما نمایش داده میشود. برای نصب سریع، به تب نصب و راهاندازی بروید.