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
1
User Input
User types message in React composer component
2
WebSocket Send
Web app sends
SendUserMessage via WebSocket3
Provider Dispatch
Server dispatches to Codex app-server via JSON-RPC
4
Event Stream
Codex streams provider events back over stdio
5
Event Projection
Server projects events into orchestration domain events
6
WebSocket Push
Server pushes orchestration events to web via WebSocket
7
UI Update
React components render streaming response
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
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
