{"contract_version":"2026-11-27b","text":"## What Flinger runs — choose only from this\n\n**Node** — Express, Fastify, Next.js, Nuxt, SvelteKit, Astro, Remix\n**Python** — FastAPI, Flask, Django, Streamlit\n**Static** — plain HTML/CSS/JS, any framework that builds to files\n**Frontend builds** — React, Vue, Svelte, Solid\n\nA Dockerfile overrides all of this and runs exactly as given.\n\n**Declined by name** — an app in one of these is refused at upload, with an explanation:\n\na Deno app, a .NET app, an Elixir app, a Java app, a Laravel app, a PHP app, a Ruby on Rails app, a Rust app\n\n## What is provided\n\n**Database** — PostgreSQL, one database per app, provisioned automatically.\n  DATABASE_URL and SUPABASE_URL / SUPABASE_ANON_KEY point at the SAME database. Do not list either in .env.example — Flinger supplies them.\n\n**Schema** — Flinger runs the app's own migrations on EVERY deploy, in filename order, before the new code goes live.\n  Write every migration so re-running it is harmless — CREATE TABLE IF NOT EXISTS, ADD COLUMN IF NOT EXISTS, ON CONFLICT DO NOTHING, never a bare CREATE TYPE. Name them with a timestamp prefix. Do not run them yourself and do not shell out to any database command-line tool; none exists where the app is built. Framework-native sync in the start command (prisma db push, alembic upgrade head) is fine — Alembic in particular MUST do this, because it writes Python rather than SQL.\n\n**Auth** — Email sign-in for the app's own users, provisioned automatically (supabase-js's auth calls work against it).\n  auth.users exists before your migrations run, so foreign keys to it are fine. Use auth.uid() and the authenticated role in your policies.\n  Sign-in, confirmation and password-reset emails are sent for you, from the app's own name and address, in a styled template. You do not need an email provider, an API key, or your own templates — do not add one.\n  Flinger grants your app's own server connection access to everything your migrations create, in every schema, after every deploy. Do not add GRANT statements for it. Don't build your own database roles or a setup step the server needs before it starts — Flinger provisions the app's database login.\n  To know who really owns the app, read the FLINGER_OWNER_EMAIL variable on the server: it is the email of the Flinger account that claimed the app, set by Flinger — not by whoever signs in first. Give the admin role to the user with that email, and only after their email is confirmed. It is empty until the app is claimed, so until then give nobody the admin role.\n  Create the supabase-js client with auth: { flowType: 'pkce' }. Sign-in links and Google sign-in then come back with a short ?code= that your page exchanges for a session, instead of the session tokens themselves sitting in the address bar, where browser history, logs and referrers can leak them.\n  *Watch out:* A password reset has a RETURN TRIP: the link comes back to your app with a recovery token in the URL hash, and your page must read it before anything else runs and show a 'choose a new password' screen. A reset flow that emails a link and has nowhere for it to land is the most common way this is got wrong.\n  *Watch out:* On every page load, check the URL hash for `error=` before anything else. A link that was superseded (asking for a second email invalidates the first) arrives as #error=access_denied&error_code=otp_expired — with no page to explain it, somebody gets a blank screen and a frightening URL. Show a plain line instead: that link is no longer valid, here is a button to send a fresh one. Never show the raw code.\n\n**Build** — Flinger builds your app and serves what the build produces.\n  If your build puts files anywhere other than the default, say so in FLING.md: `Output: dist` — a plain folder inside your app. Anything that changes directory (cd ...), chains commands (&&), or walks upwards (../) is ignored: it points outside the upload.\n  Put a content hash in your asset filenames — every modern build tool does this by default, so just do not switch it off. Flinger always revalidates your HTML so an update is visible on a normal reload; hashed assets are what make that safe and still fast.\n  Undeclared, Flinger guesses from your build script; where it can't, the host looks in public/ — a build writing to dist/ then fails with 'No Output Directory named public found'.\n  *Watch out:* A hand-written build script is fine, and it is the only thing that knows where its output lands — so say where.\n\n**Fling Md** — The one file that tells Flinger how to treat your app.\n  Start FLING.md with `Runtime: static | serverless | server` and one line of why. Static is files only; serverless is pages plus functions under api/; server is a process that must keep running — the scarcest of the three, so claim it only if you need it. Also declare `Shared data: yes|no — <why>`: will anyone see data another person or device entered (owner/admin view, roles, a login, orders, attendance)? If yes the runtime MUST be serverless or server with a database — `Shared data: yes` with `Runtime: static` is refused; localStorage never leaves one browser. Choosing server REQUIRES a start command: name it on the same line (`Runtime: server — start: npm start`) and make that exact script exist in package.json (or pyproject.toml). Without one it cannot deploy. Optional: `Output: <folder>`, `Routes: single-page` (unknown addresses open index.html) `Health: GET /api/health` (/health reaches it) and `Embed: yes` (other sites may frame it; otherwise they can't). Never write the host's config files — Flinger writes them from these.\n  Then list every address and what it is for — especially the owner's page — and any first-run step, like claiming the site or setting a password. Also: frontend, backend, database, build and start commands, required private settings, health endpoint. Never secret VALUES.\n\n**Loading State** — What somebody sees before your data arrives.\n  NEVER SHIP DEFAULT COPY THAT THE API WILL REPLACE. Anything driven by data starts as a skeleton or hidden, never as a plausible sentence — otherwise the first visitor reads a headline that silently turns into a different headline, which looks like a broken deploy.\n  *Watch out:* The data plane sleeps when idle, so the first fetch after a quiet spell takes seconds. Wake it before you fetch, and if you keep the last content in localStorage, returning visitors see the real thing instantly.\n\n**How It Looks When Shared** — The title, icon and preview card people see before they open the app.\n  Always put these in <head>: a <title> that is the app's real name (not 'Vite App' or 'index'), a <meta name=\"description\">, og:title, og:description, og:image, og:url, og:type=website, twitter:card=summary_large_image, and a favicon. Relative paths are right: Flinger turns og:image and og:url into full https:// addresses.\n  Ship favicon.svg (an emoji or a letter in a coloured square is plenty) and apple-touch-icon.png at 180x180, and make og:image a 1200x630 PNG or JPEG (previews ignore SVG).\n  *Watch out:* Without these, a shared link unfurls as a grey box.\n\n**Pages And Uploads** — Two things that work on your machine and fail once deployed.\n  EVERY PAGE NEEDS A REAL ADDRESS: it must resolve on a direct visit and on a refresh. Register real pages BEFORE any catch-all — a page existing only as admin.html shows the home page at /admin, which has locked owners out of their own apps.\n  UPLOAD FROM THE BROWSER STRAIGHT TO STORAGE, with a signed URL if needed. Never send a file through a function in api/: bodies there are capped at a few megabytes, so your test images pass and somebody's phone photo fails.\n\n**Who Can Open It** — Flinger can put a sign-in gate in front of the whole app.\n  Do NOT build a password page or invite list to control who can REACH the app — the owner turns that on in Flinger, and two gates means signing in twice.\n  *Watch out:* Different from the app's OWN accounts: if your app has users with their own data, build that with auth as usual.\n\n**Storage** — File storage, kept in the app's own region.\n  Use storage.from(\"bucket-name\"). Flinger reads the bucket names out of your code and creates them at deploy. Never write to the server's disk. Never call createBucket in code — it needs a service role a browser app should not have, and fails with a bare 400.\n\n**Social Signin** — Sign in with Google works with no Google setup: Flinger supplies a Google client. Facebook, Apple, GitHub and the rest are NOT provided.\n  Implement Google OAuth in your own server code (Flinger's built-in sign-in is email only; supabase.auth.signInWithOAuth will not work). Read GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET and GOOGLE_REDIRECT_URI from the environment, EMPTY in .env.example — Flinger fills them in, and the owner may replace them with their own. Send GOOGLE_REDIRECT_URI to Google exactly as given (empty: https://<request host>/auth/google/callback), and send state = fl1:<request host>:<base64url of your callback path>:<your own random value> — Flinger's one return address reads it to send the person back to that path; check the whole value as usual. Ask Google only for openid, email, profile. The app must load without them.\n  Other providers (Facebook: FACEBOOK_APP_ID / FACEBOOK_APP_SECRET) are the person's own: read their keys from the environment, EMPTY in .env.example, build the callback from the request host.\n\n**Notifications** — Web notifications to people who said yes, even with the tab closed — through Flinger's Firebase, nothing to set up.\n  In the page add <script src=\"/__flinger/push.js\" defer></script>, then from a click (never on load) call Flinger.push.enable({userRef: <your signed-in user's id, optional>}) — it asks the visitor and resolves {ok, reason}; also Flinger.push.status(), .disable() and .identify(userRef) after sign-in. Do NOT write a service worker or add Firebase. From the server: POST $FLINGER_PUSH_URL with Authorization: Bearer $FLINGER_PUSH_KEY and JSON {title, body, url, icon, tag, user_ref} (user_ref left out = everyone). Flinger supplies both variables — never list them in .env.example. A site with no server sends from Flinger → Manage → Notifications.\n  Explain why before asking, and treat denied or unsupported quietly (an iPhone only supports it once the app is on the Home Screen). A strict Content-Security-Policy must allow https://www.gstatic.com for scripts.\n\n**Email** — Sign-in, confirmation and reset emails are sent for you; any other email is the app's own.\n  Other email: send from server code with Resend (RESEND_API_KEY), EMPTY in .env.example, never from the browser. No key: Flinger sends it (`from` replaced); use `resend` package or `${process.env.RESEND_BASE_URL || 'https://api.resend.com'}/emails`.\n\n**Secrets** — Credentials are encrypted, injected as env vars, and never reach the browser.\n  Put ONLY credentials fetched from somewhere else in .env.example, with empty values. Name any self-comparing random value with one of the generated suffixes and nobody is ever asked for it.\n  Supplied automatically, never put in `.env.example`: `DATABASE_URL`, `NEXT_PUBLIC_SUPABASE_ANON_KEY`, `NEXT_PUBLIC_SUPABASE_URL`, `SUPABASE_ANON_KEY`, `SUPABASE_KEY`, `SUPABASE_SERVICE_ROLE_KEY`, `SUPABASE_URL`, `VITE_SUPABASE_ANON_KEY`, `VITE_SUPABASE_URL`, `PORT`\n  Generated automatically — name a value with one of these and nobody is ever asked for it: `*_cookie_secret`, `*_csrf_secret`, `*_encryption_key`, `*_jwt_secret`, `*_nextauth_secret`, `*_session_secret`, `*_verify_token`\n  Given a default, so they do not belong in the environment: `anthropic_model`, `host`, `log_level`, `node_env`, `openai_base_url`, `openai_model`, `timezone`, `whatsapp_api_version`\n\n**Domains** — Every app gets a subdomain immediately. A custom domain can be bought or connected.\n  Never hardcode a hostname. Derive absolute URLs from the incoming request.\n\n**Realtime** — Realtime over WebSockets (socket.io or ws): chat rooms, multiplayer, live updates. It runs on an always-on server.\n  Serve it from the app's own server, on PORT, at a path on the app's address. Reconnect on the client when it drops (an update or a wake closes it). Keep what must outlast a connection in the database.\n\n**Scheduled** — Scheduled jobs (UTC).\n  In FLING.md: `Cron: <min hour day month weekday> <path>`, e.g. `Cron: 0 5 * * * /api/digest`; the path does the job within a request. A long-running server may use node-cron instead.\n\n**Rollback** — The last 10 versions are kept; the owner can restore any, by time or by name.\n  Don't build your own version history.\n\n## What cannot run, and what to build instead\n\n**Redis** — Cache in Postgres, or a signed cookie. (An app requiring it cannot deploy at all.)\n**Background queues (BullMQ, Celery, Sidekiq)** — A status column and a 'process next' action.\n**A persistent filesystem** — Object storage — see the storage capability.\n**Work longer than about 30 seconds in one request** — Split it into steps the person triggers.\n\n## Content the owner can change: /admin\n\n- Decide this unasked: if the owner will want to change what the app shows (items, prices, people, photos, hours, contact details, page text), or you invented any of it, build an editor at /admin and /admin/. Not for a game or calculator. This overrides advice to ship a single index.html.\n- Plain forms (never raw JSON) to add, change and remove every item, plus name, logo, colours and search title and description. Save to the database by migration (pictures: storage.from(\"site\")); public pages read it, with the starting content as fallback. Mark invented entries \"Example\", with \"Clear examples\".\n- Owner only, checked on the server. Without app accounts: ADMIN_PASSWORD (empty in .env.example) and a *_SESSION_SECRET-signed session; until it is set, /admin says to add it in Flinger.\n- It counts as an app with a database. If the plan has no room, let the person choose: the editor, or none.\n\n## Always-on server: check before you choose it\n\n- The plan counts always-on servers: Free and unclaimed links include none, Pro 1, Business 3.\n- Choose one only if a process must keep running (a connected bot, WebSockets shared between visitors, a worker or queue, Streamlit). A Procfile, a Dockerfile or a Node server serving its own pages also make an app always-on. Otherwise use pages plus functions under api/.\n- Flinger asks before putting one online: tell the person why and let them choose.\n\n## The rules that most often break deploys\n\n1. Bind to the PORT environment variable. Never hardcode 3000 or 8000, never a fallback port, never localhost anywhere in the app.\n2. Target Node 22: set \"engines\": {\"node\": \"22.x\"} in package.json. Node 20 is past end-of-life, and current libraries — supabase-js included — refuse to start on it.\n3. Exact build and start commands in package.json scripts (Node) or pyproject.toml. Use a Procfile only for a Python app that genuinely needs a long-running process — a Procfile is read as needing an always-on server, which starts slower and costs more.\n4. Expect the first call after a quiet spell to be slow. An app's database, sign-in and storage sleep when idle, so a visitor's first action can take several seconds or come back 502/503/504. Do three things: (1) on page load, fire a request at {SUPABASE_URL}/auth/v1/settings and {SUPABASE_URL}/rest/v1/ and ignore the result, so they wake while the person is reading; (2) retry a few times with a growing wait, but only where repeating the request is SAFE — 502 and 503 mean it never arrived, while 504 means it timed out and the work may already be done, so retrying a POST after a 504 sends a second reset email or turns a sign-up into \"already registered\"; retry 502/503 for anything and 504 only for reads — with supabase-js, pass your own fetch as createClient(url, key, {global: {fetch: myFetch}}) so its own calls retry too; (3) never show \"something went wrong\" on the first failure.\n5. If your app has passwords, give it a way back in. Flinger sends the reset email for you. Add a \"forgot password\" action that calls auth.resetPasswordForEmail(email, {redirectTo: location.origin}), and when somebody returns from that email the address will contain type=recovery and they will already be signed in — show a \"choose a new password\" form and call auth.updateUser({password}). Without the second half the link signs them in and then strands them.\n6. A sign-up that times out may still have worked. If signing up returns \"already registered\" moments after a timeout, sign the person in instead of showing an error.\n7. Every endpoint must be called by something in the front end. No placeholder handlers, no button that does nothing — include an endpoint→control table in FLING.md.\n8. Keep test tooling out of the production install. A browser download during build fails the deploy.\n9. Model choices belong in code with a default, not in the environment.\n10. A /health route answers 200 at once WITHOUT touching the database — one that waits on a sleeping database makes a working app look down.\n11. Visitors see only ok/down from /health; put no secrets in it.\n12. Payment webhooks: verify the signature on the RAW body; Flinger makes RAZORPAY_WEBHOOK_SECRET.\n13. Pin every dependency to a version range in package.json — never \"latest\" or \"*\".\n14. On Express 5, a catch-all route is '/{*splat}' — '*' crashes the server at startup.\n15. Flinger opens each new version in a real browser before it goes live: the first screen must render before its data arrives — never .map or read a field on data that may not exist yet.\n16. An app that runs its own headless browser (Playwright, Puppeteer) needs `Runtime: server` — Flinger installs the browser and its libraries.\n17. Don't set temperature, top_p or top_k when calling claude-haiku-5-5 — it refuses them.\n18. Store and send times in UTC (timestamptz; ISO 8601 with Z); convert to local time only for display.\n\n## Before you finish — check every line\n\n- [ ] Runtime: server → the start command it names exists as that exact script.\n- [ ] The build writes anywhere but the default → FLING.md says `Output: <folder>`.\n- [ ] The first screen renders with no data yet — nothing reads a field of data that hasn't arrived.\n- [ ] If you can send web requests: POST {\"files\": {\"path\": \"text\"}} to https://go.flinger.ai/api/v1/preflight and fix every must_fix until the verdict is ready. Send User-Agent: flinger-skill (without one: 403, error 1010).\n- [ ] No secret in client code. Anything named VITE_*, NEXT_PUBLIC_* or PUBLIC_* is public — it ships in the bundle. Read secrets server-side only.\n- [ ] Every page opens on a direct visit and on a refresh.\n- [ ] FLING.md is present and its first line is the Runtime line.\n- [ ] BRIEF.md (what it is, how to run it, key decisions, rules not to break — about 15 lines) and BUILD_LOG.md (newest first: what changed, done, pending) sit beside FLING.md; update both on every change.\n- [ ] /health doesn't touch the database.\n- [ ] Anything the owner would change, and every invented example, is editable at /admin and saved in the database.\n- [ ] Times are UTC; only the display is local.\n\n## Then tell the person\n\nIn your own words — warm, short, no jargon — tell them: it's ready; if you could run commands, give them the live link and the claim link; if not, a .zip to upload at go.flinger.ai; for any change, come back to this chat and put the new version up the same way (same link, data kept); and Flinger keeps the previous version, so they can go back.\n\n*Flinger contract 2026-11-27b — fetched from `/v1/capabilities`, generated from the platform's own code.*"}