Commit a55417a
authored
π€ refactor: Reorganize src/ into 5 clear folders (cli, desktop, node, browser, common) (#622)
## Overview
Comprehensive reorganization of `src/` into **5 folders with
crystal-clear boundaries**:
```
src/
βββ cli/ # CLI entry points + debug utilities
βββ desktop/ # Electron-only code (main, preload, window manager, updater)
βββ node/ # Backend services (config, git, services/, runtime/)
βββ browser/ # React frontend (components, hooks, contexts, stores)
βββ common/ # Pure shared code (types, constants, pure utils)
```
**Net change**: ~0 LoC (pure refactor), 9 commits
---
## Architecture
### Dependency Flow
```
βββββββββββ βββββββββββ
β CLI β β Desktop β
ββββββ¬βββββ ββββββ¬βββββ
β β
ββββββ¬ββββββββββββ
β
βββββββββββΌββββββββββ
β Node β
β (services, used β
β by both CLI & β
β Desktop) β
βββββββββββ¬ββββββββββ
β
βββββββββββΌββββββββββ
β Common β
β (types, const, β
β pure utils) β
βββββββββββββββββββββ
β²
β
βββββββββββ΄ββββββββββ
β Browser β
β (React UI) β
βββββββββββββββββββββ
```
### Key Rules
1. `common/` imports: **NOTHING** (zero dependencies)
2. `node/` imports: `common/` only
3. `browser/` imports: `common/` only
4. `desktop/` imports: `common/`, `node/`
5. `cli/` imports: `common/`, `node/`
6. `node/` and `browser/` **NEVER** import each other
---
## Key Decisions
### 1. `ipcMain.ts` β `node/services/` (NOT `common/`)
- Creates services with Node dependencies (`fs`, `child_process`)
- **Platform-agnostic via dependency injection** (accepts Electron or
HTTP adapter)
- Still a **Node service** because it uses Node APIs
### 2. Only 4 files β `desktop/`
1. `main.ts` - Electron app setup
2. `preload.ts` - Preload script
3. `terminalWindowManager.ts` - Pop-out terminal windows (Electron-only)
4. `updater.ts` - Auto-updater
All other services β `node/services/` (platform-agnostic)
### 3. Debug tools β `cli/debug/`
8 CLI debugging utilities moved from `src/debug/` to `src/cli/debug/`
---
## Migration Summary
### Phase 1: Common
- Moved types/, constants/, lib/, mocks/
- Moved pure utils (arrays, assert, hasher, paths, etc.)
- Fixed nested directory structure (types/types/ β types/)
### Phase 2: Node
- Moved config.ts, git.ts
- Moved all services/ (including ipcMain - platform-agnostic)
- Moved runtime/, telemetry/, bench/
- Moved node-specific utils
### Phase 3: Browser
- Moved App.tsx, components/, contexts/, hooks/, stores/
- Moved browser-specific utils (ui/, highlighting/, messages/, etc.)
- Updated main.tsx and terminal-window.tsx entry points
### Phase 4: Desktop
- Moved main-desktop.ts β desktop/main.ts
- Moved preload.ts β desktop/preload.ts
- Moved Electron-specific services (terminalWindowManager, updater)
### Phase 5: CLI
- Moved main.ts β cli/index.ts
- Moved main-server.ts β cli/server.ts
- Moved debug/ β cli/debug/
### Phases 6-8: Imports & Config
- Fixed 200+ import statements across codebase
- Updated tsconfig.main.json, Makefile, package.json
- Updated Storybook and jest.config.js
- Fixed all relative imports and dynamic imports
- Result: Only 1 pre-existing TS1378 error (unrelated to refactor)
---
## Benefits
β
**Clear architecture** - 5 folders with obvious purposes
β
**Fast navigation** - IDE search works better
β
**Easy code review** - Violations are obvious
β
**Better onboarding** - New devs understand immediately
β
**Future-proof** - Easy to extract packages later
β
**No tooling overhead** - Single package.json
β
**Convention enforcement** - Structure guides decisions
---
## Testing
- β
Typecheck passes (only pre-existing TS7006/TS1378 errors)
- β
All imports updated
- β
Git history preserved for all moved files
- β
No circular dependencies
- β³ CI tests pending
---
_Generated with `mux`_1 parent 16fa272 commit a55417a
File tree
471 files changed
+1189
-1013
lines changed- .storybook
- src
- browser
- assets/icons
- components
- ChatInput
- Messages
- ChatBarrier
- RightSidebar
- CodeReview
- ai-elements
- hooks
- icons
- tools
- ui
- contexts
- hooks
- stores
- styles
- utils
- commands
- highlighting
- messages
- review
- slashCommands
- thinking
- tokenizer
- ui
- cli
- debug
- common
- constants
- lib
- mocks
- types
- utils
- ai
- providers
- tokens
- tools
- validation
- desktop
- node
- bench
- runtime
- services
- mock
- scenarios
- tools
- utils
- telemetry
- utils
- compaction
- concurrency
- errors
- git
- main
- runtime
- tests
- e2e
- scenarios
- utils
- ipcMain
- models
- runtime
- vscode/src
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
471 files changed
+1189
-1013
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
160 | | - | |
| 160 | + | |
161 | 161 | | |
162 | | - | |
| 162 | + | |
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
168 | 168 | | |
169 | | - | |
| 169 | + | |
170 | 170 | | |
171 | | - | |
| 171 | + | |
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
35 | | - | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| |||
335 | 335 | | |
336 | 336 | | |
337 | 337 | | |
| 338 | + | |
| 339 | + | |
338 | 340 | | |
339 | 341 | | |
340 | 342 | | |
| |||
1453 | 1455 | | |
1454 | 1456 | | |
1455 | 1457 | | |
| 1458 | + | |
| 1459 | + | |
1456 | 1460 | | |
1457 | 1461 | | |
1458 | 1462 | | |
| |||
1639 | 1643 | | |
1640 | 1644 | | |
1641 | 1645 | | |
| 1646 | + | |
| 1647 | + | |
1642 | 1648 | | |
1643 | 1649 | | |
1644 | 1650 | | |
| |||
1759 | 1765 | | |
1760 | 1766 | | |
1761 | 1767 | | |
| 1768 | + | |
| 1769 | + | |
1762 | 1770 | | |
1763 | 1771 | | |
1764 | 1772 | | |
| |||
2357 | 2365 | | |
2358 | 2366 | | |
2359 | 2367 | | |
| 2368 | + | |
| 2369 | + | |
2360 | 2370 | | |
2361 | 2371 | | |
2362 | 2372 | | |
| |||
2369 | 2379 | | |
2370 | 2380 | | |
2371 | 2381 | | |
| 2382 | + | |
| 2383 | + | |
2372 | 2384 | | |
2373 | 2385 | | |
| 2386 | + | |
| 2387 | + | |
2374 | 2388 | | |
2375 | 2389 | | |
2376 | 2390 | | |
| |||
2385 | 2399 | | |
2386 | 2400 | | |
2387 | 2401 | | |
2388 | | - | |
| 2402 | + | |
2389 | 2403 | | |
2390 | 2404 | | |
2391 | 2405 | | |
| |||
2397 | 2411 | | |
2398 | 2412 | | |
2399 | 2413 | | |
2400 | | - | |
2401 | | - | |
2402 | 2414 | | |
2403 | 2415 | | |
2404 | 2416 | | |
| |||
2535 | 2547 | | |
2536 | 2548 | | |
2537 | 2549 | | |
| 2550 | + | |
| 2551 | + | |
2538 | 2552 | | |
2539 | 2553 | | |
2540 | 2554 | | |
| |||
2587 | 2601 | | |
2588 | 2602 | | |
2589 | 2603 | | |
| 2604 | + | |
| 2605 | + | |
2590 | 2606 | | |
2591 | 2607 | | |
2592 | 2608 | | |
| |||
2759 | 2775 | | |
2760 | 2776 | | |
2761 | 2777 | | |
| 2778 | + | |
| 2779 | + | |
| 2780 | + | |
| 2781 | + | |
2762 | 2782 | | |
2763 | 2783 | | |
2764 | 2784 | | |
| |||
2867 | 2887 | | |
2868 | 2888 | | |
2869 | 2889 | | |
| 2890 | + | |
| 2891 | + | |
2870 | 2892 | | |
2871 | 2893 | | |
2872 | 2894 | | |
| |||
2917 | 2939 | | |
2918 | 2940 | | |
2919 | 2941 | | |
| 2942 | + | |
| 2943 | + | |
2920 | 2944 | | |
2921 | 2945 | | |
2922 | 2946 | | |
| |||
3435 | 3459 | | |
3436 | 3460 | | |
3437 | 3461 | | |
3438 | | - | |
3439 | | - | |
3440 | 3462 | | |
3441 | 3463 | | |
3442 | 3464 | | |
| |||
3491 | 3513 | | |
3492 | 3514 | | |
3493 | 3515 | | |
| 3516 | + | |
| 3517 | + | |
3494 | 3518 | | |
3495 | 3519 | | |
3496 | 3520 | | |
3497 | 3521 | | |
3498 | 3522 | | |
3499 | 3523 | | |
| 3524 | + | |
| 3525 | + | |
3500 | 3526 | | |
3501 | 3527 | | |
3502 | 3528 | | |
| |||
3527 | 3553 | | |
3528 | 3554 | | |
3529 | 3555 | | |
| 3556 | + | |
| 3557 | + | |
3530 | 3558 | | |
3531 | 3559 | | |
3532 | 3560 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
124 | | - | |
| 124 | + | |
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| |||
349 | 349 | | |
350 | 350 | | |
351 | 351 | | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
364 | 364 | | |
365 | 365 | | |
366 | 366 | | |
367 | 367 | | |
368 | 368 | | |
369 | 369 | | |
370 | 370 | | |
371 | | - | |
| 371 | + | |
372 | 372 | | |
373 | 373 | | |
374 | | - | |
375 | | - | |
| 374 | + | |
| 375 | + | |
376 | 376 | | |
377 | 377 | | |
378 | 378 | | |
| |||
402 | 402 | | |
403 | 403 | | |
404 | 404 | | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | | - | |
412 | | - | |
413 | | - | |
414 | | - | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
415 | 408 | | |
416 | 409 | | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
417 | 413 | | |
418 | 414 | | |
419 | 415 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
0 commit comments