The store keeps a Menu Set's state in the directory layout (drafts/ versus published/) and its metadata in a manifest, with publishing as a single directory rename. Editing is allowed on Drafts only, so a published menu can never change under a customer. Stages 2 and 3 of docs/plan.md, with tests.
11 KiB
Menu app — agreed plan
Replaces the scp-a-JPG workflow for menu.hopsngrains.com with a small self-hosted app that uploads, orders, previews and publishes Menu Sets. Verified against the current environment by read-only reconnaissance of monoco.
What exists today
- Caddy (80/443, TLS) →
reverse_proxy nginx-menu.hopsngrains.com:80→nginx:alpinewith-v /var/lib/menu.hopsngrains.com:/usr/share/nginx/html:ro. - Each Section is a hand-written
index.htmllisting one<img>per JPG, with a vendored copy of Materialize CSS/JS in every Section folder. - The read-only mount is why content can only be changed over SSH.
static-menu/Caddyfileis dead config from the retiredcaddy-menuplaybook and is read by nothing. - The same playbook serves three Sites:
menu.hopsngrains.com(319M, this folder),menu.hngmohali.com(208M),menu.greatbear.in(405M). Remote disk: 15G free, 82% used. nginx-menu/is untracked in theansible-playbooksrepo (git.tanshu.com:tanshu/playbooks). Sibling projects build an image locally, push toregistry.tanshu.com, then runansible-playbook -e tag=.
Decisions
| Question | Decision |
|---|---|
| Upload path | Small self-hosted app on the same host, replacing scp |
| Serving | The app serves HTML and images; nginx is retired per Site (ADR 0001) |
| Rendering | Per request, server-rendered HTML (ADR 0003) |
| Stack | Node + Fastify + sharp, one container |
| Metadata | JSON manifests, state encoded in the directory layout (ADR 0002) |
| Scope | One app instance per Site (ADR 0004); other two Sites migrate later |
| Sections | Per-Site config in git; not editable in the admin (ADR 0005) |
| Lifecycle | Draft → Current → Archive; publishing auto-archives the previous set; archives unlisted but reachable |
| Auth | Single shared password per Site; app login; hash + session secret in an untracked .env on the server |
| Images | 1600px viewing WebP + JPEG fallback, 480px admin-only thumbnails, Originals kept and never served |
| Logging | JSON to stdout only; no Prometheus, no Promtail |
| Backups | Owner's existing backups; out of scope |
Domain
CONTEXT.md is the glossary. Sections for this Site: Food, Bar, Wine, Straight Drinks, Delivery, What's On. One Current Menu Set per Section; a Section with no Current set does not appear on the landing page.
Architecture
Topology
caddy (80/443, TLS) ──reverse_proxy──▶ menu-app.hopsngrains.com:3000
├── renders landing, Section, archive pages
└── serves viewing images
(nginx-menu.hopsngrains.com retired after cutover)
Storage
/var/lib/menu-app.hopsngrains.com/
├── site.env # ADMIN_PASSWORD_HASH, SESSION_SECRET (mode 600, untracked)
└── data/
├── originals/<section>/<set-id>/<page-id>.<hash>.<ext> # never served
├── drafts/<section>/<set-id>/ # manifest.json + variants
└── published/<section>/<slug>/ # manifest.json + variants
<slug>is the valid-until date when set, else the publication date (YYYY-MM-DD), suffixed-2on collision.- Directory encodes state:
drafts/is invisible to customers,published/is reachable. manifest.jsonholdsid,section,label,validUntil,createdAt,publishedAtand the ordered Page list; each Page carries its ownid, content hash, source extension, the Viewing image's dimensions and the uploaded filename.- Current is the published set for a Section with the newest
publishedAt; everything else published is an Archive. No separate current pointer exists to drift. - Writes are temp file +
fsync+ rename, and publishing is a directory rename, so a crash leaves either a Draft or a published set.publish/archiveserialize behind one in-process lock. Boot validation checks that every manifest matches its directory and that Page files exist.
Routes
| Route | Purpose |
|---|---|
GET / |
Landing page: Sections with a Current set, text rows |
GET /<section>/ |
Current Menu Set |
GET /<section>/<slug>/ |
Archived Menu Set (unlisted, still reachable) |
GET /<section>/#page-N |
Deep link to one Page |
GET /media/<page-id>.<hash>.webp|.jpg |
Viewing image, immutable cache; keyed by Page id so the URL survives publish |
GET /admin/* |
Admin, session required, noindex |
GET /admin/sets/<id>/preview |
Draft rendered exactly as customers would see it |
Unknown Sections and Sections without a Current set 404 rather than redirect, so a stale printed link fails loudly instead of showing the wrong menu. Media for a Draft is served only to a session holder, which is what keeps Drafts unreachable in practice.
Image pipeline
- Accept JPEG/PNG/WebP up to 30MB, up to 40 Pages per set; anything else is rejected with a message naming the file.
- The browser pre-shrinks to 3000px on the long edge before upload (fast over restaurant wifi); if the browser cannot decode the file, the file is uploaded untouched.
- Server: apply EXIF orientation, strip all other metadata, write the Original, generate a 1600px WebP (q80) + JPEG (q82) Viewing image and a 480px WebP Thumbnail.
- Variant filenames carry a short content hash and are keyed by Page id, so a replaced Page cannot be served from a stale cache and a published URL keeps working across a re-publish.
Admin
Log in; see each Section with its Current set and state; create a Menu Set (choose Section, add Pages, drag to reorder, set label and optional valid-until, thumbnail grid); preview; publish (archives the previous set); restore an Archive as Current; delete a Draft or Archive. No user management, no scheduling, no Section editing, no password-change flow (edit site.env and restart).
Protection: a scrypt hash (from node:crypto, so no native build dependency) in site.env, httpOnly + Secure + SameSite=Lax session cookie, login throttled per IP, noindex on all admin routes. Originals and Drafts have no public route at all.
Customer design
Text-led landing page; Sections as tap-list rows with copper hairlines; no hero photograph, no cards, no shadows.
┌────────────────────────────┐ ┌────────────────────────────┐
│ HOPS N GRAINS │ │ HOPS N GRAINS ⌂ │
│ Food 12 pages │ │ Bar Food Wine Drinks │
│ ────────────────────────── │ │ ▓▓▓▓░░░░░░░░░░░░░░░░░░░░░░ │
│ Bar 20 pages │ ├────────────────────────────┤
│ ────────────────────────── │ │ ┌──────────────────────┐ │
│ Wine │ │ │ menu page photo │ │
└────────────────────────────┘ │ └──────────────────────┘ │
│ 3 / 12 │
└────────────────────────────┘
- Colour:
#14181bsteel,#1f262brail,#f2efe9paper,#0088aalogo teal,#b2703bcopper. - Type: self-hosted variable Archivo — expanded 600 for the brand and Section names, normal width for body and UI, tabular numerals for the counter.
- The one memorable element: a copper "pour" line in the sticky Section rail that fills as you scroll, doubling as position in a 20-page menu.
- Tapping the page counter opens a text page index for jumping; a quiet "Older menus" line at the foot of a Section page lists Archives.
- Roughly 2KB of progressive-enhancement JS for the lightbox and counter. Visible focus,
alttext ("Bar menu, page 3 of 12"),prefers-reduced-motionrespected, self-hosted fonts so it works on restaurant wifi.
Repos, build and deploy
- New repo
menu-adminongit.tanshu.com: app source,Dockerfile,compose.yamlfor local dev against afixtures/folder,docs/(this plan,CONTEXT.md, the ADRs), andnode --testtests for the storage and image layers. - Build locally and push
registry.tanshu.com/menu-admin:<tag>, matching the siblingdeploy.sh/make build-production TAG=convention. - New
menu-adminplaybook inansible-playbookswith per-Site vars (vars/hopsngrains.ymlfirst, the other two stubbed): rolesnetwork,menu-app(pull image, create/var/lib/menu-app.<site>, start container),caddy(snippet upsert). - The existing
roles/caddyonly adds a snippet when missing, which cannot change a proxy target; it is fixed to update an existing managed block in place. - One-time human step on the server: a
scripts/provision-site-env.shprompts for the admin password, hashes it, and writes/var/lib/menu-app.<site>/site.env(mode 600, never in git). - A small CLI:
verifyreports integrity problems in the data directory,repairregenerates missing variants from the Originals.
Sequence
- Commit
nginx-menu/to git so the current state is reproducible and revertible; create themenu-adminrepo and moveCONTEXT.md,docs/, and the ADRs into it. - Storage layer: config, manifest read/write, atomic writes, boot validation, tests.
- Image pipeline: sharp variants, content-hashed filenames, tests.
- Public renderer: landing, Section and archive routes, design tokens and CSS.
- Admin: login, upload with browser pre-shrink, ordering, preview, publish/restore/delete.
- Container, compose dev fixtures, Ansible role, deploy to
menu-new.hopsngrains.com, verify from a phone on restaurant wifi. - Cutover: re-upload the current Food, Bar and Delivery menus, create What's On from the posters, switch
menu.hopsngrains.comto the app, stop the old nginx container. - After a week: remove the old container and
/var/lib/menu.hopsngrains.com, delete the dated folders, drop the deadCaddyfile, and reduce this folder to dev fixtures.
Deleting the old 319MB directory is the only irreversible step, so it is last.
Out of scope
Backups (owner already runs them), Prometheus metrics, Promtail/Loki integration, multi-user accounts, scheduled publishing, admin-editable Sections, migrating menu.hngmohali.com and menu.greatbear.in, and git history for the image content.