Treasury & Bank Transfer Management System — سامانه مدیریت خزانهداری و حوالههای بانکی
docs: add TreasuryFlow UI reconstruction implementation plan
Davood Mehraban committed
Oct 5, 2026 at 22:48 UTC
fdb60fcb8fccd220fc3d244f36699d996b8099dc
1 file changed
+120
docs/superpowers/plans/2026-10-05-treasuryflow-ui-reconstruction.md
new
+120
@@ -0,0 +1,120 @@
1
+# TreasuryFlow UI Reconstruction Implementation Plan
2
+
3
+> **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.
4
+
5
+**Goal:** Replace the current non-functional shell with the approved nine-screen, RTL-first TreasuryFlow product experience and make every primary navigation/action operate through real application/domain services.
6
+
7
+**Architecture:** Keep the tested domain modules as the source of business rules. Build a reusable UI system and route-level application surfaces on top of explicit application services and repositories; desktop-local mode uses a durable free local repository while production preserves PostgreSQL and tenant isolation. Primary screens never use fragment-only navigation or synthetic success.
8
+
9
+**Tech Stack:** Next.js 16.3.8, React 19.2, TypeScript 5.9 strict, Vitest 3.2, repository-local CSS, PostgreSQL adapter for production, free/open-source dependencies only.
10
+
11
+**Spec:** `docs/superpowers/specs/2026-10-05-treasuryflow-ui-reconstruction-design.md`
12
+
13
+## Global Constraints
14
+- Approved nine-screen TreasuryFlow reference image is the visual source of truth.
15
+- No paid tools, paid plugins, paid UI kits, paid SaaS subscriptions, or commercial assets.
16
+- Real Next.js routes for all primary navigation.
17
+- UI actions must use application/domain services; no fake success.
18
+- Maker/checker, idempotency, UNKNOWN manual-review, tenant isolation, and bank-LIVE safety invariants remain mandatory.
19
+- Desktop-local mode must persist safe local state across restart.
20
+- Production authentication and PostgreSQL remain fail-closed.
21
+- Bank LIVE remains disabled without external certification/configuration.
22
+
23
+## Review Focus
24
+- Persian/RTL text corruption or mojibake must fail tests and never ship.
25
+- Navigation must not silently fall back to the dashboard or hash fragments.
26
+- Transfer submission must reject invalid IBAN/money and maker self-approval.
27
+- Restarting desktop-local mode must retain created safe-local records.
28
+- UNKNOWN or disabled bank outcomes must remain explicit and never render as success.
29
+
30
+---
31
+
32
+### Task 1: Design tokens, RTL shell, and route contract
33
+**Files:** create `src/app/ui/tokens.css`, `src/app/ui/AppShell.tsx`, `src/app/ui/navigation.ts`; modify `src/app/globals.css`, `src/app/layout.tsx`; tests `src/app/navigation.test.ts`, `src/app/shell.test.ts`.
34
+**Interfaces:** produces `PRIMARY_NAV: readonly NavItem[]` and `AppShell({children,title,actions})`; nav item = `{labelFa:string;href:string;group:'operations'|'controls'|'reports'}`.
35
+- [ ] Write failing tests for unique absolute non-fragment routes and Persian labels without replacement corruption.
36
+- [ ] Run targeted tests and verify FAIL.
37
+- [ ] Implement tokens, sidebar/header shell, active route, RTL landmarks, responsive layout, free/system font fallback.
38
+- [ ] Run targeted tests and verify PASS.
39
+- [ ] Commit `feat: add TreasuryFlow RTL application shell`.
40
+
41
+### Task 2: Local durable repository and application façade
42
+**Files:** create `src/platform/local/local-store.ts`, tests, `src/platform/application/treasury-service.ts`, tests, and `src/platform/application/types.ts`.
43
+**Interfaces:** `TreasuryService` exposes list/get/create/submit/approve payments, accounts, beneficiaries, audit, and dashboard. Local store persists versioned JSON atomically.
44
+- [ ] Write failing persistence tests for create/reload, schema version, recovery, tenant scoping.
45
+- [ ] Write failing service tests for validation, maker/checker, audit emission, no synthetic bank success.
46
+- [ ] Implement local repository and application façade using existing domain rules.
47
+- [ ] Run targeted tests and verify PASS.
48
+- [ ] Commit `feat: add durable desktop-local treasury service`.
49
+### Task 3: Dashboard and real route navigation
50
+**Files:** create `src/app/dashboard/page.tsx`, `dashboard-view.tsx`, tests; modify `src/app/page.tsx`, `src/app/ui/AppShell.tsx`.
51
+**Interfaces:** consumes `TreasuryService.getDashboard()`; cards link to filtered operational routes.
52
+- [ ] Write failing tests for queue, review, reconciliation, account health, activity, and card destinations.
53
+- [ ] Implement root entry behavior and dashboard composition matching approved reference hierarchy.
54
+- [ ] Verify every dashboard action routes to a meaningful destination.
55
+- [ ] Run tests and verify PASS.
56
+- [ ] Commit `feat: rebuild operational dashboard`.
57
+
58
+### Task 4: Payments list, detail, and new transfer workflow
59
+**Files:** create `src/app/payments/page.tsx`, `src/app/payments/new/page.tsx`, `src/app/payments/[id]/page.tsx`, shared components/actions, and `payments-flow.test.tsx`.
60
+**Interfaces:** consumes `TreasuryService.listPayments/createPayment/submitPayment/getPayment`; transfer input includes source account, beneficiary, amount IRR, payment date, reference, description.
61
+- [ ] Write failing tests for search/filter/table navigation and detail rendering.
62
+- [ ] Write failing form tests for invalid IBAN dependency, unsafe/negative amount, missing beneficiary/account, duplicate reference/idempotency, valid draft.
63
+- [ ] Implement payments table, badges, filters, lifecycle detail, and transfer form.
64
+- [ ] Ensure submit changes state only through service/domain workflow.
65
+- [ ] Run tests and verify PASS.
66
+- [ ] Commit `feat: add functional payments and transfer workflow`.
67
+
68
+### Task 5: Bank accounts and beneficiaries/master data
69
+**Files:** create `src/app/accounts/page.tsx`, `src/app/beneficiaries/page.tsx`, `src/app/master-data/actions.ts`, tests; modify treasury service.
70
+**Interfaces:** local-safe CRUD, reusing `createBankAccount` and `createBeneficiary`.
71
+- [ ] Write failing tests for valid/invalid creation and tenant isolation.
72
+- [ ] Implement account cards/table and beneficiary whitelist/history-ready surfaces.
73
+- [ ] Display connection/balance as unavailable unless backed by evidence.
74
+- [ ] Run tests and verify PASS.
75
+- [ ] Commit `feat: add accounts and beneficiary management`.
76
+
77
+### Task 6: Reconciliation and bank submission queue
78
+**Files:** create `src/app/reconciliation/page.tsx`, `src/app/queue/page.tsx`, actions and tests.
79
+**Interfaces:** consumes existing `reconcile()` and bank adapter contracts; queue lists only eligible records.
80
+- [ ] Write failing tests for MATCHED/AMBIGUOUS/UNMATCHED and manual review.
81
+- [ ] Write failing tests proving disabled adapter cannot produce success and UNKNOWN never auto-retries.
82
+- [ ] Implement reconciliation and queue views with explicit disabled/live-unavailable state.
83
+- [ ] Run tests and verify PASS.
84
+- [ ] Commit `feat: add reconciliation and safe submission queue`.
85
+### Task 7: Reports and audit explorer
86
+**Files:** create `src/app/reports/page.tsx`, `src/app/audit/page.tsx`, reports actions and tests.
87
+**Interfaces:** consumes `report()`, `toCsv()`, `filterAudit()`; exports only filtered real data.
88
+- [ ] Write failing tests for totals, filters, CSV, audit filters/order/read-only.
89
+- [ ] Implement report cards/table/export and audit explorer.
90
+- [ ] Run tests and verify PASS.
91
+- [ ] Commit `feat: add reports and audit explorer`.
92
+
93
+### Task 8: Login/local entry, permissions, and state surfaces
94
+**Files:** create `src/app/login/page.tsx`, `src/app/ui/StateView.tsx`, `PermissionBoundary.tsx`, tests; modify Tasks 3–7 routes.
95
+**Interfaces:** production stays trusted external identity; desktop-local entry is explicitly local/offline-safe.
96
+- [ ] Write failing tests for local-entry label, permission denied, validation/success/failure/loading/empty, keyboard focus.
97
+- [ ] Implement local entry and shared permission/state surfaces.
98
+- [ ] Apply consistent states to all routes.
99
+- [ ] Run tests and verify PASS.
100
+- [ ] Commit `feat: harden entry permissions and UI states`.
101
+
102
+### Task 9: Interaction, accessibility, visual regression, and desktop release
103
+**Files:** create `scripts/ui-smoke.mjs`, `scripts/desktop-workflow-smoke.mjs`; modify `scripts/smoke.mjs`, `package.json`, desktop packaging; create `docs/UI_RECONSTRUCTION_GATE.md`.
104
+**Interfaces:** `npm run ui:smoke` validates all routes/headings; desktop smoke clean-installs, creates a safe draft, navigates, restarts, and proves persistence.
105
+- [ ] Add automated route smoke coverage for all primary pages.
106
+- [ ] Add keyboard/RTL/accessibility assertions using free tooling only.
107
+- [ ] Rebuild portable desktop runtime.
108
+- [ ] Run clean-install workflow smoke with navigation, draft creation, detail, restart, retained record.
109
+- [ ] Run full gate: `npm run typecheck && npm test -- --reporter=dot && npm run lint && npm run build && npm audit --omit=dev --audit-level=high && npm run ui:smoke && npm run desktop:workflow-smoke`.
110
+- [ ] Compare running screens side-by-side against approved nine-screen reference and fix material deltas.
111
+- [ ] Record evidence in `docs/UI_RECONSTRUCTION_GATE.md`.
112
+- [ ] Commit `release: complete TreasuryFlow product UI reconstruction`.
113
+- [ ] Push branch and inspect remote CI status without inferring success from local checks.
114
+
115
+## Self-review
116
+- Spec coverage: all nine approved screens plus audit/master-data dependencies are assigned.
117
+- Free-only constraint: no paid dependency is introduced.
118
+- Architecture: domain rules remain below application services; UI has no direct financial mutation.
119
+- Safety: maker/checker, UNKNOWN, disabled LIVE bank, idempotency, tenant boundaries have owning tests.
120
+- Delivery: desktop acceptance exercises real navigation and persisted workflow, not only HTTP readiness.