# BlackDice Website — Architecture This document explains how the system is put together: the runtime pieces, how content flows from the CMS to a visitor's browser, and why the design avoids the failure mode that broke the old `blackdice-studio.html` tool. For editors, see [CMS-GUIDE.md](CMS-GUIDE.md). For hosting, see [DEPLOYMENT.md](DEPLOYMENT.md). For a directory-by-directory reference, see [PROJECT-STRUCTURE.md](PROJECT-STRUCTURE.md). --- ## 1. System overview ``` ┌─────────────────────────────┐ │ Visitor's browser │ │ ┌─────────────────────────┐ │ │ │ React app (Vite build) │ │ │ │ src/main.tsx router │ │ │ └───────────┬─────────────┘ │ └──────────────┼─────────────────┘ │ HTTPS ┌──────────────────┴───────────────────┐ │ server/index.mjs │ │ (Node, zero dependencies) │ │ │ │ • serves dist/ (the built SPA) │ │ • serves /content/site-content.json │ │ • serves /content/uploads/* │ │ • /api/* (auth, publish, leads, …) │ │ • /sitemap.xml, /robots.txt (generated) │ └──────────────────┬───────────────────┘ │ reads / writes ┌──────────────────┴───────────────────┐ │ content/ │ │ site-content.json ← published copy │ │ versions/*.json ← one per publish │ │ uploads/* ← images & clips │ │ leads.jsonl ← form submissions │ └────────────────────────────────────────┘ ``` Two things run in production: 1. **A static build** (`dist/`) — the React app, compiled once. 2. **A small Node server** (`server/index.mjs`) — serves that build, serves the published content document, and exposes the API that `/admin` calls to publish. There is no database. The published state is one JSON file plus a folder of uploaded media, both on disk. --- ## 2. The core design decision: content is data, not markup The previous tool (`blackdice-studio.html`) worked by **exporting HTML** — every save cloned the live DOM into a new `index.html` and rebuilt `blog.html` from a template string. The export *was* the site. Anything a developer had hand-edited into those files — contact-form wiring, SEO tags, routing — was silently discarded on the next export, because there was only one copy of the truth and the CMS owned it entirely. This project splits that single copy into two layers that never overwrite each other: | Layer | What it holds | Who owns it | Where it lives | |---|---|---|---| | **Markup & code** | Page structure, CSS, the router, the enquiry-form logic, the demo players | Developers, via git | `src/`, built into `dist/` | | **Content** | Copy, images, articles, demo clips, SEO text, settings | Editors, via `/admin` | `content/site-content.json` | `/admin` never writes to `src/` or regenerates any HTML file. Publishing writes **one JSON document**. A developer can change the page structure at any time without touching content, and an editor can change all the content at any time without touching structure. Requirement 1 (publishing wiping developer work) is therefore impossible by construction, not by discipline. ### How the two layers merge `src/cms/store.tsx` resolves content in three ordered layers, each overriding the one before: 1. **The build** — `src/site/siteMarkup.txt` (page HTML with CMS hooks baked in) and `src/cms/pages.ts` (routes, default SEO, demo slot definitions). 2. **Factory content** — `src/cms/generated/seedContent.json`, the one-time import of the old studio's article library. This is what a fresh install shows before anyone publishes anything. 3. **Published content** — `content/site-content.json`, fetched at page load and merged over the first two. If the API is unreachable (offline, static hosting with no server), the site still renders layers 1–2 rather than failing — see §7. --- ## 3. The CMS hook system Every editable region in the page markup carries a stable attribute, injected once by a script rather than hand-added: | Attribute | Marks | Example | |---|---|---| | `data-cms="cNNNN"` | An editable rich-text region (its `innerHTML`) | `

` | | `data-cms-img="imgNNN"` | A replaceable image (its `src`) | `` | | `data-cms-num="nNNN"` | An animated statistic (`data-count` / `data-suffix`) | `
` | **`scripts/inject-cms-ids.mjs`** parses `siteMarkup.txt`, walks the DOM tree, and: - Assigns an id to every heading, paragraph, list item, button label, image and animated stat that isn't already inside another editable region (so a `