# ashumishrag/leetcode-whisper-chrome-extension architecture

> Architecture diagram of the GitHub repository ashumishrag/leetcode-whisper-chrome-extension, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ashumishrag/leetcode-whisper-chrome-extension
- Repository: https://github.com/ashumishrag/leetcode-whisper-chrome-extension

## Overview

##### Main Components
- UI Layer (Frontend):
- Components: src/App.tsx, src/components (with further subdirectories for general UI components and specific implementations in files such as Show.tsx).
- Browser Extension Specifics:
- Manifest and static assets: manifest.json, index.html.
- Background scripts: src/background.js.
- Content scripts: src/content.tsx and src/content/* (providing interactions with web pages).
- Modals:
- Contains various modal implementations (in src/modals and its subdirectories) and a BaseModal component as a common parent.
- Utility Modules and Services:
- Hooks: Custom hooks like useChromeStorage and useIndexDB.
- Services: The ModalService (src/services/ModalService.ts) that likely handles modal state and interactions.
- Libraries: Utility files and abstractions in src/lib, constants in src/constants, interfaces in src/interface, and schema definitions in src/schema.
- Providers:
- For theming (src/providers/theme.tsx) and potentially other app-level contexts.

##### Relationships and Interactions Between Components
- The UI layer (React components) is the primary interface, possibly for both the browser extension’s popup or options page.
- Modals are a significant part of the UI; they use a base modal component to provide different interactions (for different AI versions, for instance, as seen in the modal file names).
- Background.js plays a key role in managing background logic, while content.tsx scripts interact with active web pages.
- Hooks like useChromeStorage and useIndexDB provide state management and persistent storage capabilities that are used across components and services.
- The ModalService likely orchestrates the display and interaction behavior of the modals, interfacing between the UI and possibly stored data.
- Providers (e.g., the theme provider) wrap the application to maintain consistent state across components.
- External tools and libraries include Vite (build tool), TypeScript for type safety, Tailwind CSS (tailwind.config.ts), PostCSS (postcss.config.js), and ESLint configurations (as per README guidelines for type-aware linting).

##### Architectural Patterns and Design Principles
- Modular Architecture: The separation into directories (components, modals, hooks, services, providers) indicates a well-modularized structure.
- Separation of Concerns: There is a clear split between UI rendering, state management, business logic (services), and data persistence/utilities.
- Browser Extension Pattern: Specific components for background scripts and content scripts ensure the extension's functionality is appropriately segregated.
- Component-based UI: React’s component structure is evident, with shared UI patterns in src/components/ui.

##### Elements
- Each Main Component:
- UI Components (App, various UI elements in src/components and modals)
- Browser extension components (manifest.json, background.js, content scripts)
- Service Layer (ModalService)
- Utility modules (hooks, libraries, constants, schema, interfaces)
- Providers (e.g., theme provider)
- How the UI interacts with modals and how modals escalate events to ModalService.
- Use clear labels (e.g., “UI Layer”, “Extension Background”, “Content Script”, “Modal System”, “Utilities”, “Services”).
- Dependencies & Integration:
- Integrations with external tools like Vite (build process), Tailwind CSS (styling), TypeScript (type-checking), and ESLint (code quality).

- Component Hierarchy: App, individual UI components, and modals.
- State Management: Providers and hooks.
- Services: ModalService connecting to modals.
- For example, “User Interaction → UI Components → ModalService → Modal Display”.
- And “Content Script ↔ Background Script” for extension messaging.
- Annotations where necessary to note configuration files (like tsconfig.json, vite.config.ts) that affect build/deployment processes.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Interaction"
        User["User"]:::user
    end

    subgraph "UI Layer"
        A["App Component"]:::ui
        UIC["General UI Components"]:::ui
        S["Styling & Assets"]:::ui
        P["Theme Provider"]:::provider
        H["Hooks"]:::hooks
        MS["Modal Service"]:::service
        M["Modal System"]:::modal
        U["Utility Libraries & Constants"]:::utility
    end

    subgraph "Browser Extension"
        MANIFEST["Manifest.json"]:::extension
        BG["Background Script"]:::extension
        CS["Content Scripts"]:::extension
    end

    %% User Interaction with UI
    User -->|"interacts"| A
    A -->|"renders"| UIC
    A -->|"applies"| S
    P -->|"wraps"| A
    A -->|"utilizes"| H
    H -->|"leverages"| U
    UIC -->|"triggers"| MS
    MS -->|"displays"| M

    %% Extension Components Relationships
    MANIFEST -->|"configures"| BG
    MANIFEST -->|"defines"| CS
    CS <-->|"communicates"| BG

    %% Click Events for UI Layer
    click A "https://github.com/ashumishrag/leetcode-whisper-chrome-extension/blob/add-gemini-models/src/App.tsx"
    click UIC "https://github.com/ashumishrag/leetcode-whisper-chrome-extension/tree/add-gemini-models/src/components"
    click S "https://github.com/ashumishrag/leetcode-whisper-chrome-extension/blob/add-gemini-models/index.html"
    click P "https://github.com/ashumishrag/leetcode-whisper-chrome-extension/blob/add-gemini-models/src/providers/theme.tsx"
    click H "https://github.com/ashumishrag/leetcode-whisper-chrome-extension/blob/add-gemini-models/src/hooks/useChromeStorage.ts"
    click MS "https://github.com/ashumishrag/leetcode-whisper-chrome-extension/blob/add-gemini-models/src/services/ModalService.ts"
    click M "https://github.com/ashumishrag/leetcode-whisper-chrome-extension/blob/add-gemini-models/src/modals/BaseModal.ts"
    click U "https://github.com/ashumishrag/leetcode-whisper-chrome-extension/tree/add-gemini-models/src/lib"

    %% Click Events for Browser Extension
    click MANIFEST "https://github.com/ashumishrag/leetcode-whisper-chrome-extension/blob/add-gemini-models/manifest.json"
    click BG "https://github.com/ashumishrag/leetcode-whisper-chrome-extension/blob/add-gemini-models/src/background.js"
    click CS "https://github.com/ashumishrag/leetcode-whisper-chrome-extension/blob/add-gemini-models/src/content.tsx"

    %% Styles
    classDef ui fill:#CCF0FF,stroke:#005B96,stroke-width:2px;
    classDef provider fill:#FFE6E6,stroke:#D9534F,stroke-width:2px;
    classDef modal fill:#E6E6FF,stroke:#5BC0DE,stroke-width:2px;
    classDef hooks fill:#FFF0B3,stroke:#F0AD4E,stroke-width:2px;
    classDef service fill:#D9EDF7,stroke:#31708F,stroke-width:2px;
    classDef utility fill:#F7E1D7,stroke:#8A6D3B,stroke-width:2px;
    classDef extension fill:#FFF9CC,stroke:#8A6D3B,stroke-width:2px;
    classDef user fill:#F5F5F5,stroke:#666666,stroke-width:2px;
```
