Every phase is behind you. This last lesson is the part of the plan people skim — and it’s the part that keeps working after the tutorial ends.
House rules
The plan calls these hard invariants, and the plan means it: if a requirement seems to conflict with one, you stop and ask — you never break the invariant. Here’s the whole set, arranged the way you’ll actually meet them:
Auth & sessions
- Credentials live only in env vars — never stored, logged, rendered, committed.
- A cookie counts only if the signature verifies, it’s unexpired, and
substill matches ADMIN_EMAIL. - Every non-GET with an Origin must match PUBLIC_BASE_URL. Every
nextgoes throughlocalPath().
Database
- Pooler-safe always: schema-qualified SQL, no session state, no named statements.
- snake_case in the database, camelCase in code — the mapping lives in one layer.
- Migrations: generated, read by hand, applied by hand. Deploys never migrate.
Pages & HTTP
- Post/redirect/get. A successful POST never renders — it 303s.
<%= %>for data;<%- %>only for includes. No inline script or style, ever.- Mutations are POST forms. A GET never changes anything.
Images & R2
- The browser gets tickets, never credentials: one key, one method, 5 minutes.
- The database stores keys; server-minted, HeadObject-verified, raster-only.
- DB first, R2 second. A failed object delete never fails a user’s request.
The footgun gallery
The plan keeps a table of traps — every one earned by somebody’s bad evening, kept so it doesn’t have to be yours. Tap through them:
The footgun gallery
Every one of these is a real paragraph in the plan. Tap a card to see what's under it.
The plan keeps this list so you never have to earn these scars yourself.
The boss fight: definition of done
The plan ends with a checklist, and “done” is not a feeling — it’s eight verifiable facts. Tick them honestly; each one runs a real thing:
Requirements checklist
Now make it yours
The plan doesn’t end at “done” — it ends with the extension playbook: the seams where new features plug in without touching the core. You’ve used every one of them already; here’s the map for the gallery’s missing features:
- Folders — a
folder_idonphotos, afoldersresource through the exact six-file pattern from lesson 8, and a?folder=filter on the list route. Two files change; nothing else does. - Likes — a
likestable (photo id + timestamp), aPOST /photos/:id/likeroute, and the count folded intophotoView. Your first write that isn’t admin-only — so it’s also your first rate-limit conversation. - Comments — the same shape, with the body validated by zod and rendered with
<%= %>. (Guess why the escaping rule matters most here.)
And beyond the gallery, the playbook covers the patterns for external APIs (wrap in a small class with a configured flag and a fake for tests), email (send() that logs in dev, fakes in tests, always best-effort), and scheduled work (a CLI script under src/scripts/, idempotent, dry-run by default — sweep-orphans.ts is the model).
The final mission
the plan's verify stepStart the boss fight. Run every check in the checklist above against the real app — the one on your machine, and then the one on the internet. Everything ticks → you're done, and you can say you did it the boring, reliable way.
npm test && npm run typecheck
curl http://localhost:8000/health
# and then... the production URL. The real one.The plan's own words for this moment: an app is done when all of it passes — not when it looks done.
Recap
House rules are invariants: they make whole bug categories impossible, not just fixed.
The footgun gallery exists so you never have to earn those scars yourself.
"Done" is eight verifiable facts — a checklist, not a feeling.
The extension playbook: new resources, external APIs, email, and scheduled chores all plug into existing seams.
You now hold the recipe — the gallery was just the first thing it can build.
The gallery still has somewhere to go — folders, likes, comments — and those lessons are on the roadmap. But the engine underneath them is finished, and it’s yours.
Up next
Folders & filtering
Group photos into folders and filter the public page.