Skip to main content

@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-application and @ai-coach/vault-domain.
  • No external network exposure. Binds strictly to 127.0.0.1, validates Host and Origin headers, and serves a strict Content-Security-Policy with zero remote assets.
  • No Angular UI source code. The frontend bundle is built by apps/vault-view and 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 of apps/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.ts handles loopback host checks, CSRF token validation, and top-level dispatch to focused route modules under src/routes/ (static-assets, graph-routes, plans-routes, climb-routes, distill-routes) using shared request helpers in src/http-helpers.ts.
  • Write protection: Every POST write endpoint requires a matching Origin, application/json content type, and the per-server x-vault-token injected into index.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 HTTP Server exposing 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 to 127.0.0.1 and resolves its local URL.
  • bookPage, noteBody — Helpers that load a book page or expand embedded tasks query blocks in a note body.

How to extend it​

  1. 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).
  2. Wire the handler into createVaultViewServer in src/view.ts and register any new POST path in WRITES so token and origin checks apply automatically.
  3. Add asset or route coverage in src/assets.spec.ts and end-to-end HTTP tests in vault-view-server.
  4. Run npm exec nx test @ai-coach/vault-adapter-view and npm 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.