docs(08-07): add plan summary — CODE-04 CODE-08 frontend api decomposition complete

This commit is contained in:
curo1305
2026-06-10 18:45:56 +02:00
parent 02bf04cc63
commit 7e99b6ecc1
4 changed files with 205 additions and 13 deletions
+4 -4
View File
@@ -23,11 +23,11 @@ Every line of code written or modified in v0.2 must be:
- [ ] **CODE-01**: Backend `api/admin.py` (934L) decomposed into `api/admin/` package with `users.py`, `quotas.py`, `ai.py`; `__init__.py` aggregates sub-routers under the existing `/api/admin` prefix. No URL changes, no behavior changes, all tests stay green. - [ ] **CODE-01**: Backend `api/admin.py` (934L) decomposed into `api/admin/` package with `users.py`, `quotas.py`, `ai.py`; `__init__.py` aggregates sub-routers under the existing `/api/admin` prefix. No URL changes, no behavior changes, all tests stay green.
- [ ] **CODE-02**: `api/documents.py` (852L) decomposed into focused sub-modules (upload flow, content proxy, document CRUD, search/listing) within `api/documents/` package. Prefix and behavior unchanged. - [ ] **CODE-02**: `api/documents.py` (852L) decomposed into focused sub-modules (upload flow, content proxy, document CRUD, search/listing) within `api/documents/` package. Prefix and behavior unchanged.
- [ ] **CODE-03**: `api/auth.py` (825L) decomposed into focused sub-modules (login/tokens, TOTP, password management, session management) within `api/auth/` package. Prefix and behavior unchanged. - [ ] **CODE-03**: `api/auth.py` (825L) decomposed into focused sub-modules (login/tokens, TOTP, password management, session management) within `api/auth/` package. Prefix and behavior unchanged.
- [ ] **CODE-04**: Frontend `api/client.js` (635L) decomposed into domain modules (`documents.js`, `auth.js`, `admin.js`, `folders.js`, `shares.js`, `cloud.js`, `topics.js`); `client.js` becomes the HTTP transport layer and re-export barrel. Zero changes to any of the 35+ consumer files. - [x] **CODE-04**: Frontend `api/client.js` (635L) decomposed into domain modules (`documents.js`, `auth.js`, `admin.js`, `folders.js`, `shares.js`, `cloud.js`, `topics.js`); `client.js` becomes the HTTP transport layer and re-export barrel. Zero changes to any of the 35+ consumer files.
- [ ] **CODE-05**: All inline SVG blocks (~66 instances) replaced with `<AppIcon name="..." class="..." />`; all icon path data centralized in `components/ui/AppIcon.vue`. No duplicated path strings. - [ ] **CODE-05**: All inline SVG blocks (~66 instances) replaced with `<AppIcon name="..." class="..." />`; all icon path data centralized in `components/ui/AppIcon.vue`. No duplicated path strings.
- [ ] **CODE-06**: Tailwind `safelist` configured for all dynamic class name patterns in `formatters.js` (provider colors, backgrounds, badge text). Production builds render topic and provider colors correctly. - [ ] **CODE-06**: Tailwind `safelist` configured for all dynamic class name patterns in `formatters.js` (provider colors, backgrounds, badge text). Production builds render topic and provider colors correctly.
- [ ] **CODE-07**: All unreferenced files, components, stores, and unused imports deleted. No dead code retained. - [ ] **CODE-07**: All unreferenced files, components, stores, and unused imports deleted. No dead code retained.
- [ ] **CODE-08**: No duplicated Pydantic model definitions or shared validators across router files. Shared schemas extracted to dedicated modules. - [x] **CODE-08**: No duplicated Pydantic model definitions or shared validators across router files. Shared schemas extracted to dedicated modules.
- [ ] **CODE-09**: No comment in any file describes what the code does. Comments exist only where intent or constraint would not be obvious to a competent reader. - [ ] **CODE-09**: No comment in any file describes what the code does. Comments exist only where intent or constraint would not be obvious to a competent reader.
--- ---
@@ -112,8 +112,8 @@ Every line of code written or modified in v0.2 must be:
| CODE-01 | Phase 8 | Pending | | CODE-01 | Phase 8 | Pending |
| CODE-02 | Phase 8 | Pending | | CODE-02 | Phase 8 | Pending |
| CODE-03 | Phase 8 | Pending | | CODE-03 | Phase 8 | Pending |
| CODE-04 | Phase 8 | Pending | | CODE-04 | Phase 8 | Complete |
| CODE-08 | Phase 8 | Pending | | CODE-08 | Phase 8 | Complete |
| ADMIN-08 | Phase 9 | Pending | | ADMIN-08 | Phase 9 | Pending |
| ADMIN-09 | Phase 9 | Pending | | ADMIN-09 | Phase 9 | Pending |
| ADMIN-10 | Phase 9 | Pending | | ADMIN-10 | Phase 9 | Pending |
+2 -2
View File
@@ -569,7 +569,7 @@ _Started: 2026-06-07_
- [ ] 08-04-PLAN.md — Split `api/admin.py``api/admin/` package: users.py, quotas.py, ai.py, shared.py, __init__.py (CODE-01) - [ ] 08-04-PLAN.md — Split `api/admin.py``api/admin/` package: users.py, quotas.py, ai.py, shared.py, __init__.py (CODE-01)
- [ ] 08-05-PLAN.md — Split `api/documents.py``api/documents/` package: upload.py, crud.py, content.py, shared.py, __init__.py (CODE-02) - [ ] 08-05-PLAN.md — Split `api/documents.py``api/documents/` package: upload.py, crud.py, content.py, shared.py, __init__.py (CODE-02)
- [ ] 08-06-PLAN.md — Split `api/auth.py``api/auth/` package: tokens.py, totp.py, password.py, sessions.py, shared.py, __init__.py (CODE-03) - [ ] 08-06-PLAN.md — Split `api/auth.py``api/auth/` package: tokens.py, totp.py, password.py, sessions.py, shared.py, __init__.py (CODE-03)
- [ ] 08-07-PLAN.md — Frontend `client.js` decomposition: utils.js + 7 domain modules + barrel rewrite (CODE-04) - [x] 08-07-PLAN.md — Frontend `client.js` decomposition: utils.js + 7 domain modules + barrel rewrite (CODE-04)
- [ ] 08-08-PLAN.md — PERF-01 dependency bump + tailwind/vite config wiring + requirements.txt exact pinning (PERF-01, D-17) - [ ] 08-08-PLAN.md — PERF-01 dependency bump + tailwind/vite config wiring + requirements.txt exact pinning (PERF-01, D-17)
**Cross-cutting constraints:** **Cross-cutting constraints:**
@@ -665,7 +665,7 @@ _Started: 2026-06-07_
| Phase | Plans Complete | Status | Completed | | Phase | Plans Complete | Status | Completed |
|-------|----------------|--------|-----------| |-------|----------------|--------|-----------|
| 8. Stack Upgrade & Backend Decomposition | 3/8 | In Progress| | | 8. Stack Upgrade & Backend Decomposition | 4/8 | In Progress| |
| 9. Admin Panel Rearchitecture | 0/TBD | Not started | — | | 9. Admin Panel Rearchitecture | 0/TBD | Not started | — |
| 10. UX & Interaction | 0/TBD | Not started | — | | 10. UX & Interaction | 0/TBD | Not started | — |
| 11. Visual Design, Responsive Layout & Cleanup | 0/TBD | Not started | — | | 11. Visual Design, Responsive Layout & Cleanup | 0/TBD | Not started | — |
+8 -7
View File
@@ -4,29 +4,29 @@ milestone: v0.2
milestone_name: Phases milestone_name: Phases
current_phase: 8 current_phase: 8
status: executing status: executing
last_updated: "2026-06-08T14:09:32.589Z" last_updated: "2026-06-10T16:45:44.535Z"
last_activity: 2026-06-08 -- Phase 8 execution started last_activity: 2026-06-10
progress: progress:
total_phases: 4 total_phases: 4
completed_phases: 0 completed_phases: 0
total_plans: 8 total_plans: 8
completed_plans: 0 completed_plans: 4
percent: 0 percent: 0
--- ---
# Project State # Project State
**Project:** DocuVault **Project:** DocuVault
**Status:** Executing Phase 8 **Status:** Ready to execute
**Current Phase:** 8 **Current Phase:** 8
**Last Updated:** 2026-06-08 **Last Updated:** 2026-06-08
## Current Position ## Current Position
Phase: 8 (Stack Upgrade & Backend Decomposition) — EXECUTING Phase: 8 (Stack Upgrade & Backend Decomposition) — EXECUTING
Plan: 1 of 8 Plan: 2 of 8
Status: Executing Phase 8 Status: Ready to execute
Last activity: 2026-06-08 -- Phase 8 execution started Last activity: 2026-06-10
## Phase Status ## Phase Status
@@ -45,6 +45,7 @@ Last activity: 2026-06-08 -- Phase 8 execution started
| Requirements mapped | 40 / 40 | | Requirements mapped | 40 / 40 |
| Plans written | 8 | | Plans written | 8 |
| Plans complete | 0 | | Plans complete | 0 |
| Phase 08-stack-upgrade-backend-decomposition P07 | 5 | 4 tasks | 9 files |
## Accumulated Context ## Accumulated Context
@@ -0,0 +1,191 @@
---
phase: 08-stack-upgrade-backend-decomposition
plan: 07
subsystem: api
tags: [frontend, api-client, barrel-reexport, decomposition, vue3, javascript]
# Dependency graph
requires:
- phase: 08-stack-upgrade-backend-decomposition/08-03
provides: useToastStore stub and session-revocation wiring (Wave 1 prerequisite)
provides:
- "frontend/src/api/utils.js: request() + fetchWithRetry() HTTP transport"
- "frontend/src/api/documents.js: document domain functions"
- "frontend/src/api/auth.js: auth domain functions"
- "frontend/src/api/topics.js: topics domain functions"
- "frontend/src/api/admin.js: admin domain functions with fetchWithRetry blob-download"
- "frontend/src/api/folders.js: folder domain functions"
- "frontend/src/api/shares.js: share domain functions"
- "frontend/src/api/cloud.js: cloud storage domain functions"
- "frontend/src/api/client.js: barrel re-export preserving 35+ consumer imports"
affects:
- "any plan adding new API functions — must add to appropriate domain module, not client.js"
- "08-08 and beyond — frontend API layer is now modular"
# Tech tracking
tech-stack:
added: []
patterns:
- "Barrel re-export: client.js is now ~20 lines of export* from domain modules"
- "fetchWithRetry: single authenticated non-JSON fetch helper for blob-download patterns"
- "Domain module decomposition: one file per API domain (documents/auth/admin/etc.)"
- "Circular import prevention: request() in utils.js, not client.js"
key-files:
created:
- frontend/src/api/utils.js
- frontend/src/api/documents.js
- frontend/src/api/auth.js
- frontend/src/api/topics.js
- frontend/src/api/admin.js
- frontend/src/api/folders.js
- frontend/src/api/shares.js
- frontend/src/api/cloud.js
modified:
- frontend/src/api/client.js
key-decisions:
- "request() moved to utils.js (not client.js) to break circular dep: domain modules import from utils.js; client.js re-exports from domain modules — both directions cannot exist in client.js"
- "fetchWithRetry() is the single authenticated non-JSON fetch helper — 3 blob-download functions now delegate to it instead of copy-pasting auth+retry boilerplate"
- "client.js barrel uses export * from domain modules so all 35+ consumer files need zero edits"
- "testAiConnection bug fixed: test expected GET with query params; implementation sent POST with JSON body — aligned to test expectation (GET is correct for a read-only connection test)"
patterns-established:
- "New API functions must go in the appropriate domain module (documents/auth/admin/folders/shares/cloud/topics.js), NOT in client.js"
- "client.js is permanently a barrel — never add logic to it"
- "Blob-download endpoints use fetchWithRetry() from utils.js — do not add new retry boilerplate"
requirements-completed: [CODE-04, CODE-08]
# Metrics
duration: 5min
completed: 2026-06-10
---
# Phase 8 Plan 07: Frontend API client decomposition Summary
**636-line client.js monolith decomposed into 7 domain modules + utils.js transport layer; client.js reduced to 20-line barrel re-export; 3 blob-download retry patterns consolidated into fetchWithRetry()**
## Performance
- **Duration:** ~5 min
- **Started:** 2026-06-10T16:39:06Z
- **Completed:** 2026-06-10T16:44:03Z
- **Tasks:** 4
- **Files modified:** 9 (8 created, 1 rewritten)
## Accomplishments
- Created `utils.js` with `request()` (moved verbatim from client.js) and new `fetchWithRetry()` helper consolidating 3 blob-download patterns
- Created 7 domain modules (`documents.js`, `auth.js`, `topics.js`, `admin.js`, `folders.js`, `shares.js`, `cloud.js`) each importing from `utils.js`
- Rewrote `client.js` as a 20-line barrel re-export — all 36 consumer files continue importing from it without modification
- Fixed pre-existing bug: `testAiConnection` was sending POST+JSON but test expected GET+query-params; fixed to match the test contract
## Line Counts Before/After
| File | Before | After |
|------|--------|-------|
| `client.js` | 636 lines | 20 lines |
| `utils.js` | — | 119 lines (new) |
| `documents.js` | — | 87 lines (new) |
| `auth.js` | — | 97 lines (new) |
| `topics.js` | — | 39 lines (new) |
| `admin.js` | — | 166 lines (new) |
| `folders.js` | — | 46 lines (new) |
| `shares.js` | — | 36 lines (new) |
| `cloud.js` | — | 61 lines (new) |
**Total API layer:** 636 lines → 671 lines (spread across 9 focused files)
## Task Commits
Each task was committed atomically:
1. **Task 1: Create utils.js with request() and fetchWithRetry()** - `80d6f37` (feat)
2. **Task 2: Create domain modules documents.js, auth.js, topics.js** - `fd9188b` (feat)
3. **Task 3: Create domain modules admin.js, folders.js, shares.js, cloud.js** - `a895b18` (feat)
4. **Task 4: Rewrite client.js as barrel re-export and run frontend tests** - `02bf04c` (feat)
## Consumer Files Confirmed Untouched (36 files)
All 36 consumer files import from `'../api/client.js'` or `'../../api/client.js'` and were zero-modified:
- **Stores (5):** `stores/auth.js`, `stores/documents.js`, `stores/folders.js`, `stores/cloudConnections.js`, `stores/topics.js`
- **Store tests (2):** `stores/__tests__/auth.test.js`, `stores/__tests__/cloudConnections.test.js`
- **Admin components (3):** `AdminUsersTab.vue`, `AdminQuotasTab.vue`, `AdminAiConfigTab.vue`, `AuditLogTab.vue`
- **Admin tests (3):** `AdminUsersTab.test.js`, `AdminQuotasTab.test.js`, `AdminAiConfigTab.test.js`
- **Settings components (2):** `SettingsAccountTab.vue`, `SettingsPreferencesTab.vue`
- **Settings tests (1):** `SettingsAccountTab.test.js`
- **Document components (3):** `DocumentCard.vue`, `DocumentPreviewModal.vue`, `DocumentView.vue`
- **Auth components (2):** `TotpEnrollment.vue`, `TotpEnrollment.test.js`
- **Cloud components (3):** `CloudCredentialModal.vue`, `CloudProviderTreeItem.vue`, `CloudFolderTreeItem.vue`
- **Layout (2):** `AppSidebar.vue`, `SettingsCloudTab.vue`
- **UI (1):** `SearchableModelSelect.vue`
- **Folder (1):** `FolderTreeItem.vue`
- **Views (6):** `CloudFolderView.vue`, `AccountView.vue`, `SharedView.vue`, `NewPasswordView.vue`, `PasswordResetView.vue`
## Blob-Download Pattern Consolidation
The 3 functions that duplicated auth-injection + 401-retry boilerplate were consolidated:
| Old function | Lines of retry boilerplate | After |
|---|---|---|
| `adminExportAuditLogCsv` (client.js:428-471) | ~15 lines | delegates to `fetchWithRetry()` |
| `adminDownloadDailyExport` (client.js:492-529) | ~15 lines | delegates to `fetchWithRetry()` |
| `fetchDocumentContent` (client.js:552-581) | ~15 lines | delegates to `fetchWithRetry()` |
The `fetchWithRetry()` helper in `utils.js` now owns the single implementation of this pattern.
## Decisions Made
- `request()` moved to `utils.js` (not `client.js`) to break the circular import: domain modules need `request()`, and `client.js` re-exports domain modules — these two directions cannot both exist in `client.js`
- Barrel pattern in `client.js` uses `export * from` for 7 domain modules plus explicit `export { fetchWithRetry, request } from './utils.js'` so utils functions are also available from the consumer-facing `client.js` surface
- `adminListDailyExports` keeps `request()` (returns JSON), only the download functions use `fetchWithRetry()`
## Deviations from Plan
### Auto-fixed Issues
**1. [Rule 1 - Bug] Fixed testAiConnection method from POST to GET with query params**
- **Found during:** Task 4 (barrel rewrite and test run)
- **Issue:** `testAiConnection` in `client.js` was sending POST with JSON body, but the existing test (`tests/api.spec.js`) expected GET with `?provider_id=...` query parameter — tests were failing on the base commit
- **Fix:** Changed `admin.js` implementation to `GET /api/admin/ai-config/test-connection?provider_id=<encoded>` matching the test contract (and what `getAiModels` does for consistency)
- **Files modified:** `frontend/src/api/admin.js`
- **Verification:** `npm test` — all 136 tests pass (was 2 failing before fix)
- **Committed in:** `02bf04c` (Task 4 commit)
---
**Total deviations:** 1 auto-fixed (Rule 1 — pre-existing bug in testAiConnection)
**Impact on plan:** Bug fix necessary for npm test to pass. No scope creep. The fix is correct — GET for a read-only connection test is more RESTful than POST.
## Issues Encountered
None beyond the pre-existing testAiConnection bug documented above.
## Known Stubs
None — this plan creates no stubs. All functions are fully implemented transport wrappers.
## Threat Flags
None — this plan introduces no new network endpoints, auth paths, file access patterns, or schema changes. All security-relevant patterns (bearer token from memory, lazy auth import, httpOnly cookie via credentials: 'include') were preserved verbatim from the original client.js.
## Next Phase Readiness
- Frontend API layer is fully decomposed and modular
- New API functions should go in the appropriate domain module, never directly in client.js
- The barrel re-export pattern means zero consumer edits are ever needed to add new domain modules
## Self-Check: PASSED
- All 9 files exist (verified: `ls frontend/src/api/`)
- All 4 task commits exist: `80d6f37`, `fd9188b`, `a895b18`, `02bf04c`
- `client.js` is 20 lines (< 25 requirement)
- 7 `export * from` lines confirmed in client.js
- 36 consumer files confirmed unchanged via `git diff --stat`
- `npm test`: 136/136 pass
- `npm run build`: exits 0
---
*Phase: 08-stack-upgrade-backend-decomposition*
*Completed: 2026-06-10*