# aclap-dev/video-downloadhelper architecture

> Architecture diagram of the GitHub repository aclap-dev/video-downloadhelper, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aclap-dev/video-downloadhelper
- Repository: https://github.com/aclap-dev/video-downloadhelper

## Overview

##### Project type and purpose
- From the README and file tree, this is a browser extension (“Video DownloadHelper”) that integrates with Firefox, Chrome, and Edge to detect and download videos from web pages.
- It is not a full-stack web app but rather a client-side extension with multiple components (content scripts, background scripts, UI popup, and assets).

##### File structure
- Top-level directories:
- .github – CI/discussion templates, license-purchase requests.
- Files you’d expect (not listed here but typical):
- manifest.json – declares permissions, scripts, UI pages.
- /src or /lib – content scripts (e.g., detector.js), background scripts (e.g., downloader.js), popup HTML/JS.
- README.md – badge links to stores, discussion, wiki. No explicit architecture section, so infer from standard extension patterns.

##### README for additional insights
- Wiki and CoApp links suggest a modular build/distribution process.

a. Main components:
1. Browser Extension Manifest – central registry for scripts, permissions, and UI.
2. Content Scripts – injected into web pages to detect media elements and send metadata to the background script.
3. Background Script – orchestrates download requests, manages state, handles download API calls.
4. Popup UI – user-facing interface (HTML/CSS/JS) to list detected videos, trigger downloads, show progress.
5. Browser Download Manager – native browser component invoked by the background script.
7. External Video Hosts – third-party websites streaming video content (YouTube, Vimeo, etc.).

b. Relationships and interactions:
- Content Script → Background Script: via `chrome.runtime.sendMessage` or `browser.runtime.sendMessage`.
- Popup UI ↔ Background Script: via message passing or port connection for commands (e.g., “startDownload”).
- Background Script → Browser Download Manager: using `chrome.downloads.download()` API.
- Content Script ↔ Web Page: DOM access to video tags or network interception.
- All scripts share data through the extension’s storage (e.g., `chrome.storage.local`).

c. Architectural patterns / design principles:
- Separation of concerns: detection logic in content scripts, orchestration in background, UI in popup.
- Event-driven messaging between components.
- Use of browser extension APIs (downloads, storage, runtime messaging).

d. Key technologies and libraries:
- WebExtension API (cross-browser compatibility).
- JavaScript/TypeScript for scripts.
- HTML/CSS for popup.
- Build tools (webpack/Rollup) if present in actual repo.
- Optional polyfills for cross-browser support.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Browser Extension"
        subgraph "Content Script Context"
            CS["Content Script"]:::service
            DOM["Web Page DOM"]:::external
        end
        subgraph "Background Service Worker Context"
            BG["Background Script"]:::service
            Storage["chrome.storage.local"]:::storage
            BDM["Browser Download Manager"]:::external
        end
        subgraph "Popup UI Context"
            UI["Popup UI"]:::ui
        end
        Assets["Assets"]:::assets
    end
    ExtHosts["External Video Hosts"]:::external

    CS -->|"reads video tags"|DOM
    CS -->|"runtime.sendMessage"|BG
    UI -->|"runtime.sendMessage"|BG
    BG -->|"response"|UI
    BG -->|"chrome.storage"|Storage
    BG -->|"chrome.downloads.download()"|BDM
    DOM -->|"streams from"|ExtHosts

    click Assets "https://github.com/aclap-dev/video-downloadhelper/tree/master/assets/"

    classDef ui fill:#e3f2fd,stroke:#0d47a1,color:#0d47a1
    classDef service fill:#e8f5e9,stroke:#1b5e20,color:#1b5e20
    classDef external fill:#eeeeee,stroke:#424242,color:#424242
    classDef storage fill:#fff3e0,stroke:#ef6c00,color:#e65100
    classDef assets fill:#f3e5f5,stroke:#6a1b9a,color:#4a148c
```
