Skip to main content

@ai-coach/vault-view-data-access

Frontend-owned DTOs, typed HTTP API services, browser platform adapters, and focused Angular signal stores for the vault view. It owns every HTTP call to the local view server and holds reactive state for the shell, Graph, Plans, and Climb features.

What it does not do​

  • No components, templates, or CSS. Presentational components live in libs/vault-view/ui and smart containers live in libs/vault-view/feat-*.
  • No direct backend or vault imports. @nx/enforce-module-boundaries restricts type:data-access inside scope:vault-view to type:data-access, type:util, and scope:shared. All payloads are defined here as frontend-owned DTOs.
  • No HttpClient or raw globalThis access in stores. Stores delegate HTTP calls to typed *Api services and read/write browser state exclusively through UrlHashService or injected DOCUMENT.

Architecture fit​

  • Scope: scope:vault-view
  • Style: architecture:layered (type:data-access)
  • Depends on: @ai-coach/vault-view-util
  • Used by: @ai-coach/vault-view, @ai-coach/vault-view-feat-graph, @ai-coach/vault-view-feat-plans, @ai-coach/vault-view-feat-climb
[feat-graph / feat-plans / feat-climb / app shell]
│
▼
[Focused Signal Stores + Facades] ──▶ [UrlHashService / DOCUMENT]
│
▼
[GraphApi / PlansApi / ClimbApi] ──HTTP + vaultTokenInterceptor──▶ [vault-view-server]

Internal architecture & rules​

  • Domain-grouped folders: Internals are grouped under src/lib/http/ (error normalization, latest-request cancellation, CSRF token interceptor), src/lib/shell/ (app-wide ShellStore, UrlHashService), src/lib/graph/ (graph, distill, and distill toasts), src/lib/plans/, and src/lib/climb/, each re-exported through src/index.ts.
  • Transport separated from state: GraphApi, PlansApi, and ClimbApi are pure providedIn: 'root' HTTP clients returning typed Observable<T>. Stores never inject HttpClient.
  • Focused, feature-scoped stores: ShellStore is app-scoped (providedIn: 'root'), while feature stores (PlansStore, ClimbStore, and provideGraphStores() composing GraphDataStore, GraphFilterStore, DistillStore, ToastStore, and the thin GraphStore facade) are provided at their lazy page components so state and subscriptions tear down on route exit.
  • Latest-request cancellation: Every store load() runs through createLatestRequestRunner(destroyRef), unsubscribing stale in-flight HTTP requests on rapid reloads and on destroy.
  • Centralized error normalization & CSRF token: normalizeHttpError and extractHttpErrorPayload standardize API error handling; vaultTokenInterceptor reads meta[name="vault-token"] via injected DOCUMENT and attaches x-vault-token on mutating requests.
  • Code hygiene: Explicit public/private member accessibility on every class member and zero comments in source code (DEC-AIC-0011).

Public surface​

  • HTTP & platform infrastructure: GraphApi, PlansApi, ClimbApi, vaultTokenInterceptor, readVaultToken, UrlHashService, normalizeHttpError, extractHttpErrorPayload.
  • App-wide store: ShellStore (theme, presentation mode, global refresh signal).
  • Graph stores & facade: provideGraphStores, GraphDataStore, GraphFilterStore, DistillStore, ToastStore, GraphStore.
  • Feature stores: PlansStore, ClimbStore.
  • Frontend-owned DTOs: Graph, Plans, Climb, and shared vault note/error DTO types.

How to extend it​

  1. Define the request and response DTO interfaces in the matching *.dto.ts file.
  2. Add the typed endpoint method to GraphApi, PlansApi, or ClimbApi (returning an Observable).
  3. Wire the call into the owning focused store using normalizeHttpError and createLatestRequestRunner for cancelable loads, then export any new public symbol from src/index.ts.
  4. Add Vitest unit tests covering the API call, error normalization, and store state transitions, then run npm exec nx lint @ai-coach/vault-view-data-access, npm exec nx typecheck @ai-coach/vault-view-data-access, and npm exec nx test @ai-coach/vault-view-data-access.

Running & testing​

Unit tests run in Vitest with Angular's zoneless TestBed, HttpTestingController, and injected fake DOCUMENT/UrlHashService stubs—no real browser or server is required.

npm exec nx test @ai-coach/vault-view-data-access
npm exec nx lint @ai-coach/vault-view-data-access
npm exec nx typecheck @ai-coach/vault-view-data-access

Key ADRs​

  • DEC-AIC-0059 — Establishes the Angular layered layout and frontend-owned DTOs for the vault view.
  • DEC-AIC-0062 — Codifies data-access layer boundaries, store/API separation, and Nx lint/typecheck/test guardrails.
  • DEC-AIC-0051 — Defines workspace tags and @nx/enforce-module-boundaries rules.
  • DEC-AIC-0060 — Governs the eight-section package README structure and Docusaurus ingestion.