graph TD
subgraph Browser["Chrome Browser"]
YT[YouTube Page]
Pop[Extension Popup]
Back[Background Service]
end
subgraph Files["Extension Files"]
direction TB
Content[content.ts]
Background[background.ts]
Popup[popup.tsx]
Services[gemini.ts]
Config[config.ts]
subgraph Components["React Components"]
Summary[SummaryView]
ApiKey[ApiKeyInput]
end
subgraph Styles["Styling"]
Fonts[fonts.css]
PopCSS[popup.css]
CompCSS[component.css]
end
end
YT --> Content
Content --> Background
Background --> Services
Services --> Background
Background --> Popup
Popup --> Components
Components --> Styles
Config --> Services
Config --> Background
Pop --> Popup
sequenceDiagram
participant YT as YouTube Page
participant CS as content.ts
participant BG as background.ts
participant GS as gemini.ts
participant UI as popup.tsx
YT->>CS: Load video page
CS->>CS: Extract transcript
CS->>BG: Send transcript
BG->>BG: Chunk text
loop For each chunk
BG->>GS: Request summary
GS->>GS: Process with AI
GS->>BG: Return summary
end
BG->>BG: Combine summaries
BG->>UI: Display results
graph TD
subgraph Global["Global Styles"]
Fonts[fonts.css]
Variables[CSS Variables]
end
subgraph Components["Component Styles"]
PopupCSS[popup.css]
SummaryCSS[SummaryView.css]
ApiKeyCSS[ApiKeyInput.css]
end
Fonts --> Variables
Variables --> PopupCSS
Variables --> SummaryCSS
Variables --> ApiKeyCSS
style Fonts fill:#f9f,stroke:#333
style Variables fill:#bbf,stroke:#333
style PopupCSS fill:#dfd,stroke:#333
style SummaryCSS fill:#dfd,stroke:#333
style ApiKeyCSS fill:#dfd,stroke:#333
This Chrome extension uses a modern architecture to summarize YouTube videos using the Gemini AI model. Here's how the different components work together:
- Purpose: Main user interface of the extension
- Functionality:
- Renders when users click the extension icon
- Manages the main app container and routing
- Imports global styles and theme
- Key Dependencies: React, Components from
/components
- Purpose: Background service worker
- Functionality:
- Runs in the background continuously
- Manages API key storage
- Handles communication between content script and popup
- Initializes Gemini service
- Manages video state and summarization process
- Purpose: Content script injected into YouTube pages
- Functionality:
- Extracts video transcripts
- Communicates with background script
- Handles video page interactions
- Manages transcript processing and chunking
- Purpose: Handles all Gemini AI interactions
- Functionality:
- Manages API authentication
- Handles model selection and fallbacks
- Processes text summarization requests
- Manages rate limiting and retries
- Purpose: Manages API key input and validation
- Files:
ApiKeyInput.tsx
: Component logicApiKeyInput.css
: Component styles
- Purpose: Main popup interface components
- Files:
SummaryView.tsx
: Summary display componentSummaryView.css
: Summary styling- Other popup-related components
- Purpose: Global typography and design system
- Defines:
- Font imports (Rubik)
- Color variables
- Spacing system
- Typography scale
- Shadow styles
- Border radius values
- Purpose: Global configuration settings
- Contains:
- AI model settings
- Default parameters
- Feature flags
-
User Interaction Flow:
YouTube Page → content.ts → background.ts → Gemini API → popup.tsx
-
Summarization Process:
content.ts (extract transcript) → background.ts (chunk management) → gemini.ts (API calls) → background.ts (result processing) → popup.tsx (display results)
-
Styling Hierarchy:
fonts.css (global design system) → popup.css (global styles) → [component].css (component-specific styles)
- Uses Gemini AI models with fallback options
- Handles rate limiting and quotas
- Manages API key securely
- Modern, responsive design
- Clear visual hierarchy
- Consistent typography with Rubik font
- Interactive elements with hover states
- Loading states and error handling
- Background processing
- Chunked transcript handling
- Efficient state management
- Caching mechanisms
-
Building:
npm run build
- Compiles TypeScript
- Bundles with webpack
- Generates dist/ directory
-
Testing:
- Load unpacked extension
- Navigate to YouTube
- Click extension icon
-
Debugging:
- Use Chrome DevTools
- Check background script console
- Monitor network requests
-
State Management
- Clear data flow
- Centralized configuration
- Type safety with TypeScript
-
Styling
- CSS variables for consistency
- Component-scoped styles
- Responsive design patterns
-
Security
- Secure API key storage
- Safe message passing
- Input validation