# [DEF:ADR-0006:ADR] # @STATUS ACTIVE # @PURPOSE Define the frontend architecture for ss-tools: Svelte 5 runes reactivity model, SvelteKit routing, component composition rules, state management patterns (incl. Screen Models), design token system, UI atom reuse, API client conventions, and UX contract expectations for C4/C5 components. # @RELATION DEPENDS_ON -> [ADR-0001:ADR] # @RELATION DEPENDS_ON -> [ADR-0002:ADR] # @RELATION DEPENDS_ON -> [ADR-0010:ADR] # @RATIONALE Svelte 5 introduces a fundamentally different reactivity model (runes: `$state`, `$derived`, `$effect`, `$props`) compared to Svelte 4's `$:` reactive statements. This ADR locks in the Svelte 5 runes approach and prevents backsliding into legacy patterns when new developers or AI agents contribute code. # @RATIONALE SvelteKit with static adapter (`@sveltejs/adapter-static`) was chosen over SvelteKit SSR because: (a) ss-tools is a Docker‑deployed SPA behind nginx — server‑side rendering provides no latency benefit, (b) static SPA simplifies Docker deployment (no Node.js server needed, just nginx serving static files), (c) all data is fetched via REST API, not server‑side load functions. # @RATIONALE Svelte 5 runes (`$state`, `$derived`, `$effect`) are mandated over Svelte 4 `$:` reactivity and `writable` stores because: (a) runes are the forward path — Svelte 4 patterns are deprecated, (b) runes provide fine‑grained reactivity without subscription boilerplate, (c) `$state` can be used outside `.svelte` files in `.svelte.js` modules, enabling reusable reactive logic. # @RATIONALE Design tokens (semantic colors in `tailwind.config.js`) were introduced in 2026‑06‑02 (PR 0‑1) to eliminate raw Tailwind classes (`bg‑blue‑600`, `text‑gray‑900`) from page‑level code. This prevents visual drift and gives AI agents a single source of truth for color choices. See §"Design Token System" below. # @RATIONALE Screen Model pattern (`[TYPE Model]` in `.svelte.ts` files) was formalised in 2026‑06‑02 (PR 3‑4) to extract cross‑widget state from page files. Models reduce page files from 2700+ lines to <1400 lines and enable unit‑testing of invariants without DOM render (~10ms). See §"State Management Pattern" and ADR‑0010. # @REJECTED React/Next.js — rejected by ADR-0003 (technology stack independence from Superset). Svelte 5 was chosen for its compile‑time approach, smaller bundle size, and superior DX for this project's scale. # @REJECTED Svelte 4 legacy patterns (`$:`, `writable`/`readable` stores) — rejected because Svelte 5 runes are the actively maintained reactivity model. Mixing two models creates confusion and potential reactivity bugs. # @REJECTED Server‑Side Rendering (SSR) with SvelteKit — rejected because the data is entirely API‑driven (no server‑side page data loading), and SSR adds deployment complexity (Node.js process) without latency benefit for authenticated SPA users. # @REJECTED Raw Tailwind color classes (`bg‑blue‑600`, `text‑gray‑900`, `border‑indigo‑300`, etc.) in page and component code — rejected because they create visual drift across 70+ files (3892 violations catalogued 2026‑06‑02). Replaced by semantic token system (see §"Design Token System"). # @REJECTED Inline `$state` + handler functions in complex pages (>5 `$state` atoms) — rejected because they produce monolithic, untestable page files (DashboardHub was 2765 lines before extraction). Replaced by Screen Model pattern (see §"State Management Pattern"). ## Decision ### Technology Stack | Layer | Choice | Version | |-------|--------|---------| | Framework | SvelteKit | 2.x | | UI Library | Svelte | 5.x (runes mode) | | Build | Vite | 7.x | | Styling | Tailwind CSS 3.x + semantic design tokens | 3.x | | Adapter | @sveltejs/adapter-static | 3.x (SPA mode) | | Testing | vitest + @testing-library/svelte | 4.x / 5.x | ### Reactivity Model (Svelte 5 Runes) ``` Legacy (FORBIDDEN) Svelte 5 Runes (REQUIRED) ──────────────────────── ────────────────────────── let count = 0; let count = $state(0); $: doubled = count * 2; let doubled = $derived(count * 2); $: { /* side effect */ } $effect(() => { /* side effect */ }); export let name; let { name } = $props(); import { writable } from ... ❌ new stores MUST use .svelte.ts with $state ⚠️ 8 existing writable stores are legacy — migrate, don't extend ``` **Note on legacy stores:** 8 stores (`sidebar.ts`, `taskDrawer.ts`, `environmentContext.ts`, `datasetReviewSession.ts`, `assistantChat.ts`, `health.ts`, `activity.ts`, `translationRun.ts`) still use `writable()` from `svelte/store`. These predate Svelte 5 adoption. New reactive state MUST use `.svelte.ts` files with `$state`. Existing stores are read via `$store` syntax in `.svelte` files or `get()` in `.svelte.ts` modules. ADR‑0007 documents the `fromStore` + `$derived` rejection. ### State Management Pattern **Four tiers of state**, strictly separated: | Tier | Pattern | File | Use case | Example | |------|---------|------|----------|---------| | 1. Component‑local | `$state()` in `.svelte` | `.svelte` | Accordion open, tooltip visible, input focus | `let isOpen = $state(false)` | | 2. Screen Model | `class` with `$state` + methods | `.svelte.ts` in `lib/models/` | **Cross‑widget state with invariants** (filters, pagination, search, multi‑step) | `DashboardHubModel`, `MigrationModel` | | 3. Global store | `$state` in `.svelte.ts` module | `.svelte.ts` in `lib/stores/` | Cross‑route state (auth, notifications, sidebar) | `maintenance.svelte.ts` | | 4. Server state | Fetched via API, held in Model or component | N/A | HTTP responses from backend | `api.getDashboards()` → model atom | **Screen Model (tier 2) — the model‑first pattern:** For any page with **>5 `$state` atoms** or **cross‑widget invariants** (filter resets pagination, selection survives search), create a `[TYPE Model]` in `lib/models/` BEFORE implementing components. The Model declares `@STATE`, `@ACTION`, `@INVARIANT` tags and is testable without DOM render. ```typescript // frontend/src/lib/models/DashboardHubModel.svelte.ts export class DashboardHubModel { // Atoms dashboards: DashboardRow[] = $state([]); page: number = $state(1); searchQuery: string = $state(""); // ... < 40 atoms // Actions async loadDashboards(): Promise { ... } setPage(n: number): void { ... } // ... < 40 methods } ``` Page file becomes a thin render layer: ```svelte ``` **Decomposition gate** (ADR‑0010): If a Model exceeds **400 lines** or **40 public methods**, split into submodels by responsibility domain (e.g. `DashboardFiltersModel`, `DashboardSelectionModel`, `DashboardGitModel`). ### Design Token System **Raw Tailwind color classes are DEPRECATED in page and component code.** All colors MUST use semantic tokens defined in `frontend/tailwind.config.js`. This is the single source of truth for the visual system. **Token families** (from `tailwind.config.js`): | Purpose | Token | Maps to | |---------|-------|---------| | Primary action | `bg-primary text-white` | blue‑600 | | Page background | `bg-surface-page` | slate‑50 | | Card surface | `bg-surface-card` | white | | Muted surface | `bg-surface-muted` | slate‑100 | | Default border | `border-border` | slate‑200 | | Strong border (inputs) | `border-border-strong` | slate‑300 | | Primary text | `text-text` | slate‑900 | | Muted text | `text-text-muted` | slate‑500 | | Subtle text (placeholders) | `text-text-subtle` | slate‑400 | | Destructive / error | `bg-destructive-light text-destructive border-destructive-ring` | red family | | Success | `bg-success-light text-success` | green family | | Warning | `bg-warning-light text-warning` | amber family | | Info | `bg-info-light text-info` | sky family | **Correct vs. wrong:** ```svelte // ✅ CORRECT — semantic tokens