# ilyhalight/voice-over-translation architecture

> Architecture diagram of the GitHub repository ilyhalight/voice-over-translation, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ilyhalight/voice-over-translation
- Repository: https://github.com/ilyhalight/voice-over-translation

## Overview

##### Project Type and Purpose
- This is not a traditional full-stack web app but a browser user-script extension (“VOT”) that runs in Tampermonkey (or similar) to inject voice-over translation and subtitles into arbitrary video pages (YouTube, other sites).
- The README emphasizes features like on-the-fly translation (via Yandex.Translate or proxy), subtitle display & saving, audio export, UI customization, volume sync, and multi-language support.

##### Key Architectural Components
a. Development & CI
- GitHub repository with CI workflows (.github/workflows/build.yml, release.yml).
- Linting/precommit via Husky, ESLint, Prettier.
- Patch-package workflows for vendored dependency fixes (patches/).
- Localization generation tool (scripts/wiki-gen and @toil/localize-tui).
- Tests folder.
b. Build & Distribution
- Build scripts in package.json (npm run build, build:min, etc.).
- Output artifacts in dist/ (vot.user.js, vot-min.user.js).
- Dependencies managed via npm or Bun (bun.lock, package-lock.json).
c. Runtime (Injected User Script)
- src/index.js: entry point registered as user script.
- Core modules under src/:
- config (config.js)
- localization (hashes.json, locales, provider)
- ui (ui.js, ui/tooltip.ts) and styles (SCSS under src/styles)
- subtitle orchestration (subtitles.js)
- utilities (VideoObserver, storage, translateApis, volume control, errors)
- Type definitions (global.d.ts, index.d.ts, tooltip.ts).
d. External Services
- Yandex.Translate API (direct or via proxy servers)
- Proxy servers (vot-worker, media-proxy) for CORS or media-format support
- VOT-Backend for unsupported video formats
- Supported site pages (YouTube, others) where script is injected

##### Relationships & Data Flows
- VideoObserver → passes frames/time events → Subtitles Manager → UI overlay
- Audio Mixer → injects <audio> element or AudioContext → output mixed track
- UI Controls → user actions (volume slider, language select) → Config & Storage
- Build Pipeline → produces user script → deployed via GitHub Releases

##### Architectural Patterns & Principles
- Modular separation (config / localization / UI / utils)
- Single Responsibility per module (VideoObserver only watches player events, TranslateApis only handles API calls, etc.)
- Adapter pattern for translation backends (direct vs. proxy vs. backend)
- Observer pattern for video time updates & UI refresh
- Plugin-style localization (load JSON bundles)
- Build-time patch integration via patch-package

##### Essential Details
- Be explicit about the injection environment (Tampermonkey host context).
- How localization is loaded at startup.
- How SCSS styles compile into inline `<style>` or imported CSS.
- Patch-package mechanism at build time.
- Don’t omit the script’s interplay with browser storage and page DOM.
- Detail the external proxy/back-end services enabling translation and media handling.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Developer & CI Layer
    subgraph "Developer & CI Layer"
        direction TB
        Repo["GitHub Repository"]:::ci
        CI["CI Workflows"]:::ci
        Hooks["Pre-commit Hooks"]:::ci
        Lint["Lint & Formatting Config"]:::ci
        Patches["Patch-package Patches"]:::ci
        LocTool["Localization Generation Tool"]:::ci
        Tests["Tests Suite"]:::ci
    end

    %% Build & Distribution Layer
    subgraph "Build & Distribution"
        direction TB
        PKG["Package Config & Scripts"]:::build
        Bundler["Bundler (npm run build)"]:::build
        Artifacts["Build Artifacts (dist/)"]:::build
    end

    %% Runtime Layer
    subgraph "Runtime (Browser)"
        direction TB
        TM["Tampermonkey/MV2/MV3"]:::runtime
        Entry["User Script Entry (src/index.js)"]:::runtime

        subgraph "Core Libraries"
            direction TB
            Config["Feature Flags & Defaults"]:::runtime
            LocProv["Localization Provider Module"]:::runtime
            Hashes["Hash Indexes"]:::runtime
            Locales["Locale Bundles"]:::runtime
        end

        subgraph "Presentation"
            direction TB
            UI["UI Controller"]:::runtime
            Tooltip["Tooltip Component"]:::runtime
            StylesMain["Main Stylesheet"]:::runtime
            StylesSub["Subtitles Overlay Styles"]:::runtime
            StylesComp["Component Styles"]:::runtime
        end

        SubtitleMgr["Subtitles Orchestrator"]:::runtime

        subgraph "Utilities"
            direction TB
            VideoObs["Video Observer"]:::runtime
            TransAPI["TranslateAPI Adapter"]:::runtime
            Volume["Volume Synchronization"]:::runtime
            Storage["Storage Abstraction"]:::runtime
            Errors["Error Handling"]:::runtime
            Events["Event Implementation"]:::runtime
            Helpers["Misc Helpers"]:::runtime
        end
    end

    %% External Services Layer
    subgraph "External Services"
        direction TB
        Yandex["Yandex.Translate API"]:::external
        Proxy["Proxy Servers (vot-worker, media-proxy)"]:::external
        Backend["VOT-Backend Service"]:::external
    end

    %% Connections Developer to Build
    Repo -->|"push"| CI
    CI -->|"run workflows"| PKG
    Hooks --> PKG
    Lint --> PKG
    Patches --> PKG
    LocTool --> PKG
    Tests --> PKG

    PKG --> Bundler
    Bundler --> Artifacts

    %% Build to Runtime
    Artifacts -->|"dist/vot.user.js"| TM
    TM --> Entry

    %% Runtime module flows
    Entry --> Config
    Entry --> LocProv
    LocProv --> Hashes
    LocProv --> Locales

    Entry --> UI
    Entry --> SubtitleMgr
    Entry --> VideoObs
    Entry --> TransAPI
    Entry --> Volume
    Entry --> Storage
    Entry --> Errors
    Entry --> Events
    Entry --> Helpers

    UI --> Tooltip
    UI --> StylesMain
    UI --> StylesSub
    UI --> StylesComp

    VideoObs --> SubtitleMgr
    SubtitleMgr --> UI

    TransAPI -->|"/translate"| Yandex
    TransAPI -.->|"/translate via proxy"| Proxy
    Proxy --> Backend

    Volume --> VideoObs
    UI --> Storage
    Config --> Storage

    %% Click Events
    click CI "https://github.com/ilyhalight/voice-over-translation/blob/master/.github/workflows/build.yml"
    click CI "https://github.com/ilyhalight/voice-over-translation/blob/master/.github/workflows/release.yml"
    click Hooks "https://github.com/ilyhalight/voice-over-translation/tree/master/.husky/pre-commit"
    click Lint "https://github.com/ilyhalight/voice-over-translation/blob/master/eslint.config.js"
    click Lint "https://github.com/ilyhalight/voice-over-translation/blob/master/.prettierrc.json"
    click Lint "https://github.com/ilyhalight/voice-over-translation/blob/master/.prettierignore"
    click Patches "https://github.com/ilyhalight/voice-over-translation/tree/master/patches/"
    click LocTool "https://github.com/ilyhalight/voice-over-translation/tree/master/scripts/wiki-gen/"
    click Tests "https://github.com/ilyhalight/voice-over-translation/tree/master/tests/"
    click PKG "https://github.com/ilyhalight/voice-over-translation/blob/master/package.json"
    click PKG "https://github.com/ilyhalight/voice-over-translation/blob/master/bun.lock"
    click PKG "https://github.com/ilyhalight/voice-over-translation/blob/master/package-lock.json"
    click Artifacts "https://github.com/ilyhalight/voice-over-translation/blob/master/dist/vot.user.js"
    click Artifacts "https://github.com/ilyhalight/voice-over-translation/blob/master/dist/vot-min.user.js"
    click Entry "https://github.com/ilyhalight/voice-over-translation/blob/master/src/index.js"
    click Config "https://github.com/ilyhalight/voice-over-translation/blob/master/src/config/config.js"
    click Hashes "https://github.com/ilyhalight/voice-over-translation/blob/master/src/localization/hashes.json"
    click Locales "https://github.com/ilyhalight/voice-over-translation/tree/master/src/localization/locales/"
    click LocProv "https://github.com/ilyhalight/voice-over-translation/blob/master/src/localization/localizationProvider.js"
    click UI "https://github.com/ilyhalight/voice-over-translation/blob/master/src/ui.js"
    click Tooltip "https://github.com/ilyhalight/voice-over-translation/blob/master/src/ui/tooltip.ts"
    click StylesMain "https://github.com/ilyhalight/voice-over-translation/blob/master/src/styles/main.scss"
    click StylesSub "https://github.com/ilyhalight/voice-over-translation/blob/master/src/styles/subtitles.scss"
    click StylesComp "https://github.com/ilyhalight/voice-over-translation/tree/master/src/styles/components/"
    click SubtitleMgr "https://github.com/ilyhalight/voice-over-translation/blob/master/src/subtitles.js"
    click VideoObs "https://github.com/ilyhalight/voice-over-translation/blob/master/src/utils/VideoObserver.js"
    click TransAPI "https://github.com/ilyhalight/voice-over-translation/blob/master/src/utils/translateApis.ts"
    click Volume "https://github.com/ilyhalight/voice-over-translation/blob/master/src/utils/volume.js"
    click Storage "https://github.com/ilyhalight/voice-over-translation/blob/master/src/utils/storage.ts"
    click Errors "https://github.com/ilyhalight/voice-over-translation/blob/master/src/utils/VOTLocalizedError.js"
    click Events "https://github.com/ilyhalight/voice-over-translation/blob/master/src/utils/EventImpl.js"
    click Helpers "https://github.com/ilyhalight/voice-over-translation/blob/master/src/utils/utils.js"
    click Helpers "https://github.com/ilyhalight/voice-over-translation/blob/master/src/utils/debug.ts"

    %% Styles
    classDef ci fill:#D0E6FF,stroke:#0366d6,color:#0366d6
    classDef build fill:#DFF5D8,stroke:#28A745,color:#28A745
    classDef runtime fill:#E6FFE6,stroke:#22863A,color:#22863A
    classDef external fill:#FFEFD5,stroke:#D9730D,color:#D9730D
```
