Skip to main content

01 · Architecture & hosts

The pieces

Piece What it is
Worker wedding-planner One Cloudflare Worker script (worker/src/index.js plus modules under core/, routes/, pages/, domain/, lib/). It serves the API, the plan-portal app, the server-rendered guest pages, the family portal and the MCP connector.
Frontend React 18 + TypeScript + Vite app (frontend/). npm run build makes dist/; npm run gen-assets embeds it into the Worker as src/assets.js, so the whole app ships as one deploy. Page chunks are lazy-loaded and each page has its own error boundary, so one broken page doesn’t take down the app.
D1 database wedding-planner (binding DB) SQLite. Schema in worker/migrations/0001…0015. Migrations only ever add things. D1 Time Travel keeps restore points for 30 days.
R2 bucket wedding-media (binding MEDIA) Hero photos uploaded from the Guest Website editor, served at /media/*.
Cron */15 * * * * Every 15 minutes: checks the email assistant’s mailbox, sends the morning brief (first run at or after its UK time), runs the daily in-app check-in, the one-off launch review, and sends held “while you were away” notification summaries.
Workers Logs Console lines are kept. Per-request logs are off because URLs carry secrets. Query strings are stripped. Emails are masked.

Every hostname (all built from SITE_DOMAIN, for example example.com)

Host Serves Who can open it
apex <domain> The live guest site, in whichever mode is live (go-live schedule and wedding date first, then the manual choice; see notebook 11) Everyone
www.<domain> 301 redirect to the apex, keeping path and query Everyone
plan.<domain> The plan portal (the React app + /api/*) The couple (Cloudflare Access, or the password)
v1. … v5.<domain> Private previews: v1 teaser, v2 countdown, v3 RSVP site, v4 wedding day, v5 thank you Only a browser with a valid plan session. Everyone else gets a static “preview ended” page with no app and no data.
family.<domain> (or FAMILY_HOST) The read-only family payment portal, GET / only Family on the list, through Cloudflare Access
MCP_PUBLIC_ORIGIN host (optional) Only /mcp/<token>; everything else 404 Any AI client holding a valid link

/media/* works on every host and in every live mode. The session cookie is set for .<domain>, which is why signing in to the plan also unlocks the v1–v5 previews.

How a request is handled

  1. The family host is matched first and isolated: only GET /; /api, /mcp, /media and the app bundle all 404 there.
  2. On the MCP host only /mcp answers.
  3. /mcp/<token> on other hosts goes to the MCP server, and writes no log line at all.
  4. /api/* goes to the route table (about 170 routes, see notebook 28). Every response is { success, data, error }.
  5. /media/* is read from R2 with long-lived caching.
  6. Guest hosts: the Worker picks the mode from the host (v1–v5 force a mode) or from the live guest_mode setting on the apex, then renders that page on the server, filling in names, date and venues from Setup.
  7. Anything else is the app shell. When it serves index.html, manifest.webmanifest and sw.js it fills in the %WP_BRAND_*% placeholders and the Open Graph / Twitter tags.

Source layout (worker/src)

Module Job
index.js Entry point, remaining routes, digest builder
core/ auth.js (passwords, cookies, Access JWTs), config.js, router.js, setup.js (recalculations), seed.js (default tasks and categories), codes.js (access codes), db.js
routes/ auth.js, chat.js, system routes
pages/ Server-rendered guest pages: countdown, wedding-day, thank-you, preview-ended
domain/guest-settings.js Mode per host, RSVP open/closed, window payload
lib/http.js, lib/text.js Responses, ids, time; escaping and text helpers
family.js, family-access.js, access.js Family portal, family list + Access sync, JWT checks
mcp.js MCP connector and the shared planner tool list
assistant.js, mailbox.js Email assistant; IMAP/SMTP over Worker TCP sockets
chat.js, push.js, notify.js, ai-usage.js In-app chat, Web Push, notifications, usage and cost
brand.js, site.js, log-safe.js Branding, host names, log redaction

The index.js split (issue #3) is happening in stages (PRs 1–4 merged so far), guarded by route-table, bundle-size and “verbatim move” checks (see notebook 29).