@ai-coach/vault-adapter-view
Local loopback HTTP adapter for the vault browser UI. This package turns a Vault instance into a 127.0.0.1-only HTTP server that serves the Angular vault-view app and exposes read/write JSON endpoints for the graph, plans, climb, and distillation views. Change this package when adding or updating HTTP routes, headers, or token checks for the browser UI.
What it does not do
- No vault business rules. All planning, climb, distillation, and graph logic stays in
@ai-coach/vault-applicationand@ai-coach/vault-domain. - No external network exposure. Binds strictly to
127.0.0.1, validatesHostandOriginheaders, and serves a strict Content-Security-Policy with zero remote assets. - No Angular UI source code. The frontend bundle is built by
apps/vault-viewand served as static files from its build output.
Architecture fit
- Scope:
scope:vault - Style:
architecture:hexagonal(type:adapter,adapter:vault-view) - Depends on:
@ai-coach/vault-application,@ai-coach/vault-domain(and build output ofapps/vault-view) - Used by:
@ai-coach/vault-view-server, and the view integration tests in@ai-coach/vault-mcp-server
[Browser (apps/vault-view)]
│ HTTP (127.0.0.1 + x-vault-token)
▼
[@ai-coach/vault-adapter-view] ──▶ [@ai-coach/vault-application]
Internal architecture & rules
- Modular route handlers:
src/view.tshandles loopback host checks, CSRF token validation, and top-level dispatch to focused route modules undersrc/routes/(static-assets,graph-routes,plans-routes,climb-routes,distill-routes) using shared request helpers insrc/http-helpers.ts. - Write protection: Every
POSTwrite endpoint requires a matchingOrigin,application/jsoncontent type, and the per-serverx-vault-tokeninjected intoindex.html. - Safe static serving: Static asset names are checked against a strict filename pattern before reading from
apps/vault-view/dist/browser/. - No comments in source code: Follow DEC-AIC-0011.
Public surface
createVaultViewServer(vault, opts)— Creates the Node HTTPServerexposing SPA routes (/,/plans,/climb), read endpoints (/graph.json,/note.json,/page.json,/plans.json,/climb.json,/structure.json,/sketch.png), and token-gated write endpoints (/api/mark,/api/summary,/api/structure,/api/reveal,/api/generate,/api/sketch).listenOnLoopback(server, port)— Binds the server to127.0.0.1and resolves its local URL.bookPage,noteBody— Helpers that load a book page or expand embeddedtasksquery blocks in a note body.
How to extend it
- Add or update the route handler in the matching module under
src/routes/(or create a new route module if adding a new view domain). - Wire the handler into
createVaultViewServerinsrc/view.tsand register any newPOSTpath inWRITESso token and origin checks apply automatically. - Add asset or route coverage in
src/assets.spec.tsand end-to-end HTTP tests invault-view-server. - Run
npm exec nx test @ai-coach/vault-adapter-viewandnpm exec nx lint @ai-coach/vault-adapter-view.
Running & testing
npm exec nx test @ai-coach/vault-adapter-view
npm exec nx lint @ai-coach/vault-adapter-view
npm exec nx typecheck @ai-coach/vault-adapter-view
npm exec nx build @ai-coach/vault-adapter-view
Unit tests run with Vitest to verify that served UI assets stay strictly local and preserve theme/graph styles. Full HTTP route tests live in vault-view-server.
Key ADRs
- DEC-AIC-0061 — Establishes the dedicated local view server hosted by this adapter.
- DEC-AIC-0052 — Defines the adapter boundary around
@ai-coach/vault-application. - DEC-AIC-0060 — Governs the eight-section package README structure.