# saghen/heimdall architecture

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

- Interactive diagram: https://gitdiagram.com/saghen/heimdall
- Repository: https://github.com/saghen/heimdall

## Overview

##### Main Components

a. Browser Extension Layer
- Extension's content script and service worker components
- Permission management system
- Proxy routing system
- Cookie and storage management

b. Web Application Layer
- Frontend components (React-based)
- Parser system for different platforms
- Video player implementation
- Cache management system

##### Extension Infrastructure
**┌─ Browser Extension ─────────────────┐**
- Service Worker                   │
- Content Script                   │
- Permission Manager               │
- Proxy Router                     │
- ┘

##### Core Application
**┌─ Web Application ──────────────────┐**
- UI Components                   │
- Video Player                 │
- Navigation                   │
- Content Views               │
- State Management               │
- ┘

##### Parser System
**┌─ Platform Parsers ────────────────┐**
- YouTube Parser                 │
- Twitch Parser                 │
- Standard Parser Interface     │
- ┘

##### External Services Integration
**┌─ External APIs ─────────────────┐**
- YouTube API                 │
- Twitch API                 │
- ReturnYouTubeDislike API   │
- Other Platform APIs        │
- ┘

Use these visual elements:

Important Relationships to Show:
##### Cache and storage management across components

Key Technical Considerations:
- How the proxy system intercepts and modifies requests
- Parsing pipeline for different platforms
- Demonstrate the video player's integration with platform-specific features
- How the caching system interacts with different components

Specific features:
- SponsorBlock integration
- Closed captions system
- Platform-specific authentication flows
- Cross-platform content aggregation

Remember to:
##### Use consistent iconography

- The extension's role in enabling cross-platform functionality
- The modular parser system
- The unified player experience
- The caching and performance optimization systems

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph BrowserExtension
        SW["Service Worker"]:::extension
        CS["Content Script"]:::extension
        PM["Permission Manager"]:::extension
        PR["Proxy Router"]:::extension
        CM["Cookie Management"]:::extension
        SM["Storage Management"]:::extension
    end

    subgraph WebApplication
        MA["Main App"]:::webapp
        VP["Video Player"]:::webapp
        PC["Player Controls"]:::webapp
        NB["Navigation Bar"]:::webapp
        CS_["Cache System"]:::webapp
    end

    subgraph ParserSystem
        SPI["Standard Parser Interface"]:::parser
        YTP["YouTube Parser"]:::parser
        TWP["Twitch Parser"]:::parser
        
        subgraph YouTubeProcessing
            YCP["Channel Processing"]:::parser
            YVP["Video Processing"]:::parser
            CCS["Closed Captions System"]:::parser
            SBI["SponsorBlock Integration"]:::parser
        end
    end

    subgraph UIComponents
        VC["Video Components"]:::ui
        CC["Channel Components"]:::ui
        PC_["Playlist Components"]:::ui
    end

    subgraph Views
        WV["Watch View"]:::view
        CV["Channel View"]:::view
        PV["Playlist View"]:::view
        SV["Settings View"]:::view
    end

    subgraph ExternalAPIs
        YTA["YouTube API"]:::external
        TWA["Twitch API"]:::external
        RYD["ReturnYouTubeDislike API"]:::external
    end

    %% Relationships
    SW --> PR
    CS --> PR
    PR --> CM
    PR --> SM
    
    MA --> VP
    MA --> NB
    VP --> PC
    
    SPI --> YTP
    SPI --> TWP
    YTP --> YCP
    YTP --> YVP
    YVP --> CCS
    YVP --> SBI
    
    YTP --> YTA
    TWP --> TWA
    SBI --> RYD
    
    WV --> VP
    CV --> CC
    PV --> PC_
    
    CS_ --> MA

    %% Click Events
    click SW "https://github.com/saghen/heimdall/blob/master/extension/src/service-worker.ts"
    click CS "https://github.com/saghen/heimdall/blob/master/extension/src/content-script.ts"
    click PM "https://github.com/saghen/heimdall/blob/master/extension/src/permissions.ts"
    click PR "https://github.com/saghen/heimdall/blob/master/extension/src/routes/proxy/index.ts"
    click CM "https://github.com/saghen/heimdall/blob/master/extension/src/routes/cookies.ts"
    click SM "https://github.com/saghen/heimdall/blob/master/extension/src/routes/storage.ts"
    click MA "https://github.com/saghen/heimdall/blob/master/src/App.tsx"
    click VP "https://github.com/saghen/heimdall/blob/master/src/views/watch/player/Player.tsx"
    click PC "https://github.com/saghen/heimdall/blob/master/src/views/watch/player/Controls.tsx"
    click NB "https://github.com/saghen/heimdall/blob/master/src/components/NavBar.tsx"
    click CS_ "https://github.com/saghen/heimdall/blob/master/src/libs/cache/index.ts"
    click SPI "https://github.com/saghen/heimdall/blob/master/src/parser/std/index.ts"
    click YTP "https://github.com/saghen/heimdall/blob/master/src/parser/yt/index.ts"
    click TWP "https://github.com/saghen/heimdall/blob/master/src/parser/twitch/index.ts"
    click YCP "https://github.com/saghen/heimdall/blob/master/src/parser/yt/channel/index.ts"
    click YVP "https://github.com/saghen/heimdall/blob/master/src/parser/yt/video/index.ts"
    click CCS "https://github.com/saghen/heimdall/blob/master/src/parser/yt/video/processors/player/captions.ts"
    click SBI "https://github.com/saghen/heimdall/blob/master/src/parser/yt/video/sponsorblock.ts"
    click VC "https://github.com/saghen/heimdall/blob/master/src/components/Video/Card.tsx"
    click CC "https://github.com/saghen/heimdall/blob/master/src/components/Channel/Card.tsx"
    click PC_ "https://github.com/saghen/heimdall/blob/master/src/components/Playlist/Card.tsx"
    click WV "https://github.com/saghen/heimdall/blob/master/src/views/watch/Watch.tsx"
    click CV "https://github.com/saghen/heimdall/blob/master/src/views/channel/Channel.tsx"
    click PV "https://github.com/saghen/heimdall/blob/master/src/views/playlist/Playlist.tsx"
    click SV "https://github.com/saghen/heimdall/blob/master/src/views/settings/Settings.tsx"

    %% Styles
    classDef extension fill:#2196F3,color:white
    classDef webapp fill:#4CAF50,color:white
    classDef parser fill:#FF9800,color:white
    classDef ui fill:#9C27B0,color:white
    classDef view fill:#607D8B,color:white
    classDef external fill:#795548,color:white

    %% Legend
    subgraph Legend
        L1["Extension Components"]:::extension
        L2["Web Application"]:::webapp
        L3["Parser System"]:::parser
        L4["UI Components"]:::ui
        L5["Views"]:::view
        L6["External APIs"]:::external
    end
```
