How ashumishrag/leetcode-whisper-chrome-extension works
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.