This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
npm run build # Build for production with TypeScript compilation
npm run build:en # Build English version specifically
npm run build:fr # Build French version specifically
npm run build:all # Build all language versionsnpm run deploy # Deploy to GitHub Pages (gh-pages -d dist)
npm run to2web # Build, release, and deploy to web
npm run mcp-proxy # Start MCP bridge service (node bin/mcp-bridge.js)
npm run serve # Build and serve with http-server on LITECHAT_PORT (default: 5173)
npm run update # Git pull, npm install, and serve (respects LITECHAT_ORIGIN and LITECHAT_BRANCH)npm run serve or start any servers - user has their own dev environment running!
# Manual build
npm run build && docker build -t litechat .
docker run -d -p 8080:3000 litechat
# Docker Compose (includes MCP bridge)
docker-compose up -dLiteChat is a 100% client-side AI chat application built with a modular, event-driven architecture designed for extensibility and privacy.
- Frontend: React 19, TypeScript, Vite, Tailwind CSS, shadcn/ui
- State Management: Zustand with Immer middleware and domain-specific stores
- Data Storage: Dexie.js (IndexedDB) with ZenFS for virtual file system
- AI Integration: Vercel AI SDK supporting multiple providers (OpenAI, Claude, Gemini, OpenRouter, local models)
- Version Control: isomorphic-git for browser-based Git operations
- Internationalization: i18next with React integration
LiteChat uses a sophisticated control module architecture with three scopes:
- PromptControls: Input area extensions and prompt manipulation
- ChatControls: Sidebar panels, headers, and general UI controls
- CanvasControls: Action buttons and interactions within chat canvas
Control Module Lifecycle:
initialize(): Setup phaseregister(modApi): Registration with mod APIdestroy(): Cleanup and resource deallocation
Key Directories:
src/controls/modules/: Control module implementationssrc/controls/components/: UI components for controlssrc/store/control.store.ts: Central control registry
All inter-system communication uses a centralized event emitter with strongly-typed events:
- Event Types: Organized in
src/types/litechat/events/by domain - Event Coordinator:
EventActionCoordinatorServiceautomatically binds store actions to events - Store Integration: Stores emit events on state changes and expose
getRegisteredActionHandlers()
Domain-specific Zustand stores with consistent patterns:
- Immer middleware: Immutable state updates
- Event integration: Automatic event emission on changes
- Action handlers: Exposed for event coordinator registration
- Type safety: Full TypeScript coverage
Key Stores:
conversation.store.ts: Chat data and statesettings.store.ts: Application configurationprovider.store.ts: AI provider managementvfs.store.ts: Virtual file system state
Extensible content rendering with priority-based selection:
- Language-specific renderers: Handle code blocks, diagrams, etc.
- Universal fallback: Default renderer with enhanced features
- Context-aware: Rich context including streaming state, file paths
- Registration:
src/services/block-renderer.service.ts
Example Renderers:
JsRunnableBlockRenderer: JavaScript execution with safe/unsafe/iframe modesMermaidBlockRenderer: Real-time diagram renderingPythonRunnableBlockRenderer: Python code execution
Browser-based filesystem using ZenFS + IndexedDB:
- Full CRUD operations: Create, read, update, delete files/directories
- Git integration: Clone, commit, push, pull repositories
- Project organization: Hierarchical project structure
- Sync capabilities: Git-based conversation synchronization
Safe, controlled extension interface:
- Resource management: Automatic cleanup on mod unload
- Sandboxed API:
createModApi()provides controlled access - Event system access: Mods can emit/listen to typed events
- Tool registration: Dynamic AI tool addition
- Build-time configuration: Custom system prompts via
VITE_SYSTEM_PROMPT_FILE - Multi-language builds: Automatic language detection and building
- Node.js polyfills: Browser compatibility for Node.js APIs
- PWA support: Service worker and offline capabilities
- 100% client-side: No server dependencies for core functionality
- Local storage: All data in browser IndexedDB
- Code execution: Multiple isolation levels (QuickJS VM, iframe sandbox, direct eval)
- CORS handling: Direct browser requests to AI providers
-
Control Registration:
export class ExampleControlModule implements ControlModule { register(modApi: LiteChatModApi): void { this.unregisterCallback = modApi.registerPromptControl({ id: "example-control", component: ExampleComponent, }); } }
-
Event Handling:
// Store exposes action handlers getRegisteredActionHandlers(): ActionHandler[] { return [ { type: 'EXAMPLE_EVENT', handler: this.handleExample } ]; }
-
Block Renderer:
const renderer: BlockRenderer = { id: "example-renderer", supportedLanguages: ["example"], priority: 10, renderer: (context) => <ExampleComponent {...context} />, };
src/components/LiteChat/: Core UI componentssrc/controls/: Control modules and componentssrc/services/: Business logic servicessrc/store/: State managementsrc/types/litechat/: TypeScript definitionssrc/lib/litechat/: Utility functionssrc/locales/: Internationalization filesdocs/: Comprehensive documentation
- Type Safety: Leverage TypeScript throughout - all events, stores, and APIs are fully typed
- Event-First: Use events for cross-system communication rather than direct imports
- Module Pattern: Follow control module lifecycle for proper resource management
- Linting: ESLint with TypeScript rules enforced (note:
@typescript-eslint/no-explicit-anyis disabled) - npm run build every time you are done with building functionalities ! when you release to user, the app must build !
When creating new functionality:
- Control Modules: For UI extensions, create control modules following the established patterns
- Block Renderers: For custom content types, implement block renderers with proper language detection
- Services: For business logic, create services with event integration
- Stores: For state management, use Zustand with the established patterns
The architecture prioritizes modularity, type safety, and extensibility while maintaining a clean separation of concerns throughout the system.