# code-charity/youtube architecture

> Architecture diagram of the GitHub repository code-charity/youtube, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/code-charity/youtube
- Repository: https://github.com/code-charity/youtube

## Overview

1. **What this repo is**
   - This is a cross-browser YouTube extension, not a web app.
   - Its runtime behavior is split between browser extension logic, YouTube-page content scripts, and a bundled settings/menu UI.

2. **Top-level execution model**
   - `manifest.json` is the main integration point that tells the browser which scripts/styles run on YouTube.
   - The extension also has browser-specific manifest variants under `build/` for packaging, especially Firefox and legacy manifest differences.

3. **Core runtime logic**
   - `background.js` is the extension-side coordinator.
   - The `js&css/extension/` tree contains the main page-facing logic and feature wiring:
     - `core.js` for shared behavior
     - `functions.js` for utilities
     - `init.js` for bootstrapping
   - This is the layer that reacts to YouTube page state and user settings.

4. **YouTube feature subsystems**
   - Most functionality is organized by YouTube surface and feature area under `js&css/extension/www.youtube.com/`.
   - Notable feature boundaries include:
     - `appearance/` for page layout and visual tweaks
     - `general/` for general page behavior
     - `night-mode/` for dark/night styling
     - `sidebar.js`, plus related player/channel/blocklist/theme modules in the web-accessible tree
   - This structure suggests the extension is modular: each feature can be enabled, styled, and maintained independently.

5. **Content scripts vs page-context scripts**
   - `js&css/web-accessible/` is a separate boundary for scripts and assets that must be reachable by the page context or injected in a more permissive way.
   - It contains feature modules like `player.js`, `channel.js`, `settings.js`, `themes.js`, `shortcuts.js`, and `blocklist.js`.
   - The split between `extension/` and `web-accessible/` is important: one side runs as extension-controlled content logic, the other exposes functionality/assets to the page or other injected contexts.

6. **Settings and user interface**
   - The `menu/` directory is the extension’s settings UI.
   - `menu/index.html`, `menu/index.js`, and `menu/sidepanel.html` indicate a browser UI surface for configuring features.
   - `menu/satus.js` and `menu/skeleton*.js` show the UI is built on the project’s own `Satus` component library, with feature-specific panels in `menu/skeleton-parts/` and matching styles in `menu/styles/`.
   - This UI is the main user control plane that drives which YouTube behaviors are enabled.

7. **Localization pipeline**
   - `_locales/` contains a large set of translation bundles, each with `messages.json`.
   - These locale files are consumed by the extension UI and feature labels, allowing the same settings/menu experience across many languages.
   - `build/crowdin.yml` indicates translations are also managed via Crowdin, so localization is partly externalized to a translation platform.

8. **Styling and DOM manipulation**
   - CSS is a first-class part of the architecture: many features are implemented by injecting or toggling CSS under `js&css/.../*.css`.
   - This aligns with the repo’s goal of lightweight YouTube modifications—many behaviors are visual or layout-based rather than full JavaScript replacements.

9. **Build and packaging**
   - `build/build.py`, `build/locale.py`, and the manifest templates in `build/` indicate a generated release pipeline rather than a single hand-written distribution artifact.
   - There are separate packaging concerns for browser stores and browser variants, including Firefox and Safari workflows in `.github/workflows/`.
   - The repo is designed to be shipped as unpacked extension code, but also as store-ready builds.

10. **Quality gates and automated checks**
   - Tests are split into repo-level and unit-level checks under `tests/`.
   - `jest.config.js` plus unit tests like `themes-menu.test.js`, `thumbnails-per-row.test.js`, and `remaining-duration.test.js` indicate feature-level regression coverage for specific YouTube behaviors.
   - CI also runs linting for JavaScript, CSS, and test rules, reflecting a codebase with many DOM/CSS-driven feature toggles.

11. **External integration points**
   - The primary external dependency is YouTube itself; nearly all runtime behavior is page-specific customization of `youtube.com`.
   - The repo also depends on browser extension ecosystems: Chrome/Chromium, Firefox, Edge, Safari, Opera/Whale.
   - Crowdin is the only clearly visible non-browser service in the architecture, used for translation management.

12. **How data flows through the system**
   - User settings are edited in the menu UI, then consumed by feature modules in the extension runtime.
   - Those modules inject scripts and CSS into YouTube pages, where they modify DOM, visibility, styling, and player/page behavior.
   - Locale strings flow from `_locales/` into the UI and feature labels, while build scripts transform source files into browser-specific packages.

13. **Main architectural boundary to diagram**
   - The key separation is: **browser extension shell + settings UI** on one side, and **YouTube page augmentation modules** on the other.
   - Inside the augmentation side, the cleanest sub-boundaries are: **core/bootstrap**, **feature modules by YouTube surface**, **web-accessible page-context helpers**, and **CSS-based appearance tweaks**.

Main entry points: [`js&css/extension/core.js`](https://github.com/code-charity/youtube/blob/master/js&css/extension/core.js) (Core), [`js&css/web-accessible/core.js`](https://github.com/code-charity/youtube/blob/master/js&css/web-accessible/core.js) (Web core), [`menu/index.js`](https://github.com/code-charity/youtube/blob/master/menu/index.js) (Menu app), [`background.js`](https://github.com/code-charity/youtube/blob/master/background.js) (Background)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_extension["Extension shell"]
  node_manifest["Manifest<br/>browser entrypoint<br/>[manifest.json]"]
  node_background["Background<br/>extension coordinator<br/>[background.js]"]
end

subgraph group_youtube["YouTube augmentation"]
  node_ext_core["Core<br/>[core.js]"]
  node_ext_functions["Functions<br/>helpers<br/>[functions.js]"]
  node_ext_init["Init<br/>bootstrap<br/>[init.js]"]
  node_appearance["Appearance<br/>feature area<br/>[appearance]"]
  node_general["General<br/>feature area<br/>[general]"]
  node_night_mode["Night mode<br/>theme feature<br/>[night-mode]"]
  node_web_core["Web core<br/>page-accessible core<br/>[core.js]"]
  node_player["Player<br/>page module<br/>[player.js]"]
  node_channel["Channel<br/>page module<br/>[channel.js]"]
  node_settings_mod["Settings<br/>page module<br/>[settings.js]"]
  node_themes["Themes<br/>page module<br/>[themes.js]"]
  node_shortcuts["Shortcuts<br/>page module<br/>[shortcuts.js]"]
  node_blocklist["Blocklist<br/>page module<br/>[blocklist.js]"]
end

subgraph group_ui["Settings UI"]
  node_menu_index["Menu app<br/>settings app<br/>[index.js]"]
  node_menu_satus["Satus<br/>ui framework<br/>[satus.js]"]
  node_menu_skeleton["Skeleton<br/>ui schema<br/>[skeleton.js]"]
  node_menu_parts["Panels<br/>ui sections"]
end

subgraph group_build["Build and release"]
  node_locales[("Locales<br/>translations")]
  node_build_scripts["Build scripts<br/>packaging<br/>[build.py]"]
  node_manifests["Build manifests<br/>packaging<br/>[manifest2.json]"]
  node_ci["CI workflows<br/>automation<br/>[workflows]"]
end

node_manifest -->|"loads"| node_background
node_manifest -->|"injects"| node_ext_init
node_background -->|"coordinates"| node_ext_core
node_background -->|"opens UI"| node_menu_index
node_ext_init -->|"boots"| node_ext_core
node_ext_core -->|"uses"| node_ext_functions
node_ext_core -->|"activates"| node_appearance
node_ext_core -->|"activates"| node_general
node_ext_core -->|"activates"| node_night_mode
node_ext_core -->|"bridges"| node_web_core
node_web_core -->|"supports"| node_player
node_web_core -->|"supports"| node_channel
node_web_core -->|"supports"| node_settings_mod
node_web_core -->|"supports"| node_themes
node_web_core -->|"supports"| node_shortcuts
node_web_core -->|"supports"| node_blocklist
node_menu_index -->|"renders with"| node_menu_satus
node_menu_index -->|"composes"| node_menu_skeleton
node_menu_skeleton -->|"organizes"| node_menu_parts
node_menu_index -->|"reads"| node_locales
node_ext_core -->|"reads"| node_locales
node_build_scripts -->|"generates"| node_manifests
node_build_scripts -->|"packages"| node_locales
node_ci -->|"runs"| node_build_scripts
node_ci -->|"checks"| node_menu_index

click node_manifest "https://github.com/code-charity/youtube/blob/master/manifest.json"
click node_background "https://github.com/code-charity/youtube/blob/master/background.js"
click node_ext_core "https://github.com/code-charity/youtube/blob/master/js&css/extension/core.js"
click node_ext_functions "https://github.com/code-charity/youtube/blob/master/js&css/extension/functions.js"
click node_ext_init "https://github.com/code-charity/youtube/blob/master/js&css/extension/init.js"
click node_appearance "https://github.com/code-charity/youtube/blob/master/js&css/extension/www.youtube.com/appearance"
click node_general "https://github.com/code-charity/youtube/blob/master/js&css/extension/www.youtube.com/general"
click node_night_mode "https://github.com/code-charity/youtube/blob/master/js&css/extension/www.youtube.com/night-mode"
click node_web_core "https://github.com/code-charity/youtube/blob/master/js&css/web-accessible/core.js"
click node_player "https://github.com/code-charity/youtube/blob/master/js&css/web-accessible/www.youtube.com/player.js"
click node_channel "https://github.com/code-charity/youtube/blob/master/js&css/web-accessible/www.youtube.com/channel.js"
click node_settings_mod "https://github.com/code-charity/youtube/blob/master/js&css/web-accessible/www.youtube.com/settings.js"
click node_themes "https://github.com/code-charity/youtube/blob/master/js&css/web-accessible/www.youtube.com/themes.js"
click node_shortcuts "https://github.com/code-charity/youtube/blob/master/js&css/web-accessible/www.youtube.com/shortcuts.js"
click node_blocklist "https://github.com/code-charity/youtube/blob/master/js&css/web-accessible/www.youtube.com/blocklist.js"
click node_menu_index "https://github.com/code-charity/youtube/blob/master/menu/index.js"
click node_menu_satus "https://github.com/code-charity/youtube/blob/master/menu/satus.js"
click node_menu_skeleton "https://github.com/code-charity/youtube/blob/master/menu/skeleton.js"
click node_menu_parts "https://github.com/code-charity/youtube/tree/master/menu/skeleton-parts"
click node_locales "https://github.com/code-charity/youtube/tree/master/_locales"
click node_build_scripts "https://github.com/code-charity/youtube/blob/master/build/build.py"
click node_manifests "https://github.com/code-charity/youtube/blob/master/build/manifest2.json"
click node_ci "https://github.com/code-charity/youtube/blob/master/.github/workflows"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_manifest,node_background toneBlue
class node_ext_core,node_ext_functions,node_ext_init,node_appearance,node_general,node_night_mode,node_web_core,node_player,node_channel,node_settings_mod,node_themes,node_shortcuts,node_blocklist toneAmber
class node_menu_index,node_menu_satus,node_menu_skeleton,node_menu_parts toneMint
class node_locales,node_build_scripts,node_manifests,node_ci toneRose
```

## Components

### Extension shell

Browser integration, bootstrap, and runtime coordination.

- [Manifest](https://github.com/code-charity/youtube/blob/master/manifest.json): browser entrypoint · Primary extension declaration and script wiring. · `manifest.json`
- [Background](https://github.com/code-charity/youtube/blob/master/background.js): extension coordinator · Extension-side runtime coordinator. · `background.js`

### YouTube augmentation

Content scripts and injected modules that modify YouTube pages.

- [Core](https://github.com/code-charity/youtube/blob/master/js&css/extension/core.js): content core · Shared extension behavior for YouTube page logic. · `js&css/extension/core.js`
- [Functions](https://github.com/code-charity/youtube/blob/master/js&css/extension/functions.js): helpers · Utility functions used across extension runtime. · `js&css/extension/functions.js`
- [Init](https://github.com/code-charity/youtube/blob/master/js&css/extension/init.js): bootstrap · Bootstraps page-facing extension behavior. · `js&css/extension/init.js`
- [Appearance](https://github.com/code-charity/youtube/blob/master/js&css/extension/www.youtube.com/appearance): feature area · Layout and visual tweaks for YouTube surfaces. · `js&css/extension/www.youtube.com/appearance`
- [General](https://github.com/code-charity/youtube/blob/master/js&css/extension/www.youtube.com/general): feature area · General page behavior and baseline UI changes. · `js&css/extension/www.youtube.com/general`
- [Night mode](https://github.com/code-charity/youtube/blob/master/js&css/extension/www.youtube.com/night-mode): theme feature · Dark-mode styling and related behavior. · `js&css/extension/www.youtube.com/night-mode`
- [Web core](https://github.com/code-charity/youtube/blob/master/js&css/web-accessible/core.js): page-accessible core · Shared helpers for injected page-context modules. · `js&css/web-accessible/core.js`
- [Player](https://github.com/code-charity/youtube/blob/master/js&css/web-accessible/www.youtube.com/player.js): page module · Player-related injected logic and state handling. · `js&css/web-accessible/www.youtube.com/player.js`
- [Channel](https://github.com/code-charity/youtube/blob/master/js&css/web-accessible/www.youtube.com/channel.js): page module · Channel-page injected logic. · `js&css/web-accessible/www.youtube.com/channel.js`
- [Settings](https://github.com/code-charity/youtube/blob/master/js&css/web-accessible/www.youtube.com/settings.js): page module · Settings-related injected logic. · `js&css/web-accessible/www.youtube.com/settings.js`
- [Themes](https://github.com/code-charity/youtube/blob/master/js&css/web-accessible/www.youtube.com/themes.js): page module · Theme handling shared with the UI and page context. · `js&css/web-accessible/www.youtube.com/themes.js`
- [Shortcuts](https://github.com/code-charity/youtube/blob/master/js&css/web-accessible/www.youtube.com/shortcuts.js): page module · Keyboard shortcut handling for YouTube. · `js&css/web-accessible/www.youtube.com/shortcuts.js`
- [Blocklist](https://github.com/code-charity/youtube/blob/master/js&css/web-accessible/www.youtube.com/blocklist.js): page module · Filtering and blocklist logic exposed to the page context. · `js&css/web-accessible/www.youtube.com/blocklist.js`

### Settings UI

User-facing configuration and menu surfaces.

- [Menu app](https://github.com/code-charity/youtube/blob/master/menu/index.js): settings app · Main settings application entrypoint. · `menu/index.js`
- [Satus](https://github.com/code-charity/youtube/blob/master/menu/satus.js): ui framework · Custom component system used by the settings UI. · `menu/satus.js`
- [Skeleton](https://github.com/code-charity/youtube/blob/master/menu/skeleton.js): ui schema · Settings UI structure and feature panel composition. · `menu/skeleton.js`
- [Panels](https://github.com/code-charity/youtube/tree/master/menu/skeleton-parts): ui sections · Feature-specific settings panels. · `menu/skeleton-parts`

### Build and release

Packaging, manifests, localization, and CI workflows.

- [Locales](https://github.com/code-charity/youtube/tree/master/_locales): translations · Localized message bundles for UI and feature labels. · `_locales`
- [Build scripts](https://github.com/code-charity/youtube/blob/master/build/build.py): packaging · Release build and locale generation scripts. · `build/build.py`
- [Build manifests](https://github.com/code-charity/youtube/blob/master/build/manifest2.json): packaging · Browser-specific manifest templates for packaged builds. · `build/manifest2.json`
- [CI workflows](https://github.com/code-charity/youtube/blob/master/.github/workflows): automation · Automated build, lint, and release workflows. · `.github/workflows`

## Connections

- Manifest → Background: loads · Declares the background runtime and extension entrypoints.
- Manifest → Init: injects · Registers page-facing scripts for YouTube.
- Background → Core: coordinates · Orchestrates extension-side behavior through the core layer.
- Background → Menu app: opens UI · Connects extension state to the settings interface.
- Init → Core: boots · Initializes shared content-script behavior.
- Core → Functions: uses · Relies on shared helpers and utilities.
- Core → Appearance: activates · Enables appearance-related feature modules.
- Core → General: activates · Enables general YouTube behavior modules.
- Core → Night mode: activates · Enables night-mode styling and behavior.
- Core → Web core: bridges · Passes common logic to injected page-context modules.
- Web core → Player: supports · Shared helpers back player logic.
- Web core → Channel: supports · Shared helpers back channel logic.
- Web core → Settings: supports · Shared helpers back settings logic.
- Web core → Themes: supports · Shared helpers back theme logic.
- Web core → Shortcuts: supports · Shared helpers back shortcut logic.
- Web core → Blocklist: supports · Shared helpers back blocklist logic.
- Menu app → Satus: renders with · Settings app is built on the project UI framework.
- Menu app → Skeleton: composes · Loads the main settings structure.
- Skeleton → Panels: organizes · Breaks the menu into feature-specific panels.
- Menu app → Locales: reads · Uses translated labels and messages.
- Core → Locales: reads · Uses localized strings for feature UI.
- Build scripts → Build manifests: generates · Produces browser-specific manifest variants.
- Build scripts → Locales: packages · Transforms translation bundles into release artifacts.
- CI workflows → Build scripts: runs · Automates build and packaging steps.
- CI workflows → Menu app: checks · Validates settings UI and related assets in CI.
