fleet init gives you a complete, working app in a handful of files. Keep this layout and let Fleet handle bundling, serving, HTTPS, and worker lifecycle for you.fleet.json — app ID, name, scheduled jobs, and optional HTML head settings (title, themeColor, icon, manifest).client/index.tsx — Preact browser entry point.client/style.css — stylesheet imported by the client.server/index.ts — server queries, mutations, and jobs.public/ — optional static files served from the app root (for example /icon.svg or /manifest.webmanifest).fleet.d.ts — TypeScript definitions for fleet/client, FleetCtx, and FleetDb.AGENTS.md — concise instructions so any coding agent understands how Fleet works..env.fleet.server — server-only environment variables, automatically ignored by Git.https://notes.fleet. Keep the generated id in fleet.json — Fleet uses it to locate the app's persistent SQLite database.server/index.ts with queries, mutations, and optional jobs:export default { queries: { notes(ctx) { return ctx.db.get('notes') ?? []; }, }, mutations: { addNote(ctx, input) { if (typeof input?.text !== 'string' || !input.text.trim()) { throw new Error('Enter a note.'); } const note = { id: crypto.randomUUID(), text: input.text.trim(), }; const notes = ctx.db.get('notes') ?? []; ctx.db.set('notes', [note, ...notes]); return note; }, }, };
ctx.db write from that call.ctx: ctx.user.id (the owner identity), ctx.db (get, set, delete, list), ctx.env (from .env.fleet.server), ctx.log(...), and ctx.runId (for scheduled jobs).input on the server.react / react-dom to preact/compat), so you don't need to install Preact inside each app. Import useQuery, useMutation, and call from fleet/client:import { render } from 'preact'; import { useQuery, useMutation } from 'fleet/client'; import './style.css'; function App() { const { data: notes, error } = useQuery('notes'); const addNote = useMutation('addNote'); if (error) return <p role="alert">{error.message}</p>; if (notes === undefined) return <p role="status">Loading…</p>; return ( <main> <h1>My notes</h1> <button onClick={async () => { try { await addNote({ text: 'Hello from my app' }); } catch (err) { alert(err.message); } }} > Add a note </button> {notes.map((note) => ( <p key={note.id}>{note.text}</p> ))} </main> ); } render(<App />, document.getElementById('app'));
useQuery(name, input?, { pollMs? }) returns { data, error } and polls every 10 seconds while the tab is visible. Pass { pollMs: false } or { pollMs: 0 } to disable polling.useMutation(name, { invalidate? }) refreshes all active queries by default. Pass { invalidate: ['notes'] } to refresh specific queries or { invalidate: false } to skip refreshing.call(kind, name, input?, { keepalive? }) invokes an operation directly without refetching queries — handy with { keepalive: true } for small writes on page unload.fleet logs APP, so your agent can spot frontend crashes without opening DevTools.public/. Fleet snapshots public/ alongside each build and serves those files from the site root (for example, public/icon.svg is served at /icon.svg).<head> in fleet.json:123456{ "title": "My Notes", "themeColor": "#101214", "icon": "/icon.svg", "manifest": "/manifest.webmanifest" }
.env.fleet.server and read them with ctx.env inside server handlers. Fleet automatically adds .env.fleet.server to .gitignore and never includes it in browser bundles. Just make sure your server handlers don't return or log secret values.fleet logs APP.ctx.db, not module-level variables. See data and jobs.