cloudflare/vibesdk/app-file-structure
Claude Code and agent skill by cloudflare/vibesdk
- vendor
Checking that the SKILL.md file is still in the repository.
Author Cloudflare Worker Bundler-compatible apps that build and preview correctly inside a space. Use this skill whenever you scaffold, modify, or deploy a project that will be built with `@cloudflare/worker-bundler` (i.e. anything served from `/space/:name/preview/:branch/`). Covers wrangler config, project layout, static asset rules, server entry conventions, npm dependency limits, and the most common cause of blank previews (JSX in browser scripts).
Install
npx vskill@latest install cloudflare/vibesdk/app-file-structureSKILL.md
The same SKILL.md was published earlier as cloudflare/vibesdk/app-file-structure.
This skill teaches how to build apps that deploy cleanly through the space deploy pipeline. Every project committed to a space is built by @cloudflare/worker-bundler (createApp when there are static assets, createWorker when there are none) and served on a Dynamic Worker via WorkerLoader. Get the conventions right and the preview "just works". Get them wrong and you get a blank page, a 500, or a Build failed error.
How the pipeline works
When deploy_space(branch) is called, the space DO:
- Reads every file from the branch's working tree (skipping
.git/). - Parses
wrangler.json/wrangler.jsonc/wrangler.tomlformain,compatibility_date,compatibility_flags, and[assets]. - If
[assets].directoryis set, files under that directory become static assets served host-side byhandleAssetRequest. Everything else is built into a Worker viacreateApp(withserver: <main>). - If no assets directory is configured, only
createWorker({ entryPoint: <main> })is run. The output is loaded as a Dynamic Worker; all requests go to the Worker. - Previews are served at
/space/:name/preview/:branch/*. Responses withcontent-type: text/htmlare run throughHTMLRewriter, which prefixes root-relativesrc/href/actionattributes with the preview base path. JS-side fetches and dynamic imports are NOT rewritten.
Practical consequences:
- You can rely on root-relative `src="/foo.js"` and `href="/style.css"` in HTML. They will be rewritten to the preview path automatically.
- You cannot rely on root-relative paths inside JS strings:
fetch("/api/x"),new URL("/foo", location.origin), dynamicimport("/lib.js"). These hit the wrong path under the preview prefix. Use relative paths (./api/x,import.meta.url) or read the base path from<base href>/ a meta tag injected at build time. - The
<base href>tag is also rewritten if present — using it lets all relative URLs resolve against the preview path.
Project layout
A typical full-stack space project:
A static-only SPA can skip src/ entirely — just wrangler.json + public/ is enough as long as main points to a minimal pass-through worker or you accept that all requests fall through assets.
Wrangler config
Minimum viable wrangler.json:
Notes:
mainis required when there's any server code. The bundler also auto-detectssrc/index.ts,src/index.js,index.ts,index.jsif missing.compatibility_datedefaults to2025-04-01if omitted. Set it explicitly for newer features.- Add
"compatibility_flags": ["nodejs_compat"]only if you actually need Node built-ins. assets.directoryis the only way to ship static files. Files outside this directory are bundled into the Worker or ignored — they will not be reachable via URL.html_handling: "auto-trailing-slash"is usually what you want for multi-page sites; SPAs should also setnot_found_handling: "single-page-application"so deep links returnindex.html.
TOML works too (wrangler.toml), but the parser only handles top-level scalar fields plus an [assets] table — no inline tables, no env overrides. Prefer JSON.
Server entry: one Durable Object class named App
Your entire backend is one Durable Object. Your main module exports a class named App extending DurableObject. The platform loads it as a Cloudflare Durable Object Facet of the host SpaceDO and forwards every non-asset request — including WebSocket upgrades — to your App.fetch(request).
Do not `export default { fetch }`. A default fetch handler will be ignored. There is no separate worker; the DO is the worker.
Or with Hono inside the DO:
When [assets] is configured, static files take priority — your fetch only sees requests that didn't match an asset. For a SPA, put index.html in public/ and App.fetch only handles /api/*.
State and storage
State lives on this.ctx.storage. No env.DB exists; you do not need to declare any binding. The DO's storage is a per-(space, branch) SQLite database that survives redeploys.
this.ctx.storage.sql.exec(sql, ...params)— full SQLite. Returns a
cursor with .toArray(), .one(), .columnNames, etc.
this.ctx.storage.kv.get(key)/.put(key, value)— simple KV
backed by SQLite.
this.ctx.storage.transactionSync(() => { ... })— atomic batch
inside the same DO instance.
Use the DO's storage for all persistent state — users, sessions, content, settings, anything that should survive a reload. Do not use localStorage or sessionStorage for primary data; they are per-browser, per-origin, and lost on incognito or any other browser.
WebSockets
The platform forwards Upgrade: websocket requests transparently into App.fetch. Use the standard Durable Object hibernation API:
acceptWebSocket + webSocketMessage is the right pattern for multi-connection use cases (chat rooms, multiplayer, presence) because the DO can hibernate between messages without losing connections.
Per-entity grouping (chat rooms, per-user records)
You get one App DO per (space, branch) — a single instance, not a namespace. Do not call idFromName or try to declare a DO binding in wrangler.json; both are rejected. For multi-room / multi-user state, partition rows with a column in the App's SQLite:
Then route by room_id inside App.fetch. SQLite is fast enough that sharing the same table across rooms is fine for prototyping; if you later need stronger isolation, attach room_id to a tag and use acceptWebSocket(ws, [room_id]) so getWebSockets(room_id) returns only that room's sockets.
What you cannot declare
- `durable_objects.bindings` in `wrangler.json`. The platform
extracts your App class automatically. Adding bindings fails the deploy with a clear error.
- `new_sqlite_classes` / migrations. Same reason. Your App's
storage is set up by the platform.
- `d1_databases`, `r2_buckets`, `kv_namespaces`. Not available.
Everything goes in this.ctx.storage.
Static asset rules (read this twice)
This is where most preview failures happen. The browser eventually runs your assets — the bundler does not transform them. So:
NEVER ship JSX in a `<script type="module">` (or any other script tag). Browsers cannot parse JSX.
This page will be blank with a SyntaxError: Unexpected token '<':
Fix one of these three ways:
- Pre-compile — write JSX in a build step (Vite/esbuild/tsup) and emit plain JS into
public/. Best for production. - `React.createElement` by hand — works without a build step but is verbose.
- `@babel/standalone` — only for prototypes. Load Babel before the script and use
type="text/babel". The modern@babel/preset-reactdefaults to the automatic JSX runtime, which emitsimport { jsx } from "react/jsx-runtime". Browsers will reject that bare specifier unless your importmap maps it. Always ship a complete importmap alongside the Babel script:
``html <script type="importmap"> { "imports": { "react": "https://esm.sh/react@18.3.1", "react/jsx-runtime": "https://esm.sh/react@18.3.1/jsx-runtime", "react-dom": "https://esm.sh/react-dom@18.3.1", "react-dom/client": "https://esm.sh/react-dom@18.3.1/client" } } </script> <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script> <script type="text/babel" data-type="module" data-presets="react"> import React from "react"; import { createRoot } from "react-dom/client"; const App = () => <div>hi</div>; createRoot(document.getElementById("root")).render(<App />); </script> ``
data-type="module" is required for import to work inside the Babel script. Import React from the importmap key ("react") — not from a hard-coded esm.sh URL — so your code and Babel's emitted react/jsx-runtime import resolve to the same React instance.
If you really cannot ship react/jsx-runtime in the importmap, force Babel to the legacy classic runtime instead so it emits React.createElement calls and never touches react/jsx-runtime:
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files. Certified 16 Jun 2026.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingworker/agents/think/skills/app-file-structure/SKILL.md
Popularity
- Repository stars
- 5,092
- Repository forks
- 1,211
- 7-day trend score
- 43
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/cloudflare/vibesdk/app-file-structure)