# libredirect/browser_extension architecture

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

- Interactive diagram: https://gitdiagram.com/libredirect/browser_extension
- Repository: https://github.com/libredirect/browser_extension

## Overview

##### Main Components Identification

The system architecture should be divided into these key components:

a) Browser Extension Core
- Background Service
- Popup Interface
- Options/Settings Interface
- Localization System

b) Service Handlers
- Request Interceptor
- Redirect Logic
- Instance Management

**Rectangle (Blue) - Browser Extension Components**
- Background Service
- Popup UI
- Options UI
- Message Handler

**Hexagon (Green) - Service Layer**
- Request Interceptor
- Redirect Service
- Instance Manager

- Configuration Storage
- User Preferences

##### Key Relationships to Highlight

**Browser Tab → Request Interceptor → Redirect Service → Privacy-Friendly Frontend**
- ↕
- Background Service
- ↕
- Storage/Configuration

##### Technical Implementation Details

Specific technical aspects:
- Svelte Components (shown in src/pages/components)
- Browser Extension APIs
- Local Storage Integration
- Multi-language Support System

##### Specific Elements

a) Extension Components:
- Background Script (src/pages/background)
- Popup Interface (src/pages/popup_src)
- Options Panel (src/pages/options_src)
- Message System (src/pages/messages)

b) Service Layer:
- Service Configurations (src/assets/javascripts/services.js)
- Utility Functions (src/assets/javascripts/utils.js)

c) UI Components:
- Reusable Components (src/pages/components)

##### Multi-language support system

This will provide a comprehensive view of how LibRedirect functions as a browser extension while maintaining clarity about its privacy-focused redirect functionality.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Browser
        Tab[Browser Tab]
    end

    subgraph "Extension Core"
        BG[Background Service]:::core
        click BG "https://github.com/libredirect/browser_extension/blob/master/src/pages/background/background.js"
        
        Popup[Popup Interface]:::ui
        click Popup "https://github.com/libredirect/browser_extension/blob/master/src/pages/popup_src/App.svelte"
        
        Options[Options Interface]:::ui
        click Options "https://github.com/libredirect/browser_extension/blob/master/src/pages/options_src/App.svelte"
        
        MSG[Message Handler]:::core
        click MSG "https://github.com/libredirect/browser_extension/tree/master/src/pages/messages_src/"
    end

    subgraph "Service Layer"
        RI[Request Interceptor]:::service
        RS[Redirect Service]:::service
        IM[Instance Manager]:::service
        click IM "https://github.com/libredirect/browser_extension/blob/master/src/pages/options_src/Services/Instances.svelte"
        
        SC[Service Config]:::config
        click SC "https://github.com/libredirect/browser_extension/blob/master/src/assets/javascripts/services.js"
        
        Utils[Utility Functions]:::service
        click Utils "https://github.com/libredirect/browser_extension/blob/master/src/assets/javascripts/utils.js"
    end

    subgraph "Storage Layer"
        Store[(Configuration Storage)]:::storage
        click Store "https://github.com/libredirect/browser_extension/blob/master/src/pages/options_src/stores.js"
        
        Prefs[(User Preferences)]:::storage
    end

    subgraph "UI Components"
        RC[Reusable Components]:::ui
        click RC "https://github.com/libredirect/browser_extension/tree/master/src/pages/components/"
        
        IC[Icon Components]:::ui
        click IC "https://github.com/libredirect/browser_extension/tree/master/src/pages/icons/"
        
        SS[Service Settings]:::ui
        click SS "https://github.com/libredirect/browser_extension/blob/master/src/pages/options_src/Services/Services.svelte"
        
        GS[General Settings]:::ui
        click GS "https://github.com/libredirect/browser_extension/blob/master/src/pages/options_src/General/General.svelte"
        
        RT[Redirect Configuration]:::ui
        click RT "https://github.com/libredirect/browser_extension/blob/master/src/pages/options_src/Services/RedirectType.svelte"
    end

    subgraph "Support Systems"
        L10n[Localization System]:::support
        click L10n "https://github.com/libredirect/browser_extension/tree/master/src/_locales/"
        
        ExtConfig[Extension Config]:::config
        click ExtConfig "https://github.com/libredirect/browser_extension/blob/master/src/manifest.json"
    end

    %% Relationships
    Tab -->|Request| RI
    RI --> RS
    RS --> IM
    BG ---|Manages| RI
    BG ---|Controls| RS
    BG <-->|State| Store
    Options -->|Updates| Store
    Store -->|Loads| BG
    Popup <-->|Interacts| BG
    MSG <-->|Coordinates| BG
    SC ---|Configures| RS
    Utils ---|Supports| RS
    L10n ---|Provides| Options
    L10n ---|Provides| Popup
    ExtConfig ---|Configures| BG
    SS ---|Updates| Store
    GS ---|Updates| Store
    RT ---|Updates| Store
    RC ---|Used by| Options
    RC ---|Used by| Popup
    IC ---|Used by| RC

    %% Styles
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef service fill:#4CAF50,stroke:#2E7D32,color:white
    classDef ui fill:#9C27B0,stroke:#6A1B9A,color:white
    classDef storage fill:#FF9800,stroke:#EF6C00,color:white
    classDef config fill:#795548,stroke:#4E342E,color:white
    classDef support fill:#607D8B,stroke:#37474F,color:white

    %% Legend
    subgraph Legend
        C1[Core Component]:::core
        C2[Service Component]:::service
        C3[UI Component]:::ui
        C4[(Storage)]:::storage
        C5[Configuration]:::config
        C6[Support System]:::support
    end
```
