From 6721e601662fccdbcf33dd88f0710a8dbca8b980 Mon Sep 17 00:00:00 2001 From: curo1305 Date: Fri, 12 Jun 2026 13:23:25 +0200 Subject: [PATCH] docs(09): capture phase context --- .../09-CONTEXT.md | 151 ++++++++++++++++++ .../09-DISCUSSION-LOG.md | 122 ++++++++++++++ 2 files changed, 273 insertions(+) create mode 100644 .planning/phases/09-admin-panel-rearchitecture/09-CONTEXT.md create mode 100644 .planning/phases/09-admin-panel-rearchitecture/09-DISCUSSION-LOG.md diff --git a/.planning/phases/09-admin-panel-rearchitecture/09-CONTEXT.md b/.planning/phases/09-admin-panel-rearchitecture/09-CONTEXT.md new file mode 100644 index 0000000..9882843 --- /dev/null +++ b/.planning/phases/09-admin-panel-rearchitecture/09-CONTEXT.md @@ -0,0 +1,151 @@ +# Phase 9: Admin Panel Rearchitecture - Context + +**Gathered:** 2026-06-12 +**Status:** Ready for planning + + +## Phase Boundary + +Phase 9 delivers: (1) `AdminLayout.vue` registered as the `/admin` route component with its own sidebar and ``; (2) each admin section extracted as a deep-linkable child route (`/admin`, `/admin/users`, `/admin/quotas`, `/admin/ai`, `/admin/audit`); (3) a new admin overview page at `/admin` showing platform stats + last 10 audit entries; (4) the `requiresAdmin` guard updated to protect all `/admin/*` children; (5) strict admin role separation — admin accounts are redirected to `/admin` on all user routes; (6) Tailwind safelist configured for dynamic `providerColor`/`providerBg`/`providerLabel` class patterns; (7) `AdminView.vue` and the original `AdminXxxTab.vue` components deleted; (8) CODE-09 comment purge pass over all Phase 9 files and retroactively over Phase 8 backend sub-packages. + + + + +## Implementation Decisions + +### Admin Overview Page (ADMIN-11) + +- **D-01:** Layout: 3–4 stat cards in a top row (total users, total storage, document status breakdown: processing/ready/failed), followed by a table of the last 10 audit log entries below. +- **D-02:** Backend: new `overview.py` sub-module in `backend/api/admin/` alongside the existing `users.py`, `quotas.py`, `ai.py`. Single `GET /api/admin/overview` endpoint returning all four stats in one payload. +- **D-03:** Audit entries are inline in the aggregate response — the overview call returns stats + last 10 entries in one HTTP request. No separate `/api/audit` call from the overview component. + +### Admin Sidebar Design (ADMIN-09 — PARTIAL OVERRIDE) + +- **D-04:** SVG icons for each sidebar nav item — consistent with `AppSidebar.vue` pattern. +- **D-05:** Visual identity: subtle "Admin" label or badge below the DocuVault logo in the sidebar header. Same indigo brand color. No accent color change. +- **D-06:** **No "Back to app" link.** Admin role is administration-only. If an admin user needs to use the document app, they must have a separate normal user account. This overrides the ADMIN-09 requirement text that specified "Back to app link at bottom returns to /". +- **D-07:** Nav items (in order): Overview, Users, Quotas, AI Config, Audit Log. No "Back to app". + +### Admin Role Strict Separation (NEW — not in original requirements) + +- **D-08:** After login, if `user.role === 'admin'`, the router redirects to `/admin` instead of `/`. +- **D-09:** The `beforeEach` guard detects admin role on non-admin routes and redirects to `/admin`. Admin accounts cannot navigate to user routes (`/`, `/topics`, `/settings`, `/cloud`, etc.). +- **D-10:** Two guards in `beforeEach`: (a) non-admin attempting `/admin/*` → redirect to `/`; (b) admin attempting non-admin route → redirect to `/admin`. Both must use `to.matched.some(r => r.meta.requiresAdmin)` for the admin check (Vue Router 4 does not inherit meta to children). + +### Tab Component Extraction (ADMIN-08, ADMIN-10) + +- **D-11:** The four existing tab components (`AdminUsersTab.vue`, `AdminQuotasTab.vue`, `AdminAiConfigTab.vue`, `AuditLogTab.vue`) become standalone view files (`AdminUsersView.vue`, `AdminQuotasView.vue`, `AdminAiView.vue`, `AdminAuditView.vue`) in `frontend/src/views/admin/`. Extraction is structural only: strip top-level padding (owned by `AdminLayout`), rename, wire as router children. +- **D-12:** Original `components/admin/AdminXxxTab.vue` files are deleted after extraction — they become dead code. `AdminView.vue` is deleted. +- **D-13:** `AuditLogTab.vue` is promoted as-is. No new features, filters, or backend changes for the audit log view in Phase 9. + +### Tailwind Safelist (CODE-06) + +- **D-14:** Add `safelist` in `tailwind.config.js` covering `providerColor`, `providerBg`, `providerLabel` dynamic class patterns from `formatters.js`. Pattern from PITFALLS.md §14: + ```js + safelist: [ + { pattern: /bg-(blue|green|purple|orange|gray|indigo|red)-(50|100|500|600)/ }, + { pattern: /text-(blue|green|purple|orange|gray|indigo|red)-(500|600|700)/ }, + ] + ``` + Researcher verifies which color families `formatters.js` actually uses and adjusts the pattern if needed. + +### CODE-09 Comment Purge + +- **D-15:** One dedicated plan at the end of Phase 9 covers all files touched in Phase 9 plus retroactive purge of Phase 8 backend sub-packages (`api/admin/`, `api/documents/`, `api/auth/`). +- **D-16:** Purge criterion: remove comments that describe WHAT code does (generic function docstrings, inline "this does X" comments). Keep comments that explain WHY: constraints, pitfall notes, non-obvious invariants (e.g., `api/admin/__init__.py`'s "sub-routers carry NO prefix" constraint stays; generic "Returns user list" docstrings go). + +### Claude's Discretion + +- Exact SVG icon choices for each admin sidebar nav item (researcher picks appropriate icons from the same icon family used in AppSidebar.vue) +- Exact Python queries for the overview aggregate endpoint (researcher reads `db/models.py` and determines the most efficient async query pattern) +- Naming of the new view files if `views/admin/` directory structure is adopted (researcher confirms directory convention) + + + + +## Canonical References + +**Downstream agents MUST read these before planning or implementing.** + +### Phase Goals and Requirements +- `.planning/ROADMAP.md` §"Phase 9: Admin Panel Rearchitecture" — goal, implementation notes, success criteria, pitfall references +- `.planning/REQUIREMENTS.md` §ADMIN-08, ADMIN-09, ADMIN-10, ADMIN-11, ADMIN-12, CODE-06, CODE-09 — formal requirement definitions +- **Note:** ADMIN-09 "Back to app link" is overridden by D-06 and D-08 above. CONTEXT.md decisions take precedence. + +### Vue Router 4 Admin Architecture +- `.planning/research/PITFALLS.md` §Pitfall 3 — `to.matched.some()` guard fix (security regression risk with flat `to.meta.requiresAdmin`) +- `.planning/research/PITFALLS.md` §Pitfall 4 — AdminLayout as route component, not App.vue v-else-if branch (double-render risk) +- `.planning/research/PITFALLS.md` §Pitfall 9 — double padding risk when extracting tab content into views with AdminLayout wrapper +- `.planning/research/PITFALLS.md` §Pitfall 14 — Tailwind purge of dynamic class names; safelist pattern + +### Frontend Architecture +- `.planning/codebase/ARCHITECTURE.md` — component responsibilities, router guard, layout resolution pattern +- `frontend/src/App.vue` — current AuthLayout switch pattern (AdminLayout must NOT be added as a third branch here) +- `frontend/src/layouts/AuthLayout.vue` — reference pattern for a standalone layout component with `` +- `frontend/src/router/index.js` — current guard and route structure being rearchitected +- `CLAUDE.md` §"Frontend: shared module map" — `formatters.js` is the single source for `providerColor`/`providerBg`/`providerLabel` +- `CLAUDE.md` §"Component architecture" — View → Smart → Presentational layering (admin views follow this) + +### Backend Architecture +- `backend/api/admin/__init__.py` — existing admin package aggregator pattern; `overview.py` is added alongside existing sub-modules +- `backend/api/admin/users.py`, `quotas.py`, `ai.py` — reference for sub-module structure (overview.py follows same pattern) +- `backend/api/audit.py` — existing audit log implementation; overview endpoint reuses its query logic for last 10 entries +- `backend/db/models.py` — ORM models for users, quotas, documents (needed for aggregate queries) +- `CLAUDE.md` §"Key Architectural Rules" — admin endpoints never return document content or credentials_enc + +### Existing Admin Components +- `frontend/src/views/AdminView.vue` — being deleted; contains current tab structure +- `frontend/src/components/admin/AdminUsersTab.vue` — being promoted to view +- `frontend/src/components/admin/AdminQuotasTab.vue` — being promoted to view +- `frontend/src/components/admin/AdminAiConfigTab.vue` — being promoted to view +- `frontend/src/components/admin/AuditLogTab.vue` — being promoted to view +- `frontend/src/utils/formatters.js` — dynamic class names that need safelist coverage + + + + +## Existing Code Insights + +### Reusable Assets +- `frontend/src/layouts/AuthLayout.vue` — exact pattern for a standalone layout: a plain `