# Massage Studio Website CMS — Agent Guidelines ## Stack - **SvelteKit 2** (SSR, Svelte 5 runes mode) — all `.svelte` files use `$state`, `$derived`, `$props()` etc. - **PocketBase** — server pinned to **0.23.12** (`docker-compose.yml`), REST API via the `pocketbase` SDK (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`, and `caddy` (reverse proxy). ## Project Structure ``` packages/shared/src/ # Shared code (types, calendar utils, blocks, pb, basket, stripe) app-admin/ # SvelteKit admin app (serves admin.) ├── src/ │ ├── lib/ │ │ ├── admin/ # Admin UI components (BlockList, Modal, editors, confirm/unsaved helpers) │ │ ├── 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) │ ├── routes/ │ │ ├── +layout.svelte # Root layout (admin shell: grouped sidebar; bare on /login and /preview) │ │ ├── login/ # Admin login │ │ ├── pages/ # Page CRUD + block editor │ │ ├── calendar/ # Event CRUD (menu label: Events) │ │ ├── items/ # Service/product CRUD (menu label: Services & products) │ │ ├── slots/ # Bookable time slot CRUD │ │ ├── orders/ # Order list + booking-email status/resend │ │ ├── emails/ # Block-based booking email editor (live preview, test send) │ │ ├── globals/ # Header/footer/colors 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 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 *.) ├── 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/ # Re-exports from $shared/server (pb-admin, basket); stripe.server.ts is public-only │ ├── routes/ │ │ ├── +layout.svelte # Root layout (always renders Header/Footer) │ │ ├── +page.svelte # Home page (slug=home) │ │ ├── [slug]/ # Dynamic CMS pages │ │ ├── api/ # basket, checkout, webhooks 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 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()` / `onMount` for side effects - `{@render children()}` for slots - `onclick={handler}` (not `on: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` - **Renderers (shared)**: `packages/shared/src/blocks/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 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 in `email/defaults.ts`. - **Sending (server)**: `packages/shared/src/server/email/` — nodemailer SMTP transport (Brevo), `.ics` builder, `sendOrderEmails(pb, orderId, kinds?)` (never throws; records status on the order) and `sendTestEmail`. Called from the Stripe webhook and the admin `/orders` resend 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 definitions - `packages/shared/src/calendar.ts` — calendar utilities (used by admin calendar editor and public upcoming calendar block) - Each app's `svelte.config.js` declares `kit.alias.$shared → '../packages/shared/src'` - Each app's `src/lib/types.ts` and `src/lib/calendar.ts` re-export from `$shared` so existing `$lib/types` and `$lib/calendar` imports work ### PocketBase Integration - Client created in `hooks.server.ts` (`event.locals.pb`) — injected per-request with auth cookie - `$lib/pb.ts` exports `createPocketBase()`, `getFileUrl()`, `uploadMedia()` - Collections: `pages` (slug, title, blocks[], published), `globals` (key, data), `media` (file, alt), `email_templates` (key, subject, blocks[], recipients, enabled) - 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 in `pb_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 != ''`, so `users` must never allow public sign-up (its createRule is superuser-only). Commerce writes (orders, baskets, basket_lines) are superuser-only; the public app does them server-side via `getAdminPb()`. ### Styling - **Public site**: Custom theme via `@theme` in `app.css` — colors: `warm`, `charcoal`, `sage`, `sage-dark`, `terracotta`. Fonts: `DM Sans` (body), `Playfair Display` (headings). - **Admin area**: DaisyUI **5** (no `form-control` / `label-text` / `*-bordered` — those are v4). Colours come from Site design via `$shared/theme`, rendered as a `