# In-App Database Documentation Implementation Plan
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** Make the Part 3a documentation viewer reachable from inside DBX and editable — table and column notes, table groups, and per-group colour — autosaved to a notes file that can live in the user's repository.
**Architecture:** The viewer components stay pure (snapshot in, DOM out, zero backend calls, enforced by an existing contract test) so Part 3c can bundle them into a standalone HTML file. `DatabaseDocsDialog.vue` sits outside `src/docs/` and owns all I/O. Edits are pure transformations of the `AnnotationFile`, applied by Rust so the `shadowedNote` rule has exactly one implementation.
**Tech Stack:** Rust (`dbx-core`, `dbx-web`, `src-tauri`), Vue 3 `
```
The sizing class is copied verbatim from `SchemaDiagramDialog.vue:827`. The docs viewer is the same
kind of thing — a full-window workspace rather than a form — so it should not invent its own
dimensions.
`DatabaseDocsDialog.vue` — props `open`, `prefillConnectionId`, `prefillDatabase`, `prefillSchema`. On open: `collectDocsSnapshot(...)` for the raw snapshot, `loadDocsAnnotations(...)` for the file (falling back to `emptyAnnotations()` when null), then `applyDocsAnnotations(...)` for what it displays. Holds the raw snapshot for re-derivation.
On an `edit` event from `DocsApp`: apply the matching `annotationEdits` function, `schedule` the autosave, and call `applyDocsAnnotations` to refresh the display. Show the save status. Call `flush()` before closing. Use `useI18n()` HERE — the dialog is outside `src/docs/` — and pass `t` down as the `translate` prop. Add a button opening the existing schema diagram via `connectionStore.diagramSource`.
- [x] **Step 6: Wire the trigger**
The schema diagram uses this exact five-point wiring. Mirror it — I verified every location:
1. **`apps/desktop/src/stores/connectionStore.ts:381`** — `diagramSource` is
`ref<{ connectionId: string; database: string; schema?: string; tableName?: string } | null>(null)`,
returned from the store at line 6928. Add `docsSource` with the same shape beside it, and export it
the same way.
2. **`apps/desktop/src/composables/useDialogSources.ts` (~line 162)** — a `watch` on
`connectionStore.diagramSource` copies the prefills, sets `showDiagramDialog.value = true`, then
clears the source back to `null`. **Clearing it is what makes the dialog re-openable** — without
that, setting the same value twice does not re-trigger the watcher. Add the docs equivalent.
3. **`apps/desktop/src/components/layout/AppDialogs.vue:13`** — `defineAsyncComponent(() => import(...))`,
and **line 198** — rendered with `v-if="dialogs.showDiagramDialog.value"`,
`v-model:open`, and the prefill props. Follow both.
4. **`apps/desktop/src/components/objects/ObjectBrowser.vue:1428`** — `openDiagram(row)` sets
`connectionStore.diagramSource = { connectionId: props.connection.id, database: props.database,
schema: row.schema || selectedSchema.value, tableName: ... }`. Add `openDocs(row)` the same way.
5. **`apps/desktop/src/components/objects/ObjectBrowser.vue:2605`** — the context-menu entry, shaped
`...(canOpenDiagram.value ? [{ label: t("diagram.open"), action: () => openDiagram(row) }] : [])`.
Add the docs entry beside it using `t("docs.title")` from the namespace Task 6 added.
**ObjectBrowser is the right entry point**, not the connection tree: the tree has no `diagram.open`
entry either, and the docs dialog takes exactly the prefills ObjectBrowser already supplies
(connection, database, schema). If a tree-level entry is wanted later it is one more call site
setting the same `docsSource`.
- [x] **Step 7: Verify two guards bite**
One at a time, restoring between each. Report both failure messages.
1. Make the `catch` in `write()` swallow its error (`catch { pending = undefined; }`) → `surfaces a failure instead of swallowing it` must fail.
2. Delete the `inFlight` guard at the top of `write()` → `never runs two saves concurrently` must fail.
- [x] **Step 8: Full verification and commit**
```bash
export PATH="$HOME/.rustup/toolchains/stable-aarch64-apple-darwin/bin:$PATH"
pnpm vitest run apps/desktop/src
pnpm exec vue-tsc --noEmit --project apps/desktop/tsconfig.json
pnpm exec oxlint --vue-plugin apps/desktop/src/docs apps/desktop/src/components/docs
cargo test --workspace
git add apps/desktop/src src-tauri
git commit -m "feat(docs): mount the documentation viewer in DBX with autosaved editing"
```
---
## Done criteria
- Documentation opens from the connection tree, and edits to notes and group colours survive closing and reopening the dialog.
- Pointing `docs_notes_path` at a repository file produces a reviewable diff.
- `apps/desktop/src/docs/**/*.vue` still makes zero backend calls and persists nothing, enforced by the contract test.
- All 8 locales declare the same `docs` keys, enforced by a test.
- A failed save is visible and does not discard the user's work.
- `cargo test --workspace` and `pnpm vitest run apps/desktop/src` pass; `vue-tsc` and `oxlint` clean.
## Deferred to Part 3c
The standalone Vite bundle and self-contained HTML export; the `dbx docs` verb; hash routing; a minimal read-only ER renderer for the export; inlining `apps/desktop/public/fonts/geist-latin-wght-normal.woff2`; and closing the `DocEnum` fixture gap, since an exportable demo wants an enum-bearing schema anyway.