How hu-ke/gemini-video-subtitle works
Main Components
• Browser Extension Shell – The project is strictly an extension. Break it into its high-level parts:
○ Background Scripts – “src/browser-extension/background”: Handles background tasks and possibly API communication.
○ Content Scripts – “src/browser-extension/content_script”: Injected into web pages to capture and process audio/video streams and manage UI overlays (e.g., InnerContainer, TitleBar).
○ UI Interfaces:
▪ Popup – “src/browser-extension/popup”: The small extension window (with components like Settings and InnerSettings) for quick interactions.
▪ Options – “src/browser-extension/options”: A dedicated configuration page (index.html, index.tsx, index.css) where users set up their Gemini API Key.
○ Shared Components and Utilities – “src/browser-extension/common” and “src/browser-extension/utils”: Contains React components, hooks (e.g., useTheme, useSettings), styles, and utility functions that support multiple parts of the extension.
• External Service:
○ Gemini API – The extension depends on a Gemini API key for transcription and translation. This external call is a key dependency.
• Build and Configuration:
Out Interactions and Relationships
• Content Script ↔ Background Script:
• Messaging channels (likely via browser.runtime or similar APIs) where content scripts (collecting audio or user actions) communicate with the background for processing.
• Background Script ↔ Gemini API:
• Popup/Options UI ↔ Background Script:
• Common Utilities & Shared Components:
• That both the content scripts and the UI components rely on shared React components (forms, hooks, error fallbacks) indicating code reuse and consistency in state and look and feel.
Architectural Patterns and Design Principles
• Separation of Concerns:
• Modularity:
• “common” folder as a shared utility hub that supports the different modules (show connectors highlighting dependency).
• Messaging and Asynchronous Communication:
• Use of browser extension messaging patterns for inter-component communication.
• External API Integration:
• External Gemini API communication, noting that it forms the critical external dependency for real-time transcription and translation.
Specific Technologies and Libraries
• TypeScript and React – The code uses .tsx files and TypeScript, implying component-based design and type safety.
• Vite – As seen in the Vite config, indicating modern bundling and fast development cycles.
• Browser Extension APIs – Implicit in the manifest and the structure (background, content script, popup, options) so include a “Browser API” component where needed.
• Gemini Multimodal – As the key external service.