# mullvad/browser-extension architecture

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

- Interactive diagram: https://gitdiagram.com/mullvad/browser-extension
- Repository: https://github.com/mullvad/browser-extension

## Overview

##### Component Relationships

- Communication between popup/options and background script
- Data flow between components and browser storage
- External API interactions
- Browser permission interactions

##### Key Technical Elements

a. Browser APIs (show as interfaces):
- Management API
- Privacy API
- Storage API
- Proxy API
- Tabs API

b. State Management:
- Browser Storage
- Composables (/src/composables)

##### Architectural Patterns to Highlight

- Vue.js Component Architecture
- Composable Pattern for Feature Management
- Event-Driven Communication
- Browser Extension Architecture (Background/Popup/Options)

##### Specific Implementation Details

Create sections for:
- Privacy Features (WebRTC, HTTPS-Only)
- Proxy Management System
- Location Management
- Connection Monitoring

**┌─ User Interface Layer ─────────────────────┐**
- Popup  │  Options  │  Shared Components   │
- ┤
- State Management (Composables)       │
- ┤
- Background Service Layer          │
- ┤
- Browser Extension APIs           │
- ┤
- External Services Layer          │
- ┘

Important Considerations:

- Browser extension specific elements
- Vue.js components
- External API endpoints
- Security/privacy features

- Proxy configuration flow
- Privacy recommendation system
- Connection status monitoring

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and classes
    classDef ui fill:#3498db,stroke:#2980b9,color:white
    classDef core fill:#2ecc71,stroke:#27ae60,color:white
    classDef api fill:#f1c40f,stroke:#f39c12,color:black
    classDef external fill:#e74c3c,stroke:#c0392b,color:white
    classDef state fill:#9b59b6,stroke:#8e44ad,color:white

    %% Legend
    subgraph Legend
        UI[UI Components]:::ui
        Core[Core Features]:::core
        API[Browser APIs]:::api
        Ext[External Services]:::external
        State[State Management]:::state
    end

    %% User Interface Layer
    subgraph UserInterface
        Popup["Popup Interface"]:::ui
        Options["Options Interface"]:::ui
        SharedComponents["Shared Components"]:::ui
    end

    %% Core Features Layer
    subgraph CoreFeatures
        ProxyMgmt["Proxy Management"]:::core
        PrivacyRec["Privacy Recommendations"]:::core
        ConnStatus["Connection Status"]:::core
        DnsLeak["DNS Leak Detection"]:::core
        WebRTC["WebRTC Privacy"]:::core
        LocationMgmt["Location Management"]:::core
    end

    %% State Management Layer
    subgraph StateManagement
        Store["Store"]:::state
        Composables["Composables"]:::state
        ConnStore["Connection Store"]:::state
    end

    %% Background Service Layer
    subgraph BackgroundService
        BgScript["Background Script"]:::core
        EventListeners["Event Listeners"]:::core
    end

    %% Browser APIs Layer
    subgraph BrowserAPIs
        ManagementAPI["Management API"]:::api
        PrivacyAPI["Privacy API"]:::api
        StorageAPI["Storage API"]:::api
        ProxyAPI["Proxy API"]:::api
        TabsAPI["Tabs API"]:::api
    end

    %% External Services Layer
    subgraph ExternalServices
        MullvadAPI["Mullvad API"]:::external
        ConnCheck["Connection Check"]:::external
    end

    %% Relationships
    Popup --> BgScript
    Options --> BgScript
    BgScript --> StorageAPI
    BgScript --> ProxyAPI
    BgScript --> PrivacyAPI
    BgScript --> MullvadAPI
    BgScript --> ConnCheck
    ProxyMgmt --> ProxyAPI
    PrivacyRec --> PrivacyAPI
    ConnStatus --> ConnCheck
    DnsLeak --> ConnCheck
    Store --> Composables
    Composables --> BgScript

    %% Click events
    click Popup "https://github.com/mullvad/browser-extension/blob/main/src/popup/Popup.vue"
    click Options "https://github.com/mullvad/browser-extension/blob/main/src/options/Options.vue"
    click BgScript "https://github.com/mullvad/browser-extension/blob/main/src/background/main.ts"
    click ProxyMgmt "https://github.com/mullvad/browser-extension/tree/main/src/components/Proxy"
    click PrivacyRec "https://github.com/mullvad/browser-extension/blob/main/src/components/PrivacyRecommendations/PrivacyRecommendations.vue"
    click ConnStatus "https://github.com/mullvad/browser-extension/blob/main/src/components/ConnectionStatus/ConnectionStatus.vue"
    click DnsLeak "https://github.com/mullvad/browser-extension/blob/main/src/components/ConnectionStatus/DnsLeakStatus.vue"
    click LocationMgmt "https://github.com/mullvad/browser-extension/blob/main/src/components/ConnectionLocation/ConnectionLocation.vue"
    click WebRTC "https://github.com/mullvad/browser-extension/blob/main/src/components/ConnectionDetails/AdvancedWebTRC.vue"
    click Store "https://github.com/mullvad/browser-extension/blob/main/src/composables/useStore.ts"
    click ConnStore "https://github.com/mullvad/browser-extension/blob/main/src/composables/useConnection.ts"
    click Composables "https://github.com/mullvad/browser-extension/tree/main/src/composables"
```
