Two Modes, Same Code
VAssist runs in two distinct modes that share 95% of the same code:Demo Mode (Standalone Web App)
Characteristics:- Lives at the demo URL as a standard React app
- Makes direct API calls to AI services
- Hot reload for fast development
- Perfect for quickly testing features
- Simpler architecture without extension constraints
- Feature development and testing
- UI/UX experimentation
- Quick demos and prototypes
Extension Mode (Chrome Extension)
Characteristics:- Injects into any website as a Chrome extension
- Uses message passing between isolated contexts
- Shadow DOM for complete CSS isolation
- Multi-tab support with per-tab state management
- Manifest V3 architecture
- Production usage on any website
- Multi-tab scenarios
- Privacy-focused local AI processing
- Integration with host page content
Code Sharing Strategy
Shared Components (95%)
These directories contain code that works identically in both modes:Components in
src/components/ automatically work in both demo and extension modes without modification.Mode-Specific Code (5%)
Demo Mode: Direct API Calls
Extension Mode: Message Passing
Smart Proxies
Proxies insrc/services/proxies/ automatically detect the environment and route calls:
- Detects if running in extension context (
chrome.runtimeexists) - Routes to background service worker (extension mode)
- Or routes to direct service implementation (demo mode)
Project Structure
Main Source (src/)
Extension-Specific (extension/)
Static Assets (public/)
Key Technologies
Frontend Framework
- React 19 - UI components and state management
- Tailwind CSS 4 - Styling with Shadow DOM support
- Vite (Rolldown) - Lightning-fast build tool
3D Graphics
- Babylon.js 8 - WebGL rendering engine
- babylon-mmd - MMD model and animation support
- Havok Physics - Physics simulation
AI & Processing
- OpenAI SDK - GPT and TTS API integration
- Transformers.js - On-device AI (Kokoro TTS)
- Chrome AI APIs - Built-in browser AI features
Data Storage
- Dexie.js - IndexedDB wrapper for large data
- chrome.storage - Extension storage API
- localStorage - Simple key-value storage
Architecture Principles
1. Maximum Code Reuse
95% code sharing between modes means:- Features work everywhere by default
- Single codebase to maintain
- Consistent behavior across modes
2. Context Isolation
Extension mode uses multiple isolated contexts:- Main World: React app with full DOM access
- Content Script: Isolated bridge between worlds
- Background Worker: Persistent service handler
- Offscreen Document: Heavy processing with AudioContext
3. Message-Based Communication
All inter-context communication uses structured messages:4. Per-Tab State Management
Each browser tab gets isolated state:- Independent chat histories
- Separate AI sessions
- Isolated abort controllers
- Automatic cleanup on tab close
5. Progressive Enhancement
- Works with minimal permissions
- Gracefully degrades without APIs
- Optional features (TTS, STT, Chrome AI)
- Fallback to basic functionality
Performance Considerations
Code Splitting
- Heavy dependencies loaded on-demand
- Separate bundles for demo vs extension
- Web Workers for parallel processing
Memory Management
- Per-tab resource cleanup
- Automatic inactive tab cleanup (1 hour)
- Model caching in IndexedDB
- Explicit abort controller cleanup
Build Optimization
- Vite (Rolldown) for fast builds
- Tree-shaking unused code
- Minification and compression
- Source maps for debugging
Next Steps
- Extension Architecture - Deep dive into extension mode
- Contributing Guide - Start contributing to VAssist
- AI Toolbar - Explore VAssist capabilities