13 / 20Architecture CritiqueSeverity: HIGH

main.tsx is 4,684 lines. That's a god object.

Monolithic architecture with significant tech debt. main.tsx serves as entry point AND orchestration — CLI parsing, init, feature flags, MCP config, session management, tool orchestration, command handlers. 187 imports in the first 210 lines. 61 feature() calls.

4,684
Lines in main.tsx
187
Imports in first 210 lines
61
feature() calls
2,800+
Lines in main action handler

Critical Issues — Verified Against Source

!
Top-Level Side Effects (lines 12-20)
profileCheckpoint(), startMdmRawRead(), startKeychainPrefetch() execute during module evaluation. Makes module untestable, creates hidden dependencies.
!
God Object
CLI parsing + business logic + infrastructure + presentation + configuration in one file. Violates SRP, Open/Closed, Dependency Inversion.
!
Deeply Nested Action Handlers
Main action handler: 2,800+ lines with deeply nested conditionals. Impossible to test individual branches.
Global Mutable State
bootstrap/state.ts: 150+ fields in a global singleton. No clear ownership. Mutable state scattered across modules.
Feature Flag Sprawl
61 feature() calls in main.tsx alone. No centralized management. Code paths difficult to trace.
Scattered Initialization
Setup across main.tsx (4,684), setup.ts (477, 9 params), init.ts, QueryEngine.ts (1,295). No clear sequence.

SOLID Scorecard

PrincipleStatusEvidence
Single Responsibilitymain.tsx has 6+ responsibilities
Open/ClosedGod object knows everything
Dependency Inversion187 concrete imports
Separation of ConcernsCLI + logic + infra + UI mixed
TestabilitySide effects block unit tests
Modularity⚠️Good tool system, poor boundaries

What's Good

  • Strong TypeScript types — well-defined interfaces (Tool.ts, Task.ts)
  • Modular tool system — clean 30-method interface, builder pattern
  • Memoization — getCommands(), getSystemContext(), getUserContext()
  • Separated query logic — QueryEngine.ts and query.ts encapsulate the loop