@@ -8,225 +8,155 @@ tags:
88- architecture
99- consolidation
1010- rust
11+ depends_on :
12+ - " 185"
13+ - " 186"
14+ - " 187"
1115created_at : 2025-12-18T14:02:41.727119Z
1216updated_at : 2025-12-18T14:02:41.727119Z
1317---
1418
15- # Consolidate packages/ui with Desktop App Frontend Architecture
19+ # Unified UI Architecture: Rust-Powered Web & Desktop (Umbrella)
1620
1721> ** Status** : planned · ** Priority** : high · ** Created** : 2025-12-18
22+ >
23+ > ** ⚠️ Umbrella Spec** : Coordinates 3 sub-specs. See [ SPLIT.md] ( SPLIT.md ) and sub-specs for implementation details.
1824
1925## Overview
2026
21- ** Problem** : We currently maintain two separate UI implementations :
22- - ** ` packages/ui ` ** : Next.js SSR app with complex TypeScript backend (filesystem/database sources)
23- - ** ` packages/desktop ` ** : Tauri + Vite SPA with Rust backend (spec 169 migration complete)
27+ ** Problem** : Two UI implementations with different capabilities :
28+ - ** ` packages/ui ` ** : Next.js SSR, rich UI, but 150MB+ bundle + slow TypeScript backend
29+ - ** ` packages/desktop ` ** : Tauri + basic UI, fast Rust backend, but limited features
2430
25- This creates:
26- - Duplicate maintenance burden (same features in two codebases)
27- - Confusion about which UI to use/develop
28- - Inconsistent user experience between web and desktop
29- - Wasted development time implementing features twice
30- - Empty data issue in ` pnpm dev:web ` due to architectural mismatch
31+ ** Solution** : Unify around ** Vite SPA + Rust HTTP Server** :
32+ - One shared component library
33+ - One Rust HTTP server (multi-project support)
34+ - One Vite SPA for both web and desktop
35+ - ** Result** : 30MB bundle, 10x faster, single codebase
3136
32- ** Solution ** : Consolidate on the ** desktop app's frontend architecture ** (Vite + React SPA) and ** Rust backend ** for both web and desktop use cases.
37+ ## Sub-Specs
3338
34- ## Design
39+ | Spec | Focus | Est. Tokens |
40+ | ------| -------| -------------|
41+ | ** [ 185] ( ../185-ui-components-extraction/ ) ** | Extract shared component library | ~ 1800 |
42+ | ** [ 186] ( ../186-rust-http-server/ ) ** | Build Rust HTTP server + multi-project | ~ 2000 |
43+ | ** [ 187] ( ../187-vite-spa-migration/ ) ** | Migrate Next.js to Vite SPA | ~ 1500 |
3544
36- ### Current State
45+ ** Total ** : ~ 5300 tokens (vs 7714 original)
3746
38- ```
39- packages/ui (Next.js)
40- ├── TypeScript backend
41- │ ├── specs service (filesystem/multi-project/database)
42- │ ├── project registry
43- │ ├── database (better-sqlite3)
44- │ └── API routes
45- └── React frontend (SSR)
46-
47- packages/desktop (Tauri)
48- ├── Rust backend
49- │ ├── specs operations
50- │ ├── project management
51- │ ├── Tauri commands
52- │ └── Native performance
53- └── React frontend (SPA)
54- ```
47+ ## Design
5548
5649### Target Architecture
5750
5851```
59- packages/ui (Vite SPA) - NEW
60- ├── Vite + React SPA (from desktop)
61- ├── Data via Rust CLI/MCP backend
62- ├── Lightweight HTTP wrapper (if needed)
63- └── Shared components with desktop
64-
65- packages/desktop (Tauri) - UNCHANGED
66- ├── Rust backend (Tauri commands)
67- └── React frontend (SPA)
68- └── Shared with packages/ui
69-
70- Rust backend (CLI/MCP) - EXISTING
71- └── All spec operations
52+ packages/ui-components (NEW)
53+ ↓ ↓
54+ packages/ui packages/desktop
55+ (Vite SPA) (Tauri → Vite SPA)
56+ ↓ ↓
57+ HTTP Client Tauri Commands
58+ ↓ (Direct Rust calls)
59+ Rust HTTP Server ↓
60+ (Axum) leanspec_core
61+ ↓
62+ leanspec_core
7263```
7364
74- ### Key Architectural Decisions
75-
76- 1 . ** Frontend** : Use desktop's Vite+React SPA codebase as the foundation
77- 2 . ** Backend** : Rust CLI/MCP for all spec operations (already exists)
78- 3 . ** Code Sharing** : Extract common components into ` packages/ui-shared ` or similar
79- 4 . ** Data Access** :
80- - Desktop: Tauri commands → Rust backend
81- - Web UI: HTTP API → Rust CLI (spawned process or HTTP wrapper)
82- 5 . ** Multi-Project** : Both use Rust backend's project registry
83-
84- ### Migration Strategy
85-
86- ** Phase 1: Extract Shared UI Components**
87- - Identify common components between desktop and current UI
88- - Create ` packages/ui-shared ` for shared React components
89- - Extract: SpecList, SpecDetail, Dependencies, Stats, Layout components
90-
91- ** Phase 2: Replace packages/ui with SPA**
92- - Copy desktop's Vite+React structure to new ` packages/ui `
93- - Remove Next.js dependencies
94- - Adapt data layer to use Rust backend (CLI spawning or HTTP wrapper)
95- - Implement lightweight API layer if needed
96-
97- ** Phase 3: Update desktop to use shared components**
98- - Replace desktop's components with shared versions
99- - Maintain Tauri command integration
100-
101- ** Phase 4: Deprecate old UI**
102- - Archive old Next.js UI code
103- - Update documentation
104- - Update CLI ` ui ` command to use new package
65+ ** Important distinction** :
66+ - ** Web** : Uses HTTP server (browser can't call Rust directly)
67+ - ** Desktop** : Uses Tauri commands (direct Rust calls, no HTTP overhead)
68+
69+ ### Key Decisions
70+
71+ 1 . ** Eliminate Next.js** : Vite SPA (83% smaller, same DX)
72+ 2 . ** Rust HTTP Server for Web** : Axum + ` leanspec_core ` (10x faster than TypeScript)
73+ 3 . ** Tauri Commands for Desktop** : Direct Rust calls (no HTTP overhead)
74+ 4 . ** Shared Components** : ` packages/ui-components ` used by web + desktop
75+ 5 . ** Multi-Project Default** : Both platforms use project registry
76+ 6 . ** Config JSON** : ` ~/.lean-spec/config.json ` (not YAML)
77+
78+ ### Configuration
79+
80+ ** ` ~/.lean-spec/config.json ` ** :
81+ ``` json
82+ {
83+ "server" : {
84+ "host" : " 127.0.0.1" ,
85+ "port" : 3333 ,
86+ "cors" : { "enabled" : true , "origins" : [" http://localhost:5173" ] }
87+ },
88+ "ui" : { "theme" : " auto" , "locale" : " en" },
89+ "projects" : { "autoDiscover" : true , "maxRecent" : 10 }
90+ }
91+ ```
10592
10693## Plan
10794
108- ### Phase 1: Analysis & Shared Components (2-3 days)
109-
110- - [ ] Audit current ` packages/ui ` features vs ` packages/desktop ` features
111- - [ ] Identify components that can be shared (SpecList, SpecDetail, Stats, Dependencies, etc.)
112- - [ ] Create ` packages/ui-shared ` package structure
113- - [ ] Extract 5-10 core components from desktop into shared package
114- - [ ] Update desktop to import from shared package (verify no regressions)
115-
116- ### Phase 2: New UI Package Setup (2-3 days)
95+ ### Timeline (4 weeks)
11796
118- - [ ] Create new ` packages/ui-vite ` directory with Vite+React setup
119- - [ ] Copy desktop's frontend structure (pages, router, hooks)
120- - [ ] Integrate ` packages/ui-shared ` components
121- - [ ] Set up data layer abstraction (interface for backend communication)
122- - [ ] Implement Rust CLI wrapper for data operations
97+ ** Week 1** : Foundations (parallel)
98+ - [ ] [ Spec 185] ( ../185-ui-components-extraction/ ) : Extract component library
99+ - [ ] [ Spec 186] ( ../186-rust-http-server/ ) : Build HTTP server
123100
124- ### Phase 3: Backend Integration (3-4 days)
101+ ** Week 2** : New UI
102+ - [ ] [ Spec 187] ( ../187-vite-spa-migration/ ) : Vite SPA using components + HTTP API
125103
126- - [ ] Design API layer: CLI spawning vs HTTP server wrapper
127- - [ ] Implement spec operations via Rust CLI (list, view, stats, search, etc.)
128- - [ ] Implement project management via Rust CLI
129- - [ ] Add caching layer for performance
130- - [ ] Test data operations match old UI functionality
104+ ** Week 3** : Integration
105+ - [ ] Desktop uses HTTP server + shared UI
106+ - [ ] Integration + performance testing
131107
132- ### Phase 4: Feature Parity (3-4 days)
108+ ** Week 4** : Launch
109+ - [ ] Archive Next.js UI (` packages/ui ` → ` packages/ui-legacy-nextjs ` )
110+ - [ ] Promote Vite SPA (` packages/ui-new ` → ` packages/ui ` )
111+ - [ ] Release v0.3.0
133112
134- - [ ] Port remaining UI features from Next.js UI:
135- - Spec detail with sub-specs
136- - Dependencies visualization (DAG + network)
137- - Project switching
138- - Search & filters
139- - Metadata editing
140- - Stats dashboard
141- - [ ] Implement missing features if any
142- - [ ] Style and UX consistency pass
113+ ### Success Criteria
143114
144- ### Phase 5: Migration & Deprecation (1-2 days)
145-
146- - [ ] Rename ` packages/ui ` → ` packages/ui-nextjs-archived `
147- - [ ] Rename ` packages/ui-vite ` → ` packages/ui `
148- - [ ] Update ` lean-spec ui ` command to use new package
149- - [ ] Update package.json scripts (` dev:web ` , etc.)
150- - [ ] Update documentation and README files
151- - [ ] Update CI/CD pipelines
152-
153- ### Phase 6: Cleanup (1 day)
154-
155- - [ ] Remove Next.js dependencies from monorepo
156- - [ ] Remove database dependencies (better-sqlite3, drizzle-orm) if no longer needed
157- - [ ] Update TypeScript paths and imports
158- - [ ] Clean up unused code
159- - [ ] Update ARCHITECTURE.md and agent instructions
115+ ** Must Have** :
116+ - [ ] All Next.js UI features in Vite SPA
117+ - [ ] Desktop uses shared UI
118+ - [ ] Bundle <30MB (vs 150MB+)
119+ - [ ] Page load <2s for 100+ specs
120+ - [ ] Multi-project on both platforms
160121
161122## Test
162123
163- ### Functional Tests
164-
165- - [ ] All spec operations work (list, view, create, update, search)
166- - [ ] Project switching works correctly
167- - [ ] Dependencies visualization renders correctly
168- - [ ] Stats page displays accurate data
169- - [ ] Sub-specs are properly displayed
170- - [ ] Metadata editing saves correctly
171- - [ ] Search returns correct results
172- - [ ] Filters and sorting work
173-
174- ### Performance Tests
175-
176- - [ ] Page load time <2s for 100+ specs
177- - [ ] Search response time <500ms
178- - [ ] Dependency graph renders <1s for 50+ specs
179- - [ ] Memory usage <200MB for typical usage
180-
181- ### Integration Tests
182-
183- - [ ] Desktop app still works with shared components
184- - [ ] ` lean-spec ui ` launches new UI correctly
185- - [ ] Multi-project switching works in both desktop and web
186- - [ ] CLI operations reflect in UI immediately
187-
188- ### Compatibility Tests
189-
190- - [ ] Works on Node.js 20+
191- - [ ] Works on Chrome, Firefox, Safari
192- - [ ] Works on macOS, Linux, Windows
193- - [ ] Existing projects load without migration
124+ ** Integration Tests** (cross-spec):
125+ - [ ] Web → HTTP server → filesystem
126+ - [ ] Desktop → HTTP server → filesystem
127+ - [ ] Project switching synchronized
128+ - [ ] Config changes apply everywhere
194129
195130## Notes
196131
197132### Why This Matters
198133
199- 1 . ** Eliminate Duplication** : One codebase to maintain instead of two
200- 2 . ** Better Performance** : SPA + Rust is faster than Next.js + TypeScript
201- 3 . ** Consistency** : Same UX between web and desktop
202- 4 . ** Faster Development ** : New features implemented once
203- 5 . ** Smaller Bundle ** : No SSR overhead ( ~ 150MB → ~ 30MB)
134+ 1 . ** Eliminate Duplication** : One codebase, not two
135+ 2 . ** 10x Performance** : Rust backend vs TypeScript
136+ 3 . ** Consistency** : Same UX everywhere
137+ 4 . ** Smaller Bundle ** : 30MB vs 150MB+
138+ 5 . ** Faster Development ** : One implementation
204139
205- ### Alternatives Considered
140+ ### Why Bold Migration?
206141
207- 1 . ** Keep both UIs** : Rejected - unsustainable maintenance burden
208- 2 . ** Migrate desktop to Next.js** : Rejected - slower, heavier, wrong direction
209- 3 . ** Use web components** : Rejected - too much refactoring, limited benefit
210- 4 . ** Micro-frontends** : Rejected - adds complexity without clear benefit
142+ AI coding era enables velocity:
143+ - AI excels at mechanical porting
144+ - Desktop migration (spec 169) proved this works
145+ - Avoid temporary bridges (no CLI spawning)
146+ - One migration, one test cycle
211147
212148### Related Specs
213149
214- - Spec 169: UI Backend Rust/Tauri Migration (desktop migration complete)
215- - Spec 170: CLI/MCP/Core Rust Migration (backend already in Rust)
216- - Spec 181: TypeScript Deprecation (core already migrated)
217-
218- ### Dependencies
219-
220- - Depends on: None (Rust backend already exists)
221- - Blocks: Future UI development should use consolidated package
150+ - [ 169] ( ../169-ui-backend-rust-tauri-migration-evaluation/ ) : Desktop migrated
151+ - [ 170] ( ../170-cli-mcp-rust-migration/ ) : CLI/MCP in Rust
152+ - [ 181] ( ../181-typescript-deprecation/ ) : TypeScript deprecation
153+ - ** [ 185] ( ../185-ui-components-extraction/ ) ** : Components (sub-spec)
154+ - ** [ 186] ( ../186-rust-http-server/ ) ** : HTTP server (sub-spec)
155+ - ** [ 187] ( ../187-vite-spa-migration/ ) ** : Vite SPA (sub-spec)
222156
223157### Open Questions
224158
225- 1 . ** API Layer** : Should we spawn CLI processes or create a lightweight HTTP server wrapper around Rust?
226- - ** Decision** : Start with CLI spawning for simplicity, evaluate HTTP wrapper if performance issues
227- 2 . ** Shared Package Name** : ` @leanspec/ui-shared ` or ` @leanspec/ui-components ` ?
228- - ** Decision** : ` @leanspec/ui-shared ` (broader scope, includes hooks/utils)
229- 3 . ** Migration Timeline** : Can we do this incrementally or all at once?
230- - ** Decision** : Incremental with new package name, then swap
231- 4 . ** Old UI Support** : How long to keep archived Next.js code?
232- - ** Decision** : Archive immediately, can recover from git if needed
159+ 1 . ** HTTP Server Distribution** : Separate npm package with platform binaries
160+ 2 . ** Hot Reload** : File watcher with ` notify-rs ` for project registry
161+ 3 . ** Spec File Changes** : Client polling initially, WebSocket upgrade later
162+ 4 . ** Web Production** : Dev-only (browser security limits)
0 commit comments