JomMula

Gallery Blog · Lesson 12

House rules, traps & the boss fight

The last lesson is the plan's real payload: the invariants as house rules, the footguns as a gallery of traps you'll never step on, the definition of done as a boss fight — and how to grow the gallery next.

10 min readInvariantsfootgunsfinaleUpdated October 2026

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 sub still matches ADMIN_EMAIL.
  • Every non-GET with an Origin must match PUBLIC_BASE_URL. Every next goes through localPath().

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 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.

0/10 revealed

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

0/8 done

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_id on photos, a folders resource 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 likes table (photo id + timestamp), a POST /photos/:id/like route, and the count folded into photoView. 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 step

Start 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.

Previous: Deploy: one container, no surprises
13

Up next

Folders & filtering

Group photos into folders and filter the public page.

Coming soonView roadmap