On this page
- Status: Accepted. Batch D2b (2026-09-03), commit
4e1b872b. - Owners: Platform (site programme).
- Extends: ADR 0012 (the template installer this ADR gives a second source), ADR 0038–0041.
Context#
dashboard-templates/registry.ts is a code module, Zod-parsed at load; installTemplate()
materialises rows from it. A department-shaped client's whole dashboard set (HR: seven pages —
overview, recruitment, turnover, OT, staff cost, ROI per employee, promotion and salary) is exactly
this shape, but authoring it as a compiled TypeScript registry entry would mean "onboarding a second
HR-shaped customer is a deploy" — the opposite of the tenant-dataset layer's promise. The installer's
OUTPUT shape (ordinary dashboards + dashboard_widgets rows) does not need to change; only WHERE
the declaration comes from does.
Decisions#
D1 — org_dataset_packs: a pack is per-org catalog data, not a fact
org_dataset_packs (packages/schema/src/tables/org-dataset-packs.ts): (org_id, pack_key, version)
is the pack's own identity; content is its full declaration (pages, widgets, bindings, filter-bar
hints, presentation notes) as validated JSONB. dataset_keys names every org_datasets.dataset_key
the pack's widgets bind to — a structural fact both the validator and the installer read to refuse
installing onto an org that has not declared one of them. A semantic edit to content is a NEW row at
version N+1 (never an update in place), the same archive-old-insert-new idiom the field catalog
runs on (ADR 0038 D1), so an already-installed dashboard's lineage stays meaningful. Rides the plain
org_only RLS cohort, like the sibling org_dataset_fields/org_dataset_links schema tables.
D2 — installDatasetPack(): the installer's second source
apps/web/src/server/dataset-packs/install.ts mirrors installTemplate() almost verbatim — one
dashboards row per pack page, dashboard_widgets materialised from that page's widget list, one
transaction, idempotent per (org, brand, pack page). Deliberately different from installTemplate():
- The source is a DB row, not a compiled registry entry.
- Installed widgets carry
origin: 'custom', never'template', anddashboards.template_keystays NULL. The ADR 0012 D3 opt-in-update engine resolves a dashboard's template by lookingtemplate_keyup in the compiled registry — a pack-scoped key there would either collide with a real template key or resolve to nothing, and the dashboard view rendersTemplateUpdateBannerfor any dashboard with a non-emptytemplate_key. Not wiring pack lineage into that machinery is the safe choice: a new pack version installs fresh dashboards for its new/changed pages rather than updating in place, and a real per-widget opt-in-update path for packs is future work, out of this batch's scope. - One pack installs N dashboards, each independently idempotent: re-running the install for a pack version already installed returns the existing dashboards for pages already present and creates only the missing ones, so a version bump that only ADDS a page never force-recreates the untouched ones.
D3 — The pack is validated by the SAME schema the compiled installer uses
apps/web/src/server/dataset-packs/pack-schema.ts (datasetPackSchema) reuses the same
widgetConfigSchema union dashboardTemplateSchema already validates against, so a pack can never
carry a config the builder or renderer cannot read. Every org_dataset binding's dataset_key inside
the pack must be one of the pack's own declared dataset_keys (enforced in the schema's own
superRefine).
D4 — Registry validity is a build-time audit, mirroring the compiled template ratchet
dataset-pack-registry-validity.ts walks every *.json file under
apps/web/src/server/dataset-packs/, parses it against datasetPackSchema, and — on top of that —
runs the same version/content ratchet dashboard-template-registry-validity.ts runs for the compiled
registry: editing a pack's content without bumping version would silently desync an org that
already installed it, because installDatasetPack keys idempotency on pack_key + version +
page_key.
D5 — The HR pack proves the mechanism end to end, on real infrastructure
hr-people-analytics.json: seven pages bound through orgDatasetBinding, bilingual, per-page filter
bars declared. scripts/onboarding/seed-hr-org.ts (dry run by default) declares five datasets through
the real router, ingests the workbook through the real dataset_record promoter, runs rollups through
the real backfill processor, installs the pack, and writes reconciliation rows. On the gate database:
11 of 15 oracle figures match exactly (Active HC 163, hires 31, OT hours 6,909.25, average HC 159.71,
five recruitment counts, promotions 15); the four gaps are blank workbook columns or a documented rule
difference, printed, never asserted red. verify-hr-dashboard-render.ts proves the overview renders
through dashboards.bySlug and explore.orgDatasetQuery; other brands with no data show no_data,
never a fabricated zero.
Consequences#
- A second HR-shaped customer (or a second finance-shaped one, once that pack exists) onboards as a pack install plus a dataset declaration — a data import, not a deploy.
- A pack's version history is real lineage: an operator can see exactly which pack version an org's
dashboards came from, and a pack edit that forgets to bump
versionis caught before it reaches a live org. - The
dashboard_widgets.template_keymechanism stays exactly what it is for the compiled registry; packs deliberately do not reuse it, avoiding a false-positive update-available banner.
Implementation status (declared 2026-09-03)#
| Decision | Status | Evidence |
|---|---|---|
D1 org_ table |
Landed | migration 0194_ |
D2 install |
Landed | apps/; idempotent per (org, brand, page), verified in hr- |
| D3 shared schema validation | Landed | dataset-, reuses widget; superRefine cross-checks dataset_ |
| D4 registry validity audit | Landed | scripts/ in audit:all, baseline file . |
| D5 HR pack + end-to-end proof | Landed | hr-; scripts/; 11/15 oracle exact on the gate DB |