|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Development Commands |
| 6 | + |
| 7 | +### Install dependencies |
| 8 | +```bash |
| 9 | +npm install |
| 10 | +``` |
| 11 | + |
| 12 | +### Run development server |
| 13 | +```bash |
| 14 | +npm run dev # Run Electron app in dev mode |
| 15 | +npm run dev:web # Run web-only version |
| 16 | +``` |
| 17 | + |
| 18 | +### Build commands |
| 19 | +```bash |
| 20 | +npm run build:win # Build for Windows |
| 21 | +npm run build:mac # Build for macOS |
| 22 | +npm run build:linux # Build for Linux |
| 23 | +npm run build:web # Build web version |
| 24 | +``` |
| 25 | + |
| 26 | +### Code quality |
| 27 | +```bash |
| 28 | +npm run lint # Run ESLint |
| 29 | +npm run lint:fix # Run ESLint with auto-fix |
| 30 | +npm run typecheck # Run TypeScript type checking (both node and web) |
| 31 | +npm run format # Format code with Prettier |
| 32 | +``` |
| 33 | + |
| 34 | +### Translation extraction |
| 35 | +```bash |
| 36 | +npm run extract-translations # Extract i18n strings |
| 37 | +``` |
| 38 | + |
| 39 | +## Architecture Overview |
| 40 | + |
| 41 | +This is an Electron + React application for an AI VTuber system with Live2D integration. The architecture consists of: |
| 42 | + |
| 43 | +### Main Process (`src/main/`) |
| 44 | +- **index.ts**: Entry point, sets up IPC handlers for window management, mouse events, and screen capture |
| 45 | +- **window-manager.ts**: Manages window state, modes (window/pet), and window properties |
| 46 | +- **menu-manager.ts**: Handles system tray and context menus |
| 47 | + |
| 48 | +### Renderer Process (`src/renderer/src/`) |
| 49 | +- **App.tsx**: Root component that sets up providers and renders the main layout |
| 50 | +- **Two display modes**: |
| 51 | + - **Window mode**: Full UI with sidebar, footer, and Live2D canvas |
| 52 | + - **Pet mode**: Minimal overlay with just Live2D and input subtitle |
| 53 | + |
| 54 | +### Core Services |
| 55 | +- **WebSocket Handler** (`services/websocket-handler.tsx`): Central communication hub that: |
| 56 | + - Manages WebSocket connection to backend server |
| 57 | + - Handles incoming messages (audio, control, model updates, chat history) |
| 58 | + - Coordinates state updates across multiple contexts |
| 59 | + - Manages audio playback queue |
| 60 | + |
| 61 | +### Context Providers (State Management) |
| 62 | +The app uses React Context for state management with multiple specialized contexts: |
| 63 | +- **AiStateContext**: AI conversation state (idle, thinking, speaking, listening) |
| 64 | +- **Live2DConfigContext**: Live2D model configuration and loading |
| 65 | +- **ChatHistoryContext**: Conversation history and messages |
| 66 | +- **VADContext**: Voice Activity Detection for microphone control |
| 67 | +- **WebSocketContext**: WebSocket connection state and messaging |
| 68 | +- **SubtitleContext**: Subtitle display management |
| 69 | +- **GroupContext**: Multi-user group session management |
| 70 | + |
| 71 | +### Live2D Integration |
| 72 | +- Uses Cubism SDK (WebSDK folder) for Live2D model rendering |
| 73 | +- **live2d.tsx**: Main Live2D component handling model loading, animation, and lip sync |
| 74 | +- Supports model switching, expressions, and motion playback |
| 75 | +- Audio-driven lip sync with volume-based animation |
| 76 | + |
| 77 | +### Key Features |
| 78 | +- Real-time voice interaction with VAD (Voice Activity Detection) |
| 79 | +- WebSocket-based communication with backend AI server |
| 80 | +- Live2D character animation with expressions and lip sync |
| 81 | +- Multi-language support (i18n) |
| 82 | +- Group/collaborative sessions |
| 83 | +- Screen capture support |
| 84 | +- Customizable backgrounds and UI themes |
| 85 | + |
| 86 | +## Important Notes |
| 87 | +- The app requires a backend server connection (WebSocket) for AI functionality |
| 88 | +- Live2D models are loaded from URLs provided by the backend |
| 89 | +- Audio is streamed as base64-encoded data with volume arrays for lip sync |
| 90 | +- The app uses Chakra UI v3 for the component library |
| 91 | +- ESLint is configured with relaxed rules (many checks disabled in .eslintrc.js) |
0 commit comments