thermograph/frontend/server
Emi Griffith b2b56bdc1a frontend: fix the three inconsistencies the onboarding guide found
1. CLAUDE.md and README.md described the superseded Python service. Both now
   describe server/ (Go), say plainly that the Python files at that level are
   the original the port was made from, and drop CLAUDE.md's claim that
   `make test-unit` is "the tier CI runs" — CI's only frontend check is the
   Dockerfile builder stage's gofmt + vet + go test.

2. static/units.js's F_REGIONS was guarded by nothing, despite three source
   comments claiming "a test asserts all three stay identical": the only check
   compared the Go set against the backend's Python. TestFCountriesMatchesUnitsJS
   now diffs the browser copy both directions.

   That backend cross-check also skips in CI — the image build context is
   frontend/, so backend/ is unreachable from the builder stage, which is the
   only place CI runs these tests. static/ IS in the context, so the Dockerfile
   copies units.js into the builder and the new assertion runs during the image
   build. Verified by mutating units.js and confirming the build fails.

3. Both docker-compose.test.yml files defaulted to the retired
   emi/thermograph-backend/app path, and the frontend harness pinned the
   split-era v0.0.2-split-ci tag. Path corrected in both. Rather than swap one
   hardcoded pin for another, backend-for-tests.sh now derives the tag from the
   checkout — sha-<12hex of `git log -1 -- backend/`>, the same domain-keyed
   rule build-push.yml and deploy.yml use — and compose requires the variable
   so a stale pin cannot creep back in.

Verified: backend 429 passed/8 skipped; frontend go vet clean and all packages
ok; frontend image builds; `make backend-up` pulls and serves on the derived
tag; shellcheck zero findings across the tree.

Unrelated pre-existing issue noted in the docs, not fixed here:
`make test-integration` fails 7/16 with 503 against a cold throwaway backend
(empty database, nothing warm). Reproduced identically on the old image, so it
predates this change.

Claude-Session: https://claude.ai/code/session_01AfXqHrxCJLs2D7hpQkiUiJ
2026-07-25 11:43:22 -07:00
..
internal frontend: fix the three inconsistencies the onboarding guide found 2026-07-25 11:43:22 -07:00
go.mod web/worker: add a process-level liveness heartbeat (#80) 2026-07-25 04:13:47 +00:00
go.sum web/worker: add a process-level liveness heartbeat (#80) 2026-07-25 04:13:47 +00:00
main.go web/worker: add a process-level liveness heartbeat (#80) 2026-07-25 04:13:47 +00:00
README.md web/worker: add a process-level liveness heartbeat (#80) 2026-07-25 04:13:47 +00:00

thermograph-frontend (Go)

The SSR frontend service, ported from the Python implementation one directory up (app.py / content.py / api_client.py / format.py): server-rendered content pages, the interactive tool's SPA shells, and every static asset. It is I/O-bound glue over the backend's /content/* JSON API — no climate maths, no database, no auth.

Layout

go.mod                        module thermograph/frontend (Go 1.26)
main.go                       config + mux + static + graceful shutdown
internal/config/              every env var the service reads (same names,
                              defaults and required/optional split as the
                              Python — see config.go's field docs)
internal/contentapi/          backend /content/* client: TTL cache, bounded
                              LRU, per-key single-flight, origin forwarding;
                              typed payloads in types.go
internal/render/              html/template engine over an embed.FS +
                              response ETag helpers (W/"sha1[:20]",
                              If-None-Match handling)
internal/render/templates/    the page templates (embedded; *.tmpl)
internal/contentdata/         glossary.yaml / pages.yaml loader (fail-loud
                              validation, file order preserved)

Dependencies: stdlib plus gopkg.in/yaml.v3 — the committed SSR copy in frontend/content/*.yaml is shared with the rest of the repo and uses block/ folded scalars, so a YAML parser is genuinely required.

Run locally

cd frontend/server
go build -o thermograph-frontend .
cd ..            # static/ and content/ resolve relative to the working dir
THERMOGRAPH_API_BASE_INTERNAL=http://127.0.0.1:8137 \
THERMOGRAPH_BASE=/thermograph \
  ./server/thermograph-frontend

THERMOGRAPH_API_BASE_INTERNAL is required — the boot fails loudly without it, same as the Python raised at import. Other env vars (all optional): THERMOGRAPH_BASE (default /thermograph; the image sets /), THERMOGRAPH_API_VERSION (default v2 — bump only per the API-version pinning contract in frontend/CLAUDE.md), THERMOGRAPH_API_BASE_PUBLIC, THERMOGRAPH_SSR_CACHE_TTL (seconds, default 600), THERMOGRAPH_GOOGLE_VERIFY / THERMOGRAPH_BING_VERIFY, and PORT (default 8080).

The process expects static/ and content/ in its working directory (frontend/ locally, /app in the image). Templates are embedded in the binary; static assets and the YAML copy are read from disk.

Test / verify

cd frontend/server
go build ./... && go vet ./... && go test ./...

The deployed binary is /usr/local/bin/thermograph-frontend inside the emi/thermograph/frontend image; the image name, frontend-* CI workflows and deploy path are unchanged from the Python service.