Documentation

Docs / Reference

ADR 0041 - Local server and embedded web UI

Status: Accepted (delegated review, 2026-11-03)

Context

ARCHITECTURE.md plans a React UI embedded in the single binary and an HTTP API that binds to 127.0.0.1 by default. VISION requires that stale data is never presented as current, so index freshness must be visible on every screen. ADR 0040 makes internal/egress the only package that may open a socket and allows listeners only on loopback IP literals through egress.ListenLoopback. The UI decisions in the T016 task record (internal) chose layout A (U1) and shadcn/ui on Radix (U2), with the M5 mockup's tokens.

Two constraints shape the build: go build and go test must keep working on Windows, macOS and Linux without Node, and go:embed needs the files at compile time (a pattern that matches nothing is a compile error; a pattern without all: silently drops names starting with . or _, which bundler hashes can produce).

T016 delivers this in two runs: T016c1 (server, API v0, security, a hand-written placeholder page) and T016c2 (the web/ project, built assets, drift check). This ADR records the decisions for both; T016c2 amends it with measurements.

Options considered and decisions

1. Built assets

internal/server/ui embeds all:static and exposes it as ui.Assets (fs.Sub rooted at static/).

2. Drift detection

scripts/check-web.sh rebuilds from the lockfile with the pinned Node and npm and fails when internal/server/ui/static differs from a clean build. It runs in CI on Linux when web inputs change; the Linux build is canonical (a different Windows build is not a failure). scripts/test.sh does not run it, so Go tests pass without Node.

3. Versions

Node 24.22.2 LTS with npm 11.19.1, pinned through .nvmrc, packageManager and engine-strict; exact dependency versions, lockfile v3, npm ci only. TypeScript 6.0.3, because typescript-eslint does not yet support 7.

4. Dependencies and licences

Runtime: react, react-dom, radix-ui, class-variance-authority, clsx, tailwind-merge, lucide-react. Development only: vite, @vitejs/plugin-react, typescript, tailwindcss, @tailwindcss/vite, tw-animate-css, vitest, jsdom, @testing-library/react, @testing-library/dom, eslint, @eslint/js, typescript-eslint, eslint-plugin-react-hooks, @types/react, @types/react-dom. No router, data-fetching, state, font or icon-font library; adding a dependency later updates this ADR.

A lockfile-based check allows MIT, ISC, BSD-2-Clause, BSD-3-Clause, Apache-2.0 and 0BSD for runtime packages, plus MPL-2.0, CC-BY-4.0, CC0-1.0, MIT-0 and BlueOak-1.0.0 for development packages; missing licences and OR/AND expressions fail. Minification drops licence comments, so the build writes third-party-licenses.txt, which the binary serves.

Some build tools copy their own code into the output, so the bundle is not only runtime packages: Tailwind CSS (preflight, theme variables, utilities), tw-animate-css (keyframes and animation utilities) and rolldown (the CommonJS interop helpers, derived from esbuild; its THIRD-PARTY-LICENSE is included). web/scripts/bundled-tools.mjs lists them as BUNDLED_TOOLS; the licence check holds them to the runtime allow-list, and the notice file carries their notices. Each known tool has markers (Tailwind's banner comment, tw-animate-css's --tw-enter-* variables, rolldown's helper prologue, Vite's modulepreload polyfill); the notice step fails when a marker of an unlisted tool is in the build or a listed tool left none. Vite's modulepreload polyfill is turned off (build.modulePreload.polyfill: false): the page is one entry chunk with no preload links, so it only added Vite's code. Tools that transform code without adding their own (TypeScript, @vitejs/plugin-react in production, the CSS minifier lightningcss, MPL-2.0) are not listed. npm run build writes the notice file itself, so a plain build output is complete. .npmrc sets ignore-scripts=true; no package needs an install script (fsevents ships a prebuilt binary).

5. Fencing

web/go.mod makes web/ its own module, so go list ./..., go vet, go test and the network boundary walk never enter web/node_modules (which contains Go files). A root .graphveinignore keeps the minified bundle out of Graphvein's self-index.

6. Serving and security

Alternatives rejected: binding names such as localhost (may resolve to non-loopback addresses); a token in the URL for authentication (adds friction while any local process can read the store file anyway); http.FileServer (directory listings, sniffed content types).

7. Routing

8. HTTP API v0

Path prefix /api/v0/. One error envelope {"error": {"code", "message"}} with codes not_found, method_not_allowed, host_not_allowed, cross_site_request, store_error, unavailable (503, the server is stopping) and internal. GET /api/v0/status reports the extractor version, the latest run (by parsed finish time, because run IDs are random and RFC3339Nano text does not sort) and freshness computed per request with the same calculation as graphvein status; no caching, calculations serialized by a one-slot semaphore, changed paths capped at 1000 with an exact count. checked_at is the instant the check starts, before the scan, so "fresh as of checked_at" never names a time after the scan began. When Ctrl+C ends serve, request contexts are cancelled at once (http.Server.BaseContext), so running walks stop, and Serve returns only after the last handler finished, before the store is closed. A failed freshness check is unknown, never fresh; clients treat unknown future states as unknown. The schema and state table are in docs/cli/serve.md.

9. Styling

Tailwind CSS v4 with shadcn/ui components copied into web/ (button, badge, tooltip, separator, skeleton) on the M5 tokens, following the OS colour scheme; system font stacks only, no web fonts.

Measurements (T016c2)

Consequences

Known gaps

Review notes (delegated review, 2026-11-03)

Review notes, web toolchain part (delegated review, 2026-11-03)

Revision 1 (T038: typed folder paths behind the guards)

Status: Accepted (delegated review, 2026-11-25)

Context

Section 6 kept every request read-only on one store, and the server read only the folder it was started on. The T038 workspace (ADR 0087) lets the UI add a folder to the workspace by typing its path, so the server must read a folder it was not started on and start an index run there. This revision records the rules for that; design question D5 of the T038 task record (internal), whose recommended default the developer accepted on 2026-11-24.

Options considered

Decision

  1. Both endpoints, and POST /api/v0/workspace/remove, pass every check of a state-changing POST (Host allow-list, Sec-Fetch-Site, Origin, http.CrossOriginProtection) plus a loopback peer (403 not_loopback), the per-process session token in X-Graphvein-Token (403 token_required; served by GET /api/v0/workspace behind the GET guard), Content-Type: application/json and one strict JSON object of at most 4 KiB, as the manifest edit (ADR 0075) does.
  2. Only absolute paths are accepted (~ and variables are not expanded); symbolic links are resolved and the resolved folder is what is shown, registered and indexed.
  3. Refused: a missing path, a file, the filesystem root, the home folder itself, the user configuration folder itself and the registry's folder (and anything inside it), any path inside a .graphvein or .git folder, a folder inside an already registered folder (the answer names that entry), a manifest or graphvein.yaml that does not load, and any other error reading the path. A folder that is already registered is answered as such, without a confirm value.
  4. The index of an added folder is written where graphvein index writes it (<folder>/.graphvein/index.db, or the configured store). No cancel (ADR 0052); only existing project manifests are added.

The rules are claim rows WS-21..WS-38 of the workspace contract.

Consequences

Review notes (delegated review, 2026-11-25, T038)

Revision 1 (typed folder paths behind the existing guards plus a confirmation) accepted with ADR 0087 after the final CI gate of 2026-11-25 (CI runs 45627357238, 45632313364 and 45638139948 (the last green on Linux, Postgres and Windows; postgres log 0 FAIL, 291 /postgres PASS)). The guards held in the independent review (Host/Origin/Fetch Metadata, loopback, session token, single-use confirmation bound to its folder, symlink and traversal refusals).

Report a problem with this pageSource: docs/adr/0041-local-server-and-embedded-web-ui.md