Overview
T3 Code is a minimal web GUI for code agents, built with a focus on performance, reliability, and maintainability. The system is designed around a WebSocket-based client-server architecture with provider abstraction.Core Principles
Performance First
Optimized for low latency and high throughput in event streaming
Reliability First
Predictable behavior under load, failures, and reconnections
Maintainability
Long-term code health through shared logic and clear boundaries
Correctness
Robust over convenient when tradeoffs are required
System Architecture
Package Architecture
/apps/server - WebSocket Server
Purpose: Node.js backend that orchestrates provider sessions and streams events to clients.
Key Responsibilities:
- Wraps Codex app-server (JSON-RPC over stdio)
- Manages WebSocket connections and protocol
- Orchestrates provider sessions and lifecycle
- Persists events and projections in SQLite
- Serves built web app as static files (production)
/apps/web - React UI
Purpose: React + Vite frontend for session control, conversation, and event rendering.
Key Responsibilities:
- Session UX and conversation rendering
- WebSocket client and transport layer
- Client-side state management (Zustand)
- Terminal emulation (xterm.js)
- Real-time diff visualization
wsTransport.ts
/apps/desktop - Electron Shell
Purpose: Native desktop wrapper with auto-updates and system integration.
Key Responsibilities:
- Spawns desktop-scoped
t3backend process - Loads shared web app in Electron renderer
- Auto-update support (electron-updater)
- Native system integration (menus, dialogs)
/packages/contracts - Shared Schemas
Purpose: Effect/Schema definitions and TypeScript contracts for all protocol messages.
Key Responsibilities:
- Provider event schemas
- WebSocket protocol messages
- Model and session types
- Schema validation and encoding
Keep this package schema-only — no runtime logic!
/packages/shared - Runtime Utilities
Purpose: Shared runtime utilities for both server and web.
Key Responsibilities:
- Model parsing and validation
- Network utilities
- Git helpers
- Shared business logic
Data Flow
User Message Flow
Event Sourcing
The server uses event sourcing for session state:- Full audit trail
- Session replay capability
- Temporal debugging
- Eventual consistency
Codex App Server Integration
T3 Code is Codex-first and wraps the Codex app-server:JSON-RPC Protocol
Communication happens over stdio using JSON-RPC:Key Integration Points
| Module | Responsibility | Location |
|---|---|---|
| Session lifecycle | Start, resume, stop sessions | codexAppServerManager.ts:39 |
| Turn management | Send messages, handle turns | codexAppServerManager.ts:156 |
| Event ingestion | Stream provider events | providerManager.ts:84 |
| NativeApi routing | Route NativeApi calls | wsServer.ts:203 |
| Domain projection | Project to orchestration events | Server-side |
Read the Codex App Server docs for protocol details.
Performance Considerations
WebSocket Optimization
- Binary Protocol: Consider MessagePack for reduced overhead
- Backpressure: Handle slow clients with buffering
- Batching: Batch rapid events for UI efficiency
State Management
- Selective Subscriptions: Only subscribe to needed data
- Memoization: Use React.memo and useMemo aggressively
- Virtual Scrolling: Render large lists efficiently (@tanstack/react-virtual)
Build Optimization
- Code Splitting: Vite automatically splits routes
- Tree Shaking: Import only what you need
- Effect Optimization: Effect-TS enables zero-cost abstractions
Reliability Patterns
Session Recovery
Sessions survive disconnections and restarts:Error Handling
Robust error boundaries at each layer:Graceful Degradation
- Offline Mode: Queue messages when disconnected
- Partial Renders: Show what’s available during streams
- Fallback UI: Graceful error states
Reference Implementations
For implementation guidance, reference:Codex (Official)
Open-source Codex repository
Codex Monitor
Tauri-based reference implementation
Next Steps
Monorepo Structure
Explore the workspace layout
Testing
Learn testing patterns
