# andresz74/youtube-transcript-extension architecture

> Architecture diagram of the GitHub repository andresz74/youtube-transcript-extension, 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/andresz74/youtube-transcript-extension
- Repository: https://github.com/andresz74/youtube-transcript-extension

## Overview

1. **What this repository is**
   - This is a **Chrome extension** whose UI lives in the browser popup.
   - It is a **thin client**: the extension itself does not scrape YouTube directly. Instead, it depends on an **external transcript API service** to fetch transcript data.

2. **Primary runtime boundary**
   - The extension runs inside Chrome’s extension runtime, centered on `manifest.json`, `src/popup.html`, and `src/popup.js`.
   - There is no separate backend in this repo; the only server-side dependency is the external transcript generator service described in the README.

3. **Popup UI subsystem**
   - `src/popup.html` defines the popup shell.
   - `src/ui.js` contains rendering helpers for the popup states: loading, transcript display, copy actions, and error/empty states.
   - `styles/styles.css` provides the popup’s presentation.
   - This is the only user-facing interface in the repo.

4. **Popup orchestration flow**
   - `src/popup.js` is the main controller for the popup lifecycle.
   - On open, it inspects the current tab, determines whether the page is a YouTube video page, and either:
     - shows a “no video found” state, or
     - triggers transcript retrieval and updates the UI as results arrive.
   - It is the central coordinator between URL detection, API calls, and rendering.

5. **YouTube page detection**
   - `src/url-detection.js` isolates the logic for deciding whether the active tab contains a YouTube video.
   - The README indicates support for standard watch pages and Shorts, and the code structure suggests this module encapsulates those URL rules so the popup controller stays small.

6. **Transcript data access boundary**
   - `src/transcript-api.js` is the network client that calls the external REST API.
   - It handles the important operational concerns for that boundary: request timing, error handling, and converting the remote response into something the UI can use.
   - This is the key integration point between the extension and the external transcript service.

7. **Response contract / normalization**
   - `src/transcript-contract.js` defines the expected shape of transcript data returned by the backend.
   - This module likely validates or normalizes the API response so the UI receives a stable contract, even if the backend response format changes slightly.
   - The presence of separate contract tests indicates this is treated as an important architectural boundary.

8. **Configuration and environment override**
   - `src/config.js` centralizes configuration such as the default API base URL and request timeout.
   - The README documents a runtime override via `localStorage.setItem('ytTranscriptApiBaseUrl', ...)`, which means the popup can be pointed at a local backend without changing source code.
   - That makes the external API endpoint a configurable dependency rather than a hard-coded one.

9. **End-to-end data flow**
   - User clicks the extension icon.
   - Popup opens and `popup.js` reads the active tab URL.
   - `url-detection.js` verifies the tab is a YouTube video page.
   - `transcript-api.js` calls the configured transcript service.
   - `transcript-contract.js` shapes the returned payload.
   - `ui.js` renders the title and transcript.
   - The user can then copy the transcript to the clipboard from the popup.

10. **Error and empty-state handling**
   - The architecture explicitly includes failure paths: non-YouTube pages, missing video IDs, API failures, timeouts, and potentially empty transcript responses.
   - These are surfaced in the popup rather than failing silently, which is important because the extension’s main dependency is an external service.

11. **Testing boundary**
   - The `tests/` directory focuses on the API client and contract logic:
     - `tests/transcript-api.spec.js`
     - `tests/transcript-contract.spec.js`
   - This indicates the most critical logic is considered to be the service integration and response-shaping layers, not the static UI markup.

12. **Repository/tooling shape**
   - The project is a small, framework-free JavaScript codebase with linting and formatting configured via ESLint and Prettier.
   - A GitHub Actions workflow (`.github/workflows/release-on-tag.yml`) handles release automation on tags, which is the main delivery pipeline in the repo.
   - The architecture is therefore: **browser extension UI + configurable REST dependency + lightweight validation/rendering layers**.

Main entry points: [`src/popup.js`](https://github.com/andresz74/youtube-transcript-extension/blob/main/src/popup.js) (Popup controller), [`src/transcript-api.js`](https://github.com/andresz74/youtube-transcript-extension/blob/main/src/transcript-api.js) (API client), [`src/ui.js`](https://github.com/andresz74/youtube-transcript-extension/blob/main/src/ui.js) (UI helpers), [`src/transcript-contract.js`](https://github.com/andresz74/youtube-transcript-extension/blob/main/src/transcript-contract.js) (Contract)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_extension["Chrome extension"]
  node_manifest["Manifest<br/>[manifest.json]"]
  node_popup_html["Popup shell<br/>popup markup<br/>[popup.html]"]
  node_popup_js["Popup controller<br/>popup orchestration<br/>[popup.js]"]
  node_ui_js["UI helpers<br/>rendering helpers<br/>[ui.js]"]
  node_url_detection["URL rules<br/>page detection<br/>[url-detection.js]"]
  node_config_js["Config<br/>[config.js]"]
  node_transcript_api["API client<br/>REST client<br/>[transcript-api.js]"]
  node_transcript_contract["Contract<br/>response shape"]
  node_styles_css["Styles<br/>popup styling<br/>[styles.css]"]
end

subgraph group_grp_service["Transcript service"]
  node_transcript_service[("Transcript API<br/>external REST service")]
end

subgraph group_grp_tooling["Tooling"]
  node_tests_api["API tests<br/>unit tests"]
  node_tests_contract["Contract tests<br/>unit tests"]
  node_release_workflow["Release flow<br/>github actions<br/>[release-on-tag.yml]"]
  node_package_json["Package config<br/>tooling config<br/>[package.json]"]
end

node_manifest -->|"popup entry"| node_popup_html
node_manifest -->|"load controller"| node_popup_js
node_popup_js -->|"detect page"| node_url_detection
node_popup_js -->|"read config"| node_config_js
node_popup_js -->|"fetch transcript"| node_transcript_api
node_transcript_api -->|"REST call"| node_transcript_service
node_transcript_api -->|"shape response"| node_transcript_contract
node_popup_js -->|"render states"| node_ui_js
node_popup_html -->|"mount UI"| node_ui_js
node_ui_js -->|"style UI"| node_styles_css
node_popup_js -->|"consume contract"| node_transcript_contract
node_tests_api -.->|"verify client"| node_transcript_api
node_tests_contract -.->|"verify shape"| node_transcript_contract
node_release_workflow -->|"release steps"| node_package_json

click node_manifest "https://github.com/andresz74/youtube-transcript-extension/blob/main/manifest.json"
click node_popup_html "https://github.com/andresz74/youtube-transcript-extension/blob/main/src/popup.html"
click node_popup_js "https://github.com/andresz74/youtube-transcript-extension/blob/main/src/popup.js"
click node_ui_js "https://github.com/andresz74/youtube-transcript-extension/blob/main/src/ui.js"
click node_url_detection "https://github.com/andresz74/youtube-transcript-extension/blob/main/src/url-detection.js"
click node_config_js "https://github.com/andresz74/youtube-transcript-extension/blob/main/src/config.js"
click node_transcript_api "https://github.com/andresz74/youtube-transcript-extension/blob/main/src/transcript-api.js"
click node_transcript_contract "https://github.com/andresz74/youtube-transcript-extension/blob/main/src/transcript-contract.js"
click node_styles_css "https://github.com/andresz74/youtube-transcript-extension/blob/main/styles/styles.css"
click node_tests_api "https://github.com/andresz74/youtube-transcript-extension/blob/main/tests/transcript-api.spec.js"
click node_tests_contract "https://github.com/andresz74/youtube-transcript-extension/blob/main/tests/transcript-contract.spec.js"
click node_release_workflow "https://github.com/andresz74/youtube-transcript-extension/blob/main/.github/workflows/release-on-tag.yml"
click node_package_json "https://github.com/andresz74/youtube-transcript-extension/blob/main/package.json"

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_popup_html,node_popup_js,node_ui_js,node_url_detection,node_config_js,node_transcript_api,node_transcript_contract,node_styles_css toneBlue
class node_transcript_service toneAmber
class node_tests_api,node_tests_contract,node_release_workflow,node_package_json toneMint
```

## Components

### Chrome extension

Popup-driven extension runtime in Chrome.

- [Manifest](https://github.com/andresz74/youtube-transcript-extension/blob/main/manifest.json): extension manifest · Declares the Chrome extension entrypoints and permissions. · `manifest.json`
- [Popup shell](https://github.com/andresz74/youtube-transcript-extension/blob/main/src/popup.html): popup markup · Defines the popup window structure. · `src/popup.html`
- [Popup controller](https://github.com/andresz74/youtube-transcript-extension/blob/main/src/popup.js): popup orchestration · Coordinates tab inspection, transcript lookup, and UI updates. · `src/popup.js`
- [UI helpers](https://github.com/andresz74/youtube-transcript-extension/blob/main/src/ui.js): rendering helpers · Renders loading, transcript, copy, empty, and error states. · `src/ui.js`
- [URL rules](https://github.com/andresz74/youtube-transcript-extension/blob/main/src/url-detection.js): page detection · Detects whether the active tab is a YouTube video page or Shorts page. · `src/url-detection.js`
- [Config](https://github.com/andresz74/youtube-transcript-extension/blob/main/src/config.js): runtime config · Holds API base URL and timeout defaults plus local override support. · `src/config.js`
- [API client](https://github.com/andresz74/youtube-transcript-extension/blob/main/src/transcript-api.js): REST client · Calls the external transcript service and handles request timing and failures. · `src/transcript-api.js`
- [Contract](https://github.com/andresz74/youtube-transcript-extension/blob/main/src/transcript-contract.js): response shape · Normalizes and validates transcript payloads from the service. · `src/transcript-contract.js`
- [Styles](https://github.com/andresz74/youtube-transcript-extension/blob/main/styles/styles.css): popup styling · Provides the popup presentation and layout. · `styles/styles.css`

### Transcript service

External REST dependency used to fetch transcript data.

- **Transcript API**: external REST service · Remote dependency that generates or serves transcript data.

### Tooling

Release, lint, and test support around the extension.

- [API tests](https://github.com/andresz74/youtube-transcript-extension/blob/main/tests/transcript-api.spec.js): unit tests · Covers transcript client behavior and failure handling. · `tests/transcript-api.spec.js`
- [Contract tests](https://github.com/andresz74/youtube-transcript-extension/blob/main/tests/transcript-contract.spec.js): unit tests · Covers transcript response shaping and validation. · `tests/transcript-contract.spec.js`
- [Release flow](https://github.com/andresz74/youtube-transcript-extension/blob/main/.github/workflows/release-on-tag.yml): github actions · Automates publishing on tagged releases. · `.github/workflows/release-on-tag.yml`
- [Package config](https://github.com/andresz74/youtube-transcript-extension/blob/main/package.json): tooling config · Defines scripts and project metadata for linting, formatting, and tests. · `package.json`

## Connections

- Manifest → Popup shell: popup entry · Manifest points Chrome to the popup UI.
- Manifest → Popup controller: load controller · Popup runtime bootstraps the controller logic.
- Popup controller → URL rules: detect page · Checks whether the active tab is a supported YouTube video page.
- Popup controller → Config: read config · Uses configured API endpoint and timeout settings.
- Popup controller → API client: fetch transcript · Requests transcript data once a valid video page is found.
- API client → Transcript API: REST call · Sends network requests to the external transcript service.
- API client → Contract: shape response · Normalizes or validates remote payloads before use.
- Popup controller → UI helpers: render states · Updates loading, transcript, empty, and error views.
- Popup shell → UI helpers: mount UI · Provides the DOM scaffold for rendering helpers.
- UI helpers → Styles: style UI · Presentation layer for the popup interface.
- Popup controller → Contract: consume contract · Relies on the stable transcript shape for rendering and copy actions.
- API tests → API client: verify client · Exercises request behavior and error handling.
- Contract tests → Contract: verify shape · Exercises transcript normalization and validation.
- Release flow → Package config: release steps · Uses project scripts and metadata during automation.
