# fivefold/linkding-injector architecture

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

- Interactive diagram: https://gitdiagram.com/fivefold/linkding-injector
- Repository: https://github.com/fivefold/linkding-injector

## Overview

##### Main Components

a. Browser Extension Components:
- Background Service (represented by background.js)
- Content Scripts (searchInjection.js)
- Options Page (options.svelte)
- Configuration Manager (configuration.js)

b. External Systems:
- Linkding Server (self-hosted instance)
- Supported Search Engines (Google, DuckDuckGo, SearX/SearXNG, etc.)
- Browser API Interface (browser.js)

**┌─ Browser Environment ─────────────────────────────────────┐**

- ┌─ Extension ─────────────────────┐                     │

- ┌─ Background Service ───┐     │     ┌─ Web Pages ─┐│

- Event Handling      ◄─────────────┐ Search     ││
- API Communication   │     │     │ Engines     ││
- ▲─────────┘     │     │             ││
- ┘│
- ┌───────────┴─────────┐     │                    │
- Content Scripts    │     │                    │

- Search Injection  │     │                    │
- UI Integration    │     │                    │
- ▲─────────┘     │                    │

- ┌──────────┴──────────┐    │                    │
- Options Page      │    │                    │

- Configuration UI  │    │                    │
- ┘    │                    │
- ┬───────────────┘                    │

- ┼─────────────────────────────────────┘

**┌────────────────▼────────────────┐**
- Linkding Server            │

- Bookmark Storage & Search     │
- ┘

##### Key Interactions to Highlight

a. Content Script Injection Flow:
- How searchInjection.js injects into supported search engine pages
- How the injected UI appears in the search results sidebar

b. Data Flow:
- Search query from search engine to background service
- Background service communication with linkding server
- Results injection back into the search page

c. Configuration Flow:
- Options page to configuration storage
- Configuration retrieval by background service

##### Important Technical Details

- Manifest Version differences (V2 for Firefox, V3 for Chrome)
- SCSS/CSS styling system
- Browser API abstraction layer
- Theme detection system

##### Additional Notes

- A note about the experimental nature of SearX/SearXNG support
- Theme detection system's integration with the browser
- Build system's role in generating different versions for Firefox and Chrome

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph BE[Browser Environment]
        subgraph EX[Extension]
            BG[Background Service]:::background
            CS[Content Scripts]:::content
            OP[Options Page]:::options
            CM[Configuration Manager]:::config
            BAI[Browser API Interface]:::browser
            LI[Linkding Integration]:::linkding
            TS[Theme System]:::theme
            UI[UI Styling]:::ui
            EP[Extension Entry Point]:::entry
        end

        subgraph WP[Web Pages]
            SE[Search Engines]
        end
    end

    LS[Linkding Server]:::external

    %% Relationships
    SE --> BG
    BG <--> BAI
    BG <--> LI
    CS --> BG
    CS --> UI
    CS --> TS
    OP --> CM
    CM --> BAI
    LI --> LS
    EP --> BG
    EP --> CS

    %% Styling
    classDef background fill:#a8d1ff
    classDef content fill:#ffb3b3
    classDef options fill:#ffd9b3
    classDef config fill:#b3ffb3
    classDef browser fill:#d1d1ff
    classDef linkding fill:#ffccff
    classDef theme fill:#ffffb3
    classDef ui fill:#b3fff9
    classDef entry fill:#e6b3ff
    classDef external fill:#cccccc

    %% Click events
    click BG "https://github.com/Fivefold/linkding-injector/blob/master/src/background.js"
    click CS "https://github.com/Fivefold/linkding-injector/blob/master/src/searchInjection.js"
    click OP "https://github.com/Fivefold/linkding-injector/blob/master/src/options.svelte"
    click CM "https://github.com/Fivefold/linkding-injector/blob/master/src/configuration.js"
    click BAI "https://github.com/Fivefold/linkding-injector/blob/master/src/browser.js"
    click LI "https://github.com/Fivefold/linkding-injector/blob/master/src/linkding.js"
    click TS "https://github.com/Fivefold/linkding-injector/blob/master/scss/theme.scss"
    click UI "https://github.com/Fivefold/linkding-injector/blob/master/scss/bookmarks.scss"
    click EP "https://github.com/Fivefold/linkding-injector/blob/master/src/index.js"
    click SE "https://github.com/Fivefold/linkding-injector/blob/master/docs/searx.md"

    %% Legend
    subgraph Legend
        L1[Background Service]:::background
        L2[Content Scripts]:::content
        L3[Options Page]:::options
        L4[Configuration]:::config
        L5[Browser API]:::browser
        L6[Linkding Integration]:::linkding
        L7[Theme System]:::theme
        L8[UI Styling]:::ui
        L9[Entry Point]:::entry
        L10[External Systems]:::external
    end
```
