Adds to the dashboard: an income-per-month bar chart (hover for the figures; the month table is its table view), opened-time utilisation (booked hours against hours opened in Slots), what sells and popular lengths, new vs. returning customers and regulars, what usable codes are still worth, and a "Needs attention" list (failed booking emails, group sessions nearly full and codes expiring in the next 30 days). Slot places and code credits come from the shop hooks, as everywhere else. Login: a Show/Hide button on the password field. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HA82gV9YDZk1XhjJ5LtyAt
23 KiB
Massage Studio Website CMS — Agent Guidelines
Stack
- SvelteKit 2 (SSR, Svelte 5 runes mode) — all
.sveltefiles use$state,$derived,$props()etc. - PocketBase — server pinned to 0.23.12 (
docker-compose.yml), REST API via thepocketbaseSDK (v0.26). Auth, DB, and image storage. Bump the server version deliberately (changelog, backup, test migrations). - Tailwind CSS v4 + DaisyUI 5 — utility-first CSS with DaisyUI components for admin; custom theme for the public site.
- Docker Compose — four services:
app-admin,app-public,pocketbase, andcaddy(reverse proxy).
Project Structure
packages/shared/src/ # Shared code (types, calendar utils, blocks, pb, basket, stripe)
app-admin/ # SvelteKit admin app (serves admin.<domain>)
├── src/
│ ├── lib/
│ │ ├── admin/ # Admin UI components (BlockList, Modal, editors, confirm/unsaved helpers, slots/ bulk modals)
│ │ ├── blocks/ # Re-exports from $shared/blocks (block renderers live in shared)
│ │ ├── pb.ts # Re-exports from $shared/pb + app-specific uploadMedia
│ │ ├── types.ts # Re-exports from $shared
│ │ ├── calendar.ts # Re-exports from $shared
│ │ ├── scrollReveal.ts # Re-exports from $shared
│ │ ├── stripe-client.ts # Re-exports from $shared
│ │ ├── basket.svelte.ts # Re-exports from $shared
│ │ └── server/ # Re-exports from $shared/server + admin helpers (actions.ts, pages.ts, slots.ts)
│ ├── routes/
│ │ ├── +layout.svelte # Root layout (admin shell: grouped sidebar; bare on /login and /preview)
│ │ ├── +page.svelte # Dashboard (income + chart, hours, utilisation, customers, codes owed, what sells, needs attention); figures from $lib/server/dashboard.ts. Login lands here
│ │ ├── login/ # Admin login
│ │ ├── pages/ # Page CRUD + block editor
│ │ ├── calendar/ # Event CRUD (menu label: Events)
│ │ ├── items/ # Service/product CRUD (menu label: Services & products)
│ │ ├── passes/ # Vouchers & codes: search, void/extend, issue (menu label: Vouchers & codes)
│ │ ├── slots/ # Time windows + group sessions: month calendar (?month=YYYY-MM), CRUD, bulk generate/copy/clear
│ │ ├── orders/ # Order list + booking-email status/resend
│ │ ├── customers/ # Customer personal data (GDPR): search, export, correct, erase, retention settings
│ │ ├── emails/ # Block-based booking email editor (live preview, test send)
│ │ ├── globals/ # Header/footer/colors/style editor (menu label: Site design)
│ │ ├── backup/ # Export/import UI (calls api/export, api/import)
│ │ ├── preview/ # Draft preview via sessionStorage (same-origin)
│ │ └── api/ # upload, export, import, slots (Shop block times in /preview) endpoints
│ ├── hooks.server.ts # Auth guard — all routes except /login
│ └── app.css # Tailwind + DaisyUI + custom theme
├── static/ # Static assets
├── build/ # Production build output
├── svelte.config.js # Adapter-node, runes mode forced, $shared alias
├── vite.config.ts # Tailwind v4 + SvelteKit plugins
└── package.json
app-public/ # SvelteKit public app (serves *.<domain>)
├── src/
│ ├── lib/
│ │ ├── blocks/ # Re-exports from $shared/blocks (block renderers live in shared)
│ │ ├── components/ # Header.svelte, Footer.svelte
│ │ ├── pb.ts # Re-exports from $shared/pb
│ │ ├── types.ts # Re-exports from $shared
│ │ ├── calendar.ts # Re-exports from $shared
│ │ ├── scrollReveal.ts # Re-exports from $shared
│ │ ├── stripe-client.ts # Re-exports from $shared
│ │ ├── basket.svelte.ts # Re-exports from $shared
│ │ └── server/ # shop.ts (client for PocketBase's /api/shop routes, basket cookie) + $shared/server re-exports
│ ├── routes/
│ │ ├── +layout.svelte # Root layout (always renders Header/Footer)
│ │ ├── +page.svelte # Home page (slug=home)
│ │ ├── [slug]/ # Dynamic CMS pages
│ │ ├── api/ # basket, checkout, webhooks, slots (Shop block times) endpoints
│ │ └── checkout/return/ # Stripe return URL
│ ├── hooks.server.ts # Creates PB client in locals (no auth guard)
│ └── app.css # Tailwind + DaisyUI + custom theme
├── static/ # Static assets
├── build/ # Production build output
├── svelte.config.js # Adapter-node, runes mode forced, $shared alias
├── vite.config.ts # Tailwind v4 + SvelteKit plugins
└── package.json
pocketbase/pb_migrations/ # JS migrations, mounted at /pb_migrations; applied on PocketBase start
pocketbase/pb_hooks/ # JS hooks, mounted at /pb_hooks: the shop API (/api/shop/*) + hold-sweeping cron
docker-compose.yml # app-admin + app-public + pocketbase + caddy services
Caddyfile # Subdomain-based routing
Subdomain Routing
Caddy routes by Host header — no path stripping:
admin.{$DOMAIN}:8080→app-admin:3001(admin app)db.{$DOMAIN}:8080→pocketbase:80(redirects/to/_/)www.{$DOMAIN}:8080,*.{$DOMAIN}:8080→app-public:3000(public app)
For local dev, DOMAIN defaults to localhost, so Caddy serves admin.localhost:8080, db.localhost:8080, www.localhost:8080. Caddy's .localhost handling works without DNS or hosts-file changes.
Key Conventions
Svelte 5 Runes Mode
All components use Svelte 5 runes syntax — never export let, $:, or on:click. Use:
$props()for component props$state()for reactive local state$derived()for computed values$effect()/onMountfor side effects{@render children()}for slotsonclick={handler}(noton:click)
Block System
Pages are composed of ContentBlock[]. Each block has { id, type, data }. Block types are defined in packages/shared/src/types.ts (re-exported via $lib/types in each app):
text | image_text | timeline | hero | button | spacer | testimonials | upcoming_calendar | shop | checkout | cards | faq | html
- Renderers (shared):
packages/shared/src/blocks/<Type>Block.svelte— one renderer per type, imported by both apps via$shared/blocks/.... The admin preview iframe uses the same shared renderers. - Admin editors:
app-admin/src/lib/admin/editors/BlockEditor.svelte— switches editor UI by type - Defaults:
app-admin/src/lib/admin/blockDefaults.ts—createBlock(type)generates a new block with sensible defaults - Block list:
app-admin/src/lib/admin/BlockList.svelte— draggable reorder, select, delete - Settings on every block (keys starting with
_, edited below each block's own fields):_background,_foreground(colours) and_anchor(id for#anchorlinks), applied byBackgroundWrapper.svelte. - Text is edited visually:
RichTextEditor.svelte(Tiptap) only producesp, h2, h3, strong, em, s, a, ul, ol, li, blockquote, br, hr— no inline styles or layout HTML. That list isEDITOR_TAGSinpackages/shared/src/richText.ts; keep it and the editor's extensions in step. A layout people keep needing becomes a block (as Cards and FAQ did), never HTML in a text block; one-offs and embeds go in anhtmlblock. Old text blocks holding other HTML are turned intohtmlblocks (or centred text) byupgradeLegacyBlocks()on backup import and by migration1793300000_text_blocks_visual_editor.js.
To add a new block type: add to BlockType union in packages/shared/src/types.ts, create renderer in packages/shared/src/blocks/, add editor case in app-admin/src/lib/admin/editors/BlockEditor.svelte, add default in app-admin/src/lib/admin/blockDefaults.ts, add import in packages/shared/src/blocks/BlockRenderer.svelte.
Booking Emails
Email templates use a separate EmailBlock[] / EmailBlockType (text | image | button | spacer | divider | booking_details | customer_details | contact_info) because email clients need table layouts with inline styles — page block renderers can't be reused.
- Rendering (pure, shared):
packages/shared/src/email/render.ts—renderEmail(template, ctx)returns{ subject, html, text }. Used by the admin live preview (client-side) and by sending, so they always match. Defaults for each template key live inemail/defaults.ts. - Sending (server):
packages/shared/src/server/email/— nodemailer SMTP transport (Brevo),.icsbuilder,sendOrderEmails(pb, orderId, kinds?)(never throws; records status on the order) andsendTestEmail. Called from the Stripe webhook and the admin/ordersresend action. - Admin:
/emails/[key]editor,app-admin/src/lib/admin/editors/EmailBlockEditor.svelte,app-admin/src/lib/admin/emailBlockDefaults.ts.
To add an email block type: add to EmailBlockType in packages/shared/src/types.ts, add HTML + text cases in render.ts, an editor case in EmailBlockEditor.svelte, and a label/default in emailBlockDefaults.ts.
Shared Code
packages/shared/src/types.ts— all type definitionspackages/shared/src/calendar.ts— calendar utilities (used by admin calendar editor and public upcoming calendar block)packages/shared/src/items.ts— service durations (parseDurations,formatDuration,lowestPrice); which length costs what is charged by the shop hookspackages/shared/src/slots.ts— pure slot planning (generate/copy-week maths on date keys + wall-clock times inSITE_TIMEZONE, DST-safe); the/slotsactions use it via$lib/slots, PocketBase I/O is inapp-admin/src/lib/server/slots.ts- Each app's
svelte.config.jsdeclareskit.alias.$shared → '../packages/shared/src' - Each app's
src/lib/types.tsandsrc/lib/calendar.tsre-export from$sharedso existing$lib/typesand$lib/calendarimports work
PocketBase Integration
- Client created in
hooks.server.ts(event.locals.pb) — injected per-request with auth cookie $lib/pb.tsexportscreatePocketBase(),getFileUrl(),uploadMedia()- Collections:
pages(slug, title, blocks[], published),globals(key, data),media(file, alt),email_templates(key, subject, blocks[], recipients, enabled); commerce:items,slots,baskets,basket_lines,orders,order_lines,passes(bundle/voucher codes) - Server load functions use
locals.pb.collection('pages').getFirstListItem() - Always build filters with
pb.filter('slug = {:slug}', { slug })— never interpolate values into filter strings (quotes break them). - Schema changes: add a migration to
pocketbase/pb_migrations/(runs once, on the next PocketBase start) and mirror it inpb_schema.json(fresh installs import that after the migrations have already run). Migrations must skip missing collections and must not throw for data problems — a failing migration stops PocketBase from starting. - API rules: CMS collections require
@request.auth.id != '', sousersmust never allow public sign-up (its createRule is superuser-only). Commerce writes (orders, order_lines, baskets, basket_lines) are superuser-only; they happen in the PocketBase shop hooks (pocketbase/pb_hooks/shop/lib.js), which bypass rules. - Slot availability (window start times, group-session places, blocking by overlapping bookings incl. get-ready time) is computed only by
availability()/windowStartTimes()/checkBooking()in the shop hooks — the public listing, basket holds and the admin/slotspage all go through it (GET /api/shop/slots?item=&minutes=&from=&to=,?detail=1for the admin). Slots arewindows (services bookable at any of their lengths) or groupsessions; bookings carry their ownstart/minuteson basket/order lines. Never store booking state on a slot or re-implement the rule elsewhere; see the README's Slot availability. - Customer personal data (GDPR) lives in
orders.customerDetails/email,passes.email/recipientName/messageand (during checkout)baskets/basket_lines.giftTo/giftMessage. Admin access, correction, erasure (= anonymise the order, never delete it — the accounts need it) and the retention cron are inpocketbase/pb_hooks/privacy/; the admin/customerspage only calls/api/privacy/*. A new place that stores customer details (e.g. a Google Calendar sync) must be covered by export, erase and retention too, and listed in the privacy draft (app-admin/src/lib/admin/privacyTemplate.ts). Don't load third-party resources on public pages (fonts are bundled; Stripe.js loads only at Pay) — each one sends visitors' IPs elsewhere and may need consent. See the README's Personal data (GDPR). - Bundles and codes (
passes): what a code has left is counted from order lines and live holds bypassCredits()in the shop hooks — never store a counter. A line a code covers haspassand costs 0; a basket with nothing to pay is confirmed without Stripe. Bundle parts are JSON, not relations: theonRecordDeletehook onitems(deleteBlocker) keeps parts that bundles or codes still need from being deleted, and a bundle with an inactive part isn't sold. PocketBase reads empty numbers back as 0 and treats 0 as blank for required fields: use a flag (likeitems.trackStock) instead of an empty number, and keep fields that can be 0 not required. See the README's Bundles and codes. - Shop / payments: all basket, slot-hold, Stripe and order logic lives in the PocketBase hooks (JSVM: synchronous, each handler
require()s the lib; see the header comment). The public app must stay unprivileged — no superuser login, no Stripe secret key; its routes only proxy to/api/shop/*and manage thebasket_idcookie (app-public/src/lib/server/shop.ts). Booking emails are rendered and sent by the public app from data the webhook hook returns (OrderEmailData,sendOrderEmailsFromData); keeporderEmailData()in the hook andloadOrderEmailData()inpackages/shared/src/server/emailreturning the same shape. Local testing usesstripe-mock(STRIPE_API_BASE, local compose only).
Styling
- Public site: Custom theme via
@themeinapp.css— colors:warm,charcoal,sage,sage-dark,terracotta. Fonts:font-sans(body),font-serif(headings), chosen in Site design → Style (default DM Sans / Playfair Display).- Site design → Style (
styleglobal: fonts, corners, text size, shadows, page width) becomes--site-*variables (siteStyleVarsin$shared/theme) that the@themetokens in bothapp.cssfiles scale. So in public-site markup use the tokens —rounded-xl/rounded-2xl/rounded-card/rounded-panel,shadow-sm…shadow-xl,max-w-3xl/6xl/7xl— neverrounded-[2rem]or an arbitraryshadow-[…], which ignore the settings. Buttons, chips and icon buttons arerounded-button(a pill when Round, square when Sharp); only dots, avatars and badges stayrounded-full. - Keep scrolling smooth: no
backdrop-bluron public pages (it is redrawn on every scrolled frame; use a nearly solid background), and keep animations short. The.reveal/.animate-fade-inanimations are switched off for people who ask for reduced motion and, byscrollReveal.ts, on devices that stutter (plain-motionon<html>, rules in bothapp.cssfiles). - Fonts are bundled
@fontsource-variable/*packages, imported in each app'ssrc/lib/fonts.tsand listed inSITE_FONTS; a new one goes in all three places.
- Site design → Style (
- Admin area: DaisyUI 5 (no
form-control/label-text/*-bordered— those are v4). Colours come from Site design via$shared/theme, rendered as a<style>in<head>(SSR, no flash): the admin gets only DaisyUI primary (= site Primary) and secondary (= site Accent) with auto-contrast text;/previewand the public site get all site colour variables. Never usetext-primary/text-secondaryfor text — a light brand colour is unreadable as text; mark state with a tint/bar instead. Conventions:- Section card:
rounded-box bg-base-100 p-5 shadowwith anh2.text-2xl.font-boldtitle (see Site design / globals). - Form field:
<label class="fieldset"><span class="fieldset-legend">Label</span><input class="input w-full" /></label>; hints in<span class="label">. - Setting rows in editors:
SegmentedControl(choices) andColorField(colours) — label column on the left, like the block Background picker; in a narrow row (a phone) the label goes above (a@containerquery). More than about four choices don't fit a phone: use a slider (like the background Overlay). - Save results in editors:
$lib/admin/SaveStatus.svelte(success fades out after a moment, an error stays). - Images: always
$lib/admin/editors/ImagePicker.svelte(choose, drag in or paste an image, or pick an uploaded one from the library:MediaLibrary.svelte,/api/media; address and alt text). It uploads tomediathrough/api/upload;withUrl={false}+altHint=""+ theidfromonChangewhere a field stores a media relation (Services & products). Store onlyurl/altfromonChangeelsewhere. - Create/edit forms open in
$lib/admin/Modal.svelte; destructive submits useconfirmSubmit()from$lib/admin/confirm(returningfalsefrom a handler does not cancel). - Server actions wrap PocketBase writes in
attempt()from$lib/server/actionsso failures show as an error banner, not a 500. - Editors with unsaved state use
use:enhance+warnOnUnsavedChanges().
- Section card:
- Dates, times and prices shown to people use
DISPLAY_LOCALE(en-GB: day-month-year, 24-hour clock) and the helpers in$shared/calendar(formatInstant,formatPricewith the shopcurrency,formatDateTime) — nevertoLocale*(undefined), which renders US formats on the server. Booking times on the public site are shown inSITE_TIMEZONEtoo (layout datatimezone, read by blocks viapage.data.timezone). Native<input type="date">fields follow the visitor's browser language and can't be changed from the page. - Dates/times in admin: entered and displayed in
SITE_TIMEZONE(layout datatimezone), viatoZonedDatetimeInput,zonedInputToIso,formatDateTimein$shared/calendar. Nevernew Date(localInput)on the server — the container runs in UTC. - Prose:
.prose-wellnessclass for rich text content styling (in both apps'app.css, which must stay alike: the admin preview uses it). A Quote in the editor is the pull quote (blockquote).
Routing
- Admin app (
app-admin): All routes except/loginare auth-guarded inhooks.server.ts(which also refreshes the token per request and sets the cookie'sSecureflag from the real scheme). The root layout renders the admin shell (grouped sidebar) except on/loginand/preview. The/previewroute readssessionStorageset by the page editor (same-origin, so it works). - Public app (
app-public): No auth guard. The root layout always renders Header/Footer.+layout.server.tsfetches header/footer/colors globals + basket/items/slots for every page. - Booking and basket links: booking = the header CTA's address, basket = the optional basket page slug typed in Site design (
header.basketPage; '' = the CTA's address), both fromshopLinks(header)inpackages/shared/src/types.ts(blocks readpage.data.header) — never hard-code/book. - Class names in components are written out whole (
'btn-primary', not`btn-${variant}`): Tailwind only generates classes it finds in the source, so a built-up name silently gets no style. +page.server.tsfor home fetchesslug = "home" && published = true[slug]/+page.server.tsfetches by dynamic slug
Build & Dev Commands
# Full stack (single entry point on port 8080) — the only supported way to run/develop
# Source changes require rebuilding; the container runs `node build`, not a dev server.
DOMAIN=localhost docker compose up --build
# Admin app: http://admin.localhost:8080
# Public app: http://www.localhost:8080
# PocketBase: http://db.localhost:8080/_/
# Type checking (needs node_modules in packages/shared too, or every shared
# file that imports a package fails with "Cannot find module")
cd packages/shared && npm install # no lockfile here, so not `npm ci`
cd app-admin && npm run check
cd app-public && npm run check
# Production build only (run by each app's Dockerfile)
cd app-admin && npm run build
cd app-public && npm run build
Environment
DOMAIN— base domain for subdomain routing. Defaults tolocalhostfor local dev. Set indocker-compose.ymlor.env.URL_SCHEME(defaulthttp),URL_PORT(default:8080; set it empty for no port) — build every browser-facing URL below as<scheme>://<sub>.<DOMAIN><port>. They must match the address bar exactly: a mismatchedORIGINmakes SvelteKit reject form POSTs (admin login) with "Cross-site POST form submissions are forbidden". Behind a TLS reverse proxy:URL_SCHEME=https,URL_PORT=. (podman-compose 1.5 can't do nested${A:-${B}}defaults, hence two flat variables.)PUBLIC_POCKETBASE_URL— public-facing PocketBase URL (<scheme>://db.${DOMAIN}<port>). Set indocker-compose.yml.POCKETBASE_INTERNAL_URL— internal Docker network URL (http://pocketbase:80). Set indocker-compose.yml.ORIGIN— SvelteKit origin for SSR. Differs per app:<scheme>://admin.${DOMAIN}<port>(admin),<scheme>://www.${DOMAIN}<port>(public).PUBLIC_SITE_URL— public site URL used by the admin app for cross-subdomain preview links (<scheme>://www.${DOMAIN}<port>).SMTP_HOST,SMTP_PORT,SMTP_USER,SMTP_PASS,EMAIL_FROM,EMAIL_FROM_NAME— Brevo SMTP relay for booking emails (both apps). EmptySMTP_HOST= log emails instead of sending.SITE_TIMEZONE— IANA timezone for booking times in emails (defaultEurope/Oslo).STRIPE_CURRENCY— shop currency (ISO 4217, defaulteur; e.g.nok). One setting for what Stripe charges and how prices are shown: PocketBase, both apps' layout data (currency, read by blocks viapage.data.currency) and booking emails. Format prices withformatPrice(amount, currency)from$shared/calendar— never hard-code a currency.- Secrets (Stripe,
INTERNAL_API_SECRET, SMTP) are read from a root-level.envnext todocker-compose.yml; see.env.example. STRIPE_SECRET_KEY,STRIPE_WEBHOOK_SECRET→ PocketBase only.INTERNAL_API_SECRET→ PocketBase and app-public (booking-email status). No app gets PocketBase superuser credentials.- Shop listings are public data, loaded anonymously by
loadShopData()inpackages/shared/src/server/shop.ts(public layout and admin/preview). The Shop block fetches bookable times itself, per service and length, fromGET /api/slotsin each app (a proxy toGET /api/shop/slots); if it has nothing to show it says "Nothing is available".