# foxgem/tsw architecture

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

- Interactive diagram: https://gitdiagram.com/foxgem/tsw
- Repository: https://github.com/foxgem/tsw

## Overview

##### Main Components Identification
The system should be divided into these primary components:

A. Extension Components:
- Popup Interface
- Content Scripts
- Background Service
- Settings Management
- UI Components Library
- AI Services Integration

B. External Services:
- Gemini AI API
- Image Processing Services (for OCR)
- Translation Services

##### Component Relationships

- Data flow between popup and content scripts
- Communication with background services
- Integration with AI services
- Storage interactions

##### Specific Implementation Details

A. Extension Architecture:
**[Popup Interface] ←→ [Background Service]**
- ↕               ↕
**[Content Scripts] ←→ [Storage Utils]**
- ↕
**[UI Components] ←→ [AI Tools]**

B. Feature Modules:
- Image OCR Pipeline
- Translation Service
- Code Analysis Tools
- Timer System
- Chat Interface

C. Tools Integration:
How the various tools in /src/ai/tools connect:
- Geomap
- Knowledge Card
- Mindmap
- Weather
- Search

##### Technical Stack Representation

Technology badges or labels for:
- Plasmo (Extension Framework)
- React
- Tailwind CSS
- Vercel AI SDK
- Gemini API

##### Key Interactions

Highlight:
- User interaction flows
- API communication patterns
- State management
- Storage mechanisms

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        UI[UI Components]
        Theme["Theme Provider"]:::ui
        PopUI["Popup Interface"]:::ui
        ChatUI["Chat Interface"]:::ui
        Tools["Tools Selection"]:::ui
        Panel["Extension Panel"]:::ui
        Settings["Settings Interface"]:::ui
        Timer["Timer System"]:::ui
        Lang["Translation UI"]:::ui
    end

    subgraph Core
        CS["Content Scripts"]:::core
        BG["Background Service"]:::core
        MH["Message Handlers"]:::core
        Storage["Storage Services"]:::core
    end

    subgraph "AI Tools"
        AI["AI Services"]:::ai
        subgraph Tools
            Geo["Geomap"]:::tool
            KC["Knowledge Card"]:::tool
            MM["Mindmap"]:::tool
            Weather["Weather"]:::tool
            Search["Search"]:::tool
        end
    end

    subgraph "External Services"
        Gemini["Gemini AI API"]:::external
        OCR["Image Processing"]:::external
        Trans["Translation API"]:::external
    end

    %% Frontend Connections
    UI --> PopUI
    UI --> ChatUI
    UI --> Tools
    UI --> Panel
    UI --> Settings
    Theme --> UI
    Timer --> Settings
    Lang --> UI

    %% Core Connections
    PopUI --> CS
    CS --> BG
    BG --> MH
    MH --> Storage

    %% AI Tools Connections
    CS --> AI
    AI --> Tools
    AI --> Gemini
    AI --> OCR
    AI --> Trans

    %% Tool Connections
    Tools --> Geo
    Tools --> KC
    Tools --> MM
    Tools --> Weather
    Tools --> Search

    %% Styling
    classDef ui fill:#4299e1
    classDef core fill:#ed8936
    classDef ai fill:#48bb78
    classDef tool fill:#68d391
    classDef external fill:#b794f4

    %% Click Events
    click PopUI "https://github.com/foxgem/tsw/blob/main/src/popup.tsx"
    click CS "https://github.com/foxgem/tsw/blob/main/src/content.ts"
    click BG "https://github.com/foxgem/tsw/blob/main/src/background.ts"
    click Settings "https://github.com/foxgem/tsw/tree/main/src/components/setting/"
    click UI "https://github.com/foxgem/tsw/tree/main/src/components/ui/"
    click AI "https://github.com/foxgem/tsw/blob/main/src/ai/ai.ts"
    click ChatUI "https://github.com/foxgem/tsw/blob/main/src/components/ChatUI.tsx"
    click Timer "https://github.com/foxgem/tsw/blob/main/src/components/setting/Timers.tsx"
    click Lang "https://github.com/foxgem/tsw/blob/main/src/components/SelectLang.tsx"
    click Geo "https://github.com/foxgem/tsw/blob/main/src/ai/tools/geomap.tsx"
    click KC "https://github.com/foxgem/tsw/blob/main/src/ai/tools/knowledgeCard.tsx"
    click MM "https://github.com/foxgem/tsw/blob/main/src/ai/tools/mindmap.tsx"
    click Weather "https://github.com/foxgem/tsw/blob/main/src/ai/tools/weather.tsx"
    click Search "https://github.com/foxgem/tsw/blob/main/src/ai/tools/search.ts"
    click Storage "https://github.com/foxgem/tsw/blob/main/src/utils/storage.ts"
    click MH "https://github.com/foxgem/tsw/blob/main/src/handlers.ts"
    click Theme "https://github.com/foxgem/tsw/blob/main/src/components/ThemeProvider.tsx"
    click Tools "https://github.com/foxgem/tsw/blob/main/src/components/ToolsSelect.tsx"
    click Panel "https://github.com/foxgem/tsw/blob/main/src/components/TSWPanel.tsx"
```
