2 Components and Contracts
Nate edited this page 2026-11-21 20:21:39 -08:00

Components and contracts

Components are Go partials

Reusable UI is a shared template with a documented data shape, rendered by the server: templates/fit_workbench.html is the model (the simulator and the read-only public copies render the same markup). The shared set is listed in pageSharedTemplates (core_pages.go). Before building a new pattern, check whether a partial already does it; before changing a partial, check every page that renders it.

Two registries are single sources of truth, and tests hold them to it:

  • Navigation: sectionNav in nav.go drives the sidebar menus AND the section tab strip. The quick-jump palette in app.js (quickJumpPages) must carry the same labels: TestQuickJumpPagesMatchNav fails otherwise.
  • Home widgets: the module manifest (module_manifest.go) and the overview registry (home_overview.go) define each widget's id, title, default size and layer. A widget renders through the home template by id; its body comes from stored data.

Server → JS contracts

  • Data reaches JS as data-* attributes for small facts and as a JSON payload for structured state (the planner). The contract lives on the Go DTO: invariants are written there (planner payload lists are never null: they are coerced in planFinishPreset, because Go nil slices marshal to null and plan.js dereferences them) and mirrored in the JS, which normalizes defensively in one place (setPayload).
  • Mirror each payload's shape as a JSDoc @typedef in the JS file that consumes it. Editors light up, no toolchain needed.
  • When a contract changes, the Go DTO comment, the typedef and the tests change in the same commit.