# Business Rules - Unit 1: Start migration and script step Rule ids are scoped to this feature (the code comments of earlier features also use `BR-MAIL-01` for the mail subject; here it is the e-mail address protection). "Source" points at a requirement (FR/NFR) or design decision (D1 to D13 in [application-design.md](../../../inception/application-design/application-design.md)). Flows: [business-logic-model.md](business-logic-model.md). Components: [frontend-components.md](frontend-components.md). Data: [domain-entities.md](domain-entities.md). Groups: BR-BLD build, BR-ENT entry and document, BR-HYD hydration, BR-MAIL e-mail address, BR-404 not found, BR-LZY lazy code, BR-MON Sentry and Umami, BR-SCR script step, BR-SEC output hygiene, BR-SRV preview server, BR-TST tests, BR-MEA measurement. ## 1. Decision flowcharts ### 1.1 Is an inline script moved ```mermaid graph TD s["Script element found by the scanner"] --> src{"Has a src attribute?"} src -->|"yes"| keepExt["Leave as is: external script"] src -->|"no"| body{"Body empty after trim?"} body -->|"yes"| keepEmpty["Leave as is: no effect"] body -->|"no"| typ{"type absent, empty, a JavaScript type or module?"} typ -->|"no"| keepData["Leave as is: data block such as ld+json"] typ -->|"yes"| bad{"async or defer on a classic script, body contains comment opener, or relative import in a module?"} bad -->|"yes"| fail["Error UNSUPPORTED_SCRIPT"] bad -->|"no"| move["Replace by external reference, write file"] classDef decision fill:#fbd38d,stroke:#92400e,stroke-width:1px,color:#000; classDef keep fill:#9ae6b4,stroke:#2f855a,stroke-width:1px,color:#000; classDef act fill:#63b3ed,stroke:#2b6cb0,stroke-width:1px,color:#000; classDef error fill:#f6e05e,stroke:#c05621,stroke-width:1px,color:#000; class src,body,typ,bad decision; class keepExt,keepEmpty,keepData keep; class s,move act; class fail error; ``` Text alternative: only scripts without src, with a non-empty body and a JavaScript or module type are moved; data blocks, external and empty scripts stay, and three unsupported forms fail the build. ### 1.2 What a component renders before and after hydration ```mermaid graph TD v["Browser-dependent value"] --> kind{"Kind of value"} kind -->|"search, pathname, year, media, visibility, load state"| def["First render uses the server-safe default, same on both sides"] kind -->|"e-mail address"| mail["First render uses an empty placeholder with reserved size"] kind -->|"observer or measurement"| eff["Set in an effect or external store after mount"] def --> after["After hydration the real value replaces the default"] mail --> after eff --> after classDef decision fill:#fbd38d,stroke:#92400e,stroke-width:1px,color:#000; classDef act fill:#63b3ed,stroke:#2b6cb0,stroke-width:1px,color:#000; classDef ok fill:#9ae6b4,stroke:#2f855a,stroke-width:1px,color:#000; class kind decision; class v,def,mail,eff act; class after ok; ``` Text alternative: every browser-dependent value starts from a default that equals the prerendered HTML (an empty placeholder for the e-mail address) and is replaced by the real value after hydration. ## 2. Rules ### BR-BLD: Build and output | Id | Rule | Source | |---|---|---| | BR-BLD-01 | `pnpm build` runs `tsc`, `vite build`, then `node config/externalizeInlineScripts.ts`, in that order. A failing step fails the build. The deployable output is `dist/client`; `dist/server` exists only during the build. | FR-PR-17, 19, 20; services.md | | BR-BLD-02 | The prerendered pages are every key of `sitePages` plus the catch-all route rendered from path `/404` to file `404.html`. `vite.config.ts` derives the list from `sitePages.ts`; paths are never typed a second time. | FR-PR-01, 03; D1, D5 | | BR-BLD-03 | `autoSubfolderIndex` is `false`. File mapping is `pageFile(path)`: `/` gives `index.html`, any other path gives its path without leading slash plus `.html` (`/over-mij` gives `over-mij.html`, `/soorten-fotoshoots/newborn` gives `soorten-fotoshoots/newborn.html`). `pageFile` lives in `config/pageFiles.ts` (pure) and is used by `vite.config.ts`, the runner and the preview server. | FR-PR-16; D1 | | BR-BLD-04 | Link crawling must not add pages beyond BR-BLD-02. The runner fails on any other `.html` file (UNEXPECTED_HTML). | FR-PR-03 | | BR-BLD-05 | Each page file has exactly one `