V5 Frontend Build Strategy
Date: 2025-10-08 Status: ✅ STRATEGIC PIVOT - LEVERAGE THEIA, NOT REBUILD
🎯 Strategic Decision
OLD APPROACH (Before Today):
- Build custom React components for everything
- Custom chat UI (~2,000 lines)
- Custom Monaco editor wrapper
- Custom terminal component
- Custom file explorer
- Custom llm service
- Timeline: 3-4 weeks
- Code: ~15,000 lines
- Risk: High (untested, unmaintained)
NEW APPROACH (theia-Based):
- Wrap theia's production-ready widgets
- Use ChatViewWidget (AI chat with MCP)
- Use theia's Monaco integration
- Use theia's terminal widget
- Use theia's file explorer
- Use theia's AI core services
- Timeline: 1-2 weeks
- Code: ~2,000 lines (wrappers only)
- Risk: Low (battle-tested by Gitpod, Google)
Decision: Use theia AI framework as foundation, add mobile-first wrapper layer.
📊 What We Learned Today
Key Discovery #1: theia Has Complete AI System
Eclipse theia 1.65 includes:
- ✅ ChatViewWidget - Complete AI chat UI
- ✅ Agent system - Custom agents with prompts
- ✅ MCP protocol - Tool calling standard
- ✅ Multi-llm support - OpenAI, Anthropic, Ollama, LM Studio
- ✅ Context management - File/code attachment
- ✅ Prompt templates - User customization
- ✅ Code completion - AI IntelliSense
- ✅ Full transparency - See all llm communication
Implication: We don't need to build ANY of this. We wrap it.
Key Discovery #2: LM Studio Works Out-of-Box
theia's @theia/ai-openai supports OpenAI-compatible APIs.
LM Studio IS OpenAI-compatible.
Configuration (That's it!):
{
"ai.openai.api.baseUrl": "http://localhost:1234/v1",
"ai.openai.models": [
"meta-llama-3.3-70b-instruct",
"qwen/qwq-32b",
"deepseek-coder-v2"
]
}
Implication: Our 16+ LM Studio models work immediately. Zero custom code.
Key Discovery #3: MCP is Built-In
theia AI fully supports Anthropic's Model Context Protocol.
We can register our MCP server:
{
"servers": {
"lmstudio": {
"command": "node",
"args": ["mcp-lmstudio/index.js"]
}
}
}
Implication: Our mcp-lmstudio/index.js server integrates natively.
Key Discovery #4: Inversify DI is Bridgeable
theia uses Inversify DI container. React uses props/hooks.
Bridge Pattern:
// Get widget from theia container
const widget = theiaContainer.get(ChatViewWidget)
// Mount in React
<div ref={(el) => el?.appendChild(widget.node)} />
Implication: We can extract and wrap ANY theia widget in React.
🏗️ Revised Architecture
┌─────────────────────────────────────────────────────┐
│ V5 React Wrapper (5% custom code) │
│ ────────────────────────────────────────── │
│ • Header/Footer (Chakra UI) │
│ • TouchFriendlyCard (mobile-first) │
│ • Tab routing (AI Studio / workspace / IDE) │
│ • Session management (JWT, FDB) │
└──────────────────┬──────────────────────────────────┘
│
↓ React-theia Bridge
┌─────────────────────────────────────────────────────┐
│ theia Widget Wrappers (thin React components) │
│ ────────────────────────────────────────── │
│ • theiaChatWidget → ChatViewWidget │
│ • theiaterminalWidget → terminalWidget │
│ • theiaMonacoWidget → Monacoeditor │
│ • theiafile-explorerWidget → FileTreeWidget │
└──────────────────┬──────────────────────────────────┘
│
↓ Inversify DI
┌─────────────────────────────────────────────────────┐
│ Eclipse theia 1.65 (95% of functionality) │
│ ────────────────────────────────────────── │
│ • Complete AI system (chat, agents, MCP) │
│ • Monaco editor (VS Code quality) │
│ • terminal (xterm.js) │
│ • File explorer (drag-drop, context menu) │
│ • Multi-llm support (including LM Studio) │
└──────────────────┬──────────────────────────────────┘
│
↓
┌─────────────────────────────────────────────────────┐
│ V5 Backend (Rust + FoundationDB) │
│ • JWT auth, sessions, file operations │
└─────────────────────────────────────────────────────┘
🗂️ Folder Structure (Updated)
src/
├── services/
│ ├── theia-container.ts # NEW: theia DI bridge
│ ├── llm-service.ts # DELETE: Use theia's ChatService
│ ├── session-service.ts # KEEP: V5 backend integration
│ ├── user-service.ts # KEEP: V5 backend integration
│ └── file-service.ts # KEEP: V5 backend integration
│
├── components/
│ ├── theia/ # NEW: theia widget wrappers
│ │ ├── theia-chat-widget.tsx # Wraps ChatViewWidget
│ │ ├── theia-terminal-widget.tsx # Wraps terminalWidget
│ │ ├── theia-monaco-widget.tsx # Wraps Monacoeditor
│ │ └── theia-file-explorer-widget.tsx # Wraps FileTreeWidget
│ │
│ ├── ai-studio/
│ │ ├── ai-studio-tab.tsx # UPDATE: Use theiaChatWidget
│ │ └── CodePreview.tsx # KEEP: Custom component
│ │
│ ├── workspace/
│ │ ├── workspace-tab.tsx # UPDATE: Use theia components
│ │ ├── file-explorer.tsx # DELETE: Use theiafile-explorerWidget
│ │ ├── Monacoeditor.tsx # DELETE: Use theiaMonacoWidget
│ │ └── terminal.tsx # DELETE: Use theiaterminalWidget
│ │
│ ├── touch-friendly-card.tsx # KEEP: Mobile-first wrapper
│ ├── header.tsx # KEEP: V5 branding
│ ├── footer.tsx # KEEP: V5 branding
│ ├── layout.tsx # UPDATE: Use theia widgets
│ └── theia-embed.tsx # KEEP: Full theia iframe
│
└── browser/ # NEW: theia extensions
└── ai-agents/
└── custom-agents-module.ts # Register V5 agents
🔨 Implementation Plan (Revised)
Phase 1: theia-React Bridge (1 day)
Goal: Enable React to use theia widgets
// src/services/theia-container.ts
import { Container } from '@theia/core/shared/inversify'
class theiaContainerService {
private container: Container | null = null
setContainer(container: Container) {
this.container = container
}
getWidget<T>(identifier: any): T {
return this.container!.get<T>(identifier)
}
}
export const theiaContainer = new theiaContainerService()
Tasks:
- Create
theia-container.ts - Initialize container in
app.tsx - Test widget retrieval
Deliverable: Working DI bridge
Phase 2: Wrap theia Widgets (2 days)
Goal: Create React wrappers for theia components
2.1 theiaChatWidget (Priority 1)
export const theiaChatWidget = ({ sessionId }) => {
const ref = useRef()
useEffect(() => {
const widget = theiaContainer.get(ChatViewWidget)
ref.current.appendChild(widget.node)
return () => widget.dispose()
}, [sessionId])
return <div ref={ref} style={{ height: '100%' }} />
}
2.2 theiaterminalWidget
export const theiaterminalWidget = ({ sessionId }) => {
// Same pattern
}
2.3 theiaMonacoWidget
export const theiaMonacoWidget = ({ file }) => {
// Same pattern
}
2.4 theiafile-explorerWidget
export const theiafile-explorerWidget = ({ sessionId }) => {
// Same pattern
}
Tasks:
- Create
theia-chat-widget.tsx - Create
theia-terminal-widget.tsx - Create
theia-monaco-widget.tsx - Create
theia-file-explorer-widget.tsx - Test each widget in isolation
Deliverable: 4 working wrapper components
Phase 3: Integrate into V5 UI (2 days)
Goal: Replace custom components with theia widgets
3.1 AI Studio Tab
// BEFORE
<Split>
<ChatInterface models={models} /> {/* Custom - 800 lines */}
<CodePreview />
</Split>
// AFTER
<Split>
<theiaChatWidget sessionId={tabId} /> {/* theia wrapper - 50 lines */}
<CodePreview />
</Split>
3.2 workspace Tab
// BEFORE
<Flex>
<file-explorer /> {/* Custom - 400 lines */}
<Monacoeditor /> {/* Custom - 300 lines */}
<terminal /> {/* Custom - 200 lines */}
</Flex>
// AFTER
<Flex>
<theiafile-explorerWidget /> {/* Wrapper - 50 lines */}
<theiaMonacoWidget /> {/* Wrapper - 50 lines */}
<theiaterminalWidget /> {/* Wrapper - 50 lines */}
</Flex>
3.3 Mobile-First Wrappers
<TouchFriendlyCard title="AI Chat" icon={FiMessageSquare}>
<Box h={{ base: '300px', md: '100%' }}>
<theiaChatWidget />
</Box>
</TouchFriendlyCard>
Tasks:
- Update
ai-studio-tab.tsx - Update
workspace-tab.tsx - Add mobile wrappers
- Delete old custom components
- Test responsive layout (320px to 4K)
Deliverable: Fully integrated theia widgets in V5 UI
Phase 4: Configure LM Studio (1 day)
Goal: Connect theia AI to LM Studio
4.1 theia Settings
// .theia/settings.json
{
"ai.openai.api.baseUrl": "http://localhost:1234/v1",
"ai.openai.api.key": "not-needed",
"ai.openai.models": [
"meta-llama-3.3-70b-instruct",
"qwen/qwq-32b",
"deepseek-coder-v2",
// ... all 16+ models
]
}
4.2 MCP Server Registration
// .theia/mcp-servers.json
{
"servers": {
"lmstudio": {
"command": "node",
"args": ["${workspaceFolder}/mcp-lmstudio/index.js"]
}
}
}
Tasks:
- Create
.theia/settings.json - Configure LM Studio as OpenAI provider
- Register MCP server
- Test chat with LM Studio models
- Verify MCP tool calls work
Deliverable: Working LM Studio integration
Phase 5: Register Custom Agents (1 day)
Goal: Define V5-specific AI agents
// src/browser/ai-agents/custom-agents-module.ts
import { Agent } from '@theia/ai-core'
const v5Agents: Agent[] = [
{
id: 'v5-code-generator',
name: 'Code Generator',
description: 'Generates production-ready TypeScript code',
model: 'meta-llama-3.3-70b-instruct',
prompt: `You are an expert TypeScript engineer.
Generate clean, well-documented, production-ready code.
Follow mobile-first design principles (56px touch targets).
Use Chakra UI for styling.
Write tests for all code.`,
},
{
id: 'v5-ui-designer',
name: 'UI Designer',
description: 'Designs mobile-first UIs with Chakra UI',
model: 'qwen/qwq-32b',
prompt: `You are a mobile-first UI/UX designer.
Create touch-friendly interfaces (56px targets).
Use TouchFriendlyCard for navigation.
Follow WCAG AAA accessibility standards.
Design for 320px to 4K displays.`,
},
{
id: 'v5-code-reviewer',
name: 'Code Reviewer',
description: 'Reviews code for quality, security, performance',
model: 'deepseek-coder-v2',
prompt: `You are a senior code reviewer.
Check for security vulnerabilities.
Suggest performance optimizations.
Enforce mobile-first patterns.
Verify accessibility compliance.`,
},
]
Tasks:
- Create
custom-agents-module.ts - Define 3 agents (Generator, Designer, Reviewer)
- Register agents with theia
- Test agent switching in chat
- Verify prompts work correctly
Deliverable: Custom V5 agents available in chat
Phase 6: E2E Testing (1 day)
Test Cases:
- AI Studio: Chat with LM Studio models
- AI Studio: Agent switching (3 agents)
- AI Studio: Context attachment (files)
- AI Studio: MCP tool calls
- workspace: File explorer navigation
- workspace: Monaco editor editing
- workspace: terminal commands
- Mobile: 320px viewport (all features)
- Desktop: 1920px viewport (all features)
- Session: Multi-session isolation
Deliverable: Fully tested V5 frontend
📈 Timeline Comparison
| Phase | Custom Build | theia-Based Build | Savings |
|---|---|---|---|
| Setup | 2 days | 1 day | 1 day |
| Chat UI | 5 days | 0.5 days (wrapper) | 4.5 days |
| editor | 3 days | 0.5 days (wrapper) | 2.5 days |
| terminal | 2 days | 0.5 days (wrapper) | 1.5 days |
| File Explorer | 3 days | 0.5 days (wrapper) | 2.5 days |
| llm Integration | 3 days | 1 day (config) | 2 days |
| Agent System | 4 days | 1 day (register) | 3 days |
| Testing | 2 days | 1 day | 1 day |
| TOTAL | 24 days | 7 days | 17 days |
Time Savings: 71% faster (3.5 weeks → 1 week)
💰 Code Comparison
| Component | Custom Build | theia-Based Build | Savings |
|---|---|---|---|
| Chat UI | ~2,000 lines | ~50 lines (wrapper) | 97.5% |
| editor | ~800 lines | ~50 lines (wrapper) | 93.75% |
| terminal | ~600 lines | ~50 lines (wrapper) | 91.67% |
| File Explorer | ~1,200 lines | ~50 lines (wrapper) | 95.83% |
| llm Service | ~1,500 lines | ~100 lines (config) | 93.33% |
| Agent System | ~2,000 lines | ~200 lines (agents) | 90% |
| TOTAL | ~8,100 lines | ~500 lines | 93.83% |
Code Reduction: 94% less custom code to maintain
✅ Success Criteria
Week 1 Deliverables
- theia-React bridge working
- theiaChatWidget created
- AI Studio tab using theiaChatWidget
- Chat connected to LM Studio
- Mobile responsive (320px tested)
Week 2 Deliverables
- All 4 wrapper components created
- workspace tab using theia components
- Custom agents registered
- MCP server integrated
- E2E tests passing
Production Ready
- All tab modalities working
- Multi-session isolation verified
- V5 backend integration complete
- Mobile-first design validated
- Documentation complete
🎉 Final Architecture
V5 = theia AI + Mobile-First Wrapper + Multi-Tenant Backend
What theia Provides (95%)
- ✅ Complete AI chat system
- ✅ Multi-llm support (16+ models via LM Studio)
- ✅ MCP protocol integration
- ✅ Agent system
- ✅ Monaco editor
- ✅ terminal
- ✅ File explorer
- ✅ Code completion
- ✅ Debugging
- ✅ Git integration
What V5 Adds (5%)
- 🆕 Mobile-first responsive UI (TouchFriendlyCard)
- 🆕 Three tab modalities (AI Studio / workspace / theia IDE)
- 🆕 Multi-tenant session routing
- 🆕 V5 backend integration (JWT, FoundationDB)
- 🆕 Custom branding (Header/Footer)
- 🆕 Progressive disclosure navigation
Result: Enterprise-grade AI IDE in 1-2 weeks, not 3-4 months.
📚 Documentation Created Today
- theia-component-reuse-strategy.md - Why wrap, not rebuild
- V5-THEIA-WRAPPER-architecture.md - How to wrap theia widgets
- theia-ai-research-findings.md - What theia AI provides
- v5-frontend-build-strategy.md - This document
Total Documentation: ~40,000 words of strategic planning
🚀 Next Steps
-
Delete custom components we don't need:
rm src/components/workspace/terminal.tsx
rm src/components/workspace/Monacoeditor.tsx
rm src/components/workspace/file-explorer.tsx
rm src/services/llm-service.ts # Use theia's ChatService -
Create theia bridge:
touch src/services/theia-container.ts -
Start wrapping widgets:
mkdir src/components/theia
touch src/components/theia/theia-chat-widget.tsx -
Configure LM Studio:
mkdir .theia
touch .theia/settings.json
touch .theia/mcp-servers.json
✅ Conclusion
Strategic Pivot: From custom build to theia-based build.
Key Decision: Wrap theia's production-ready widgets in mobile-first React components.
Timeline: 1-2 weeks instead of 3-4 weeks.
Code: ~500 lines instead of ~8,100 lines.
Quality: Production-tested (Gitpod, Google Cloud Shell) instead of unproven custom code.
Maintenance: theia team maintains core, we maintain thin wrapper.
Result: Professional AI IDE with minimal development time and code.
Status: ✅ APPROVED STRATEGY - PROCEED WITH PHASE 1 (THEIA-REACT BRIDGE)
Document Version: 1.0.0 Date: 2025-10-08 Author: V5 Development Team