# couscousz/bettergpt architecture

> Architecture diagram of the GitHub repository couscousz/bettergpt, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/couscousz/bettergpt
- Repository: https://github.com/couscousz/bettergpt

## Overview

##### Main Components

a. Browser Extension Architecture:
- Background Script (from entrypoints/background.ts)
- Content Script (from entrypoints/content/)
- UI Components Layer
- Event Communication Layer

b. External Integration:
- ChatGPT Web Interface
- Browser Extension API

##### Core Extension Components
- ┌─ Browser Extension ─────────────────────────┐

- ┌─ Background Script ─┐    ┌─ Content ─┐  │
- Script    │  │
- ┘    └───────────┘  │
- ▲                      ▲         │

- ▼                      ▼         │
- ┌─ Event Communication Layer ─┐         │
- ┘        │
- ┘

##### UI Component Hierarchy
- ┌─ UI Components ──────────────────┐

- ┌─ App.tsx ──────────────────┐ │
- Header                 │ │
- Sidebar               │ │
- Messages              │ │
- Tools                 │ │
- Footer               │ │
- Theme                │ │
- ┘ │
- ┘

##### Key Elements to Emphasize

- Blue: Core extension components
- Green: UI components
- Orange: External interfaces (ChatGPT)
- Purple: Communication channels

- Specific interactions:
- Content script ↔ ChatGPT web interface
- Event communication between components
- UI component hierarchy
- Message flow for the chat list feature

##### Technical Details

- Framework: React (evident from .tsx files)
- Styling: Tailwind CSS (from configuration files)
- Build System: WXT
- Type System: TypeScript

##### Important Architectural Patterns to Highlight

- Component-based architecture (React components)
- Event-driven communication (EventEmitterContext)
- Context-based state management
- Type-safe interfaces (Api.ts, Messages.ts)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph BrowserExtension
        BG[Background Script]
        CS[Content Script]
        ECL[Event Communication Layer]
        
        subgraph UIComponents
            App[App Container]
            
            subgraph Components
                Header[Header]
                Sidebar[Sidebar]
                Messages[Messages]
                Tools[Tools]
                Footer[Footer]
                Theme[Theme]
                Button[Base UI Components]
            end
            
            App --> Header
            App --> Sidebar
            App --> Messages
            App --> Tools
            App --> Footer
            App --> Theme
            Components --> Button
        end
        
        subgraph Types
            ApiTypes[API Types]
            MessageTypes[Message Types]
        end
        
        BuildConfig[Build Config]
        Styling[Styling Layer]
    end
    
    ChatGPT[ChatGPT Web Interface]:::external
    
    BG <--> ECL
    CS <--> ECL
    CS <--> ChatGPT
    ECL <--> App
    
    %% Component Mappings
    click BG "https://github.com/COUSCOUSZ/BetterGPT/blob/main/entrypoints/background.ts"
    click CS "https://github.com/COUSCOUSZ/BetterGPT/blob/main/entrypoints/content/index.tsx"
    click App "https://github.com/COUSCOUSZ/BetterGPT/blob/main/entrypoints/content/App.tsx"
    click ECL "https://github.com/COUSCOUSZ/BetterGPT/blob/main/entrypoints/content/context/EventEmitterContext.tsx"
    click Header "https://github.com/COUSCOUSZ/BetterGPT/blob/main/entrypoints/content/components/Header.tsx"
    click Sidebar "https://github.com/COUSCOUSZ/BetterGPT/blob/main/entrypoints/content/components/Sidebar.tsx"
    click Messages "https://github.com/COUSCOUSZ/BetterGPT/blob/main/entrypoints/content/components/Messages.tsx"
    click Tools "https://github.com/COUSCOUSZ/BetterGPT/blob/main/entrypoints/content/components/Tools.tsx"
    click Footer "https://github.com/COUSCOUSZ/BetterGPT/blob/main/entrypoints/content/components/Footer.tsx"
    click Theme "https://github.com/COUSCOUSZ/BetterGPT/blob/main/entrypoints/content/components/Theme.tsx"
    click ApiTypes "https://github.com/COUSCOUSZ/BetterGPT/blob/main/entrypoints/content/types/Api.ts"
    click MessageTypes "https://github.com/COUSCOUSZ/BetterGPT/blob/main/entrypoints/content/types/Messages.ts"
    click Styling "https://github.com/COUSCOUSZ/BetterGPT/blob/main/assets/css/tailwind.css"
    click BuildConfig "https://github.com/COUSCOUSZ/BetterGPT/blob/main/wxt.config.ts"
    click Button "https://github.com/COUSCOUSZ/BetterGPT/blob/main/entrypoints/content/components/ui/Button.tsx"
    
    classDef core fill:#2b6cb0,stroke:#1a4971,color:white
    classDef ui fill:#48bb78,stroke:#2f855a,color:white
    classDef communication fill:#805ad5,stroke:#553c9a,color:white
    classDef external fill:#ed8936,stroke:#c05621,color:white
    classDef config fill:#718096,stroke:#4a5568,color:white
    
    class BG,CS core
    class App,Header,Sidebar,Messages,Tools,Footer,Theme,Button ui
    class ECL communication
    class ChatGPT external
    class BuildConfig,Styling,ApiTypes,MessageTypes config
    
    %% Legend
    subgraph Legend
        CoreComp[Core Components]:::core
        UIComp[UI Components]:::ui
        CommComp[Communication]:::communication
        ExtComp[External Interface]:::external
        ConfigComp[Configuration]:::config
    end
```
