# ajayyy/sponsorblock architecture

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

- Interactive diagram: https://gitdiagram.com/ajayyy/sponsorblock
- Repository: https://github.com/ajayyy/sponsorblock

## Overview

##### Main Components

a. Browser Extension Components:
- Frontend UI Layer (popup, options, and content scripts)
- Background Service Worker
- Local Storage/Configuration
- Component Registry

b. External Services:
- SponsorBlock Server (API)
- YouTube/Invidious Integration
- NewLeaf Service

##### User Interface Layer
- Popup Interface (/public/popup.html)
- Options Page (/public/options)
- Content Scripts (src/content.ts)
- Help Pages (/public/help)

##### Core Extension Layer
- Background Service (src/background.ts)
- Components System (/src/components)
- Render System (/src/render)
- Utils (/src/utils)

##### External Integration Layer
- API Communication
- Video Platform Integration
- Database Interaction

Use the following visual elements:
- Hexagons for external services

- Blue: UI components
- Green: Core extension functionality
- Yellow: External services
- Gray: Utilities and helpers

##### Component Relationships

Key interactions:
**[User Interface] ↔ [Background Service]**
- ↕
**[Content Scripts] ↔ [YouTube/Invidious]**
- ↕
**[Background Service] ↔ [SponsorBlock API]**

##### Important Details

- Configuration flow (config.json.example → local storage)
- Category system for different skip types
- Crowdsourcing submission flow
- Video segment processing pipeline
- Cross-browser compatibility layer

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph UI["User Interface Layer"]
        POP["Popup Interface"]
        OPT["Options Page"]
        HELP["Help Pages"]
        CONT["Content Scripts"]
    end

    subgraph CORE["Core Extension Layer"]
        BG["Background Service"]
        COMP["Component System"]
        REND["Render System"]
        UTIL["Utils"]
        
        subgraph CONFIG["Configuration Management"]
            CONF["Config System"]
            STORAGE[("Local Storage")]
        end
        
        subgraph CAT["Category Management"]
            CATUTIL["Category Utils"]
            CATPILL["Category Pills"]
            CATCHOOSE["Category Chooser"]
        end
    end

    subgraph EXT["External Integration Layer"]
        API["SponsorBlock API"]
        YT["YouTube/Invidious"]
        NL["NewLeaf Service"]
        CROSS["Cross-Browser Layer"]
    end

    %% Relationships
    POP --> BG
    OPT --> BG
    CONT --> YT
    CONT --> BG
    BG --> API
    BG --> STORAGE
    CONF --> STORAGE
    COMP --> REND
    CATUTIL --> CATPILL
    CATUTIL --> CATCHOOSE
    CROSS --> API
    CROSS --> YT
    
    %% Click Events
    click POP "https://github.com/ajayyy/SponsorBlock/blob/master//public/popup.html"
    click OPT "https://github.com/ajayyy/SponsorBlock/blob/master//public/options/options.html"
    click HELP "https://github.com/ajayyy/SponsorBlock/blob/master//public/help/index.html"
    click CONT "https://github.com/ajayyy/SponsorBlock/blob/master//src/content.ts"
    click BG "https://github.com/ajayyy/SponsorBlock/blob/master//src/background.ts"
    click COMP "https://github.com/ajayyy/SponsorBlock/tree/master//src/components"
    click REND "https://github.com/ajayyy/SponsorBlock/tree/master//src/render"
    click UTIL "https://github.com/ajayyy/SponsorBlock/tree/master//src/utils"
    click CONF "https://github.com/ajayyy/SponsorBlock/blob/master//src/config.ts"
    click CROSS "https://github.com/ajayyy/SponsorBlock/blob/master//src/utils/compatibility.ts"
    click CATUTIL "https://github.com/ajayyy/SponsorBlock/blob/master//src/utils/categoryUtils.ts"
    click CATPILL "https://github.com/ajayyy/SponsorBlock/blob/master//src/components/CategoryPillComponent.tsx"
    click CATCHOOSE "https://github.com/ajayyy/SponsorBlock/blob/master//src/render/CategoryChooser.tsx"

    %% Styling
    classDef ui fill:#a8d1f0,stroke:#333
    classDef core fill:#90EE90,stroke:#333
    classDef external fill:#FFE5B4,stroke:#333
    classDef config fill:#E6E6FA,stroke:#333
    classDef storage fill:#D3D3D3,stroke:#333

    class POP,OPT,HELP,CONT ui
    class BG,COMP,REND,UTIL core
    class API,YT,NL,CROSS external
    class CONF,CATUTIL,CATPILL,CATCHOOSE config
    class STORAGE storage
```
