# aditauqir/fyp architecture

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

- Interactive diagram: https://gitdiagram.com/aditauqir/fyp
- Repository: https://github.com/aditauqir/fyp

## Overview

#### Purpose and deployment targets
FYouTube Premium is a browser-extension project that uses desktop YouTube as its backend while reshaping it for iPhone/Orion into a mobile-oriented, Premium-like experience: inline playback, background audio, ad blocking, simplified navigation, and responsive feed/search layouts. It has parallel Chrome/Manifest V3 and Firefox-compatible packages, with Orion consuming generated ZIP/XPI artifacts.

Paths: `chrome-extension/manifest.json`, `firefox-extension/manifest.json`, `rebuild-extension.sh`

#### Runtime entry points
Each extension package has three browser execution contexts:
- **Content script** runs on YouTube pages, injects/coordinates page-facing behavior, and applies UI transformations.
- **Page script** executes in the page context for direct interaction with YouTube’s player/application environment.
- **Background script** owns extension-level state, scheduled release checks, toolbar badge updates, and message handling.
- **Popup** provides changelog, navigation to YouTube, and manual update checking.

Paths: `chrome-extension/content.js`, `chrome-extension/page.js`, `chrome-extension/background.js`

#### YouTube transformation pipeline
The content/page layer selects the desktop YouTube experience and continuously adapts its dynamic SPA DOM into a phone-friendly interface. Major transformations include inline full-width player layout and controls, one-column watch/feed/playlist layouts, mobile search, hamburger-centered navigation, and comments/action-card handling. Because YouTube rerenders navigation and player surfaces, this layer must observe and reapply changes across route/state changes.

Paths: `chrome-extension/content.js`, `chrome-extension/page.js`, `firefox-extension/content.template.js`

#### Playback, media-session, and captions boundary
Page-context code manages browser-visible playback behavior that content scripts cannot reliably control alone: player state, inline controls, background/screen-off playback, and Media Session ownership for lock-screen controls. Caption handling constrains active tracks to one preferred track, deduplicates subtitle UI, and preserves user language selection behavior.

Paths: `chrome-extension/page.js`, `chrome-extension/content.js`, `firefox-extension/page.js`

#### Ad-blocking and YouTube network/player integration
The extension incorporates YouTube-specific ad blocking adapted from Universal Ad Blocker Pro. This is a high-risk compatibility boundary: it interacts with YouTube player, network, and overlay behavior rather than using YouTube APIs, and must coexist with YouTube’s evolving client-side application and playback lifecycle.

Paths: `chrome-extension/page.js`, `firefox-extension/page.js`

#### Extension UI and GitHub update flow
The popup queries the background runtime for version/update state and exposes user actions. The background periodically contacts GitHub Releases, compares the installed manifest version against the latest release, and sets an `UP` badge when an update is available. Updates remain manual because Orion does not replace sideloaded extensions automatically.

Paths: `chrome-extension/popup.js`, `chrome-extension/background.js`, `chrome-extension/popup.html`

#### Cross-browser packaging and release boundary
Chrome and Firefox source trees are maintained separately, likely due to manifest/runtime compatibility and Orion fallback packaging requirements. The build script validates generated JavaScript and emits the recommended Orion release ZIP plus Chrome ZIP, Firefox ZIP, Orion ZIP, and XPI artifacts. Release distribution is externalized to GitHub Releases.

Paths: `chrome-extension/`, `firefox-extension/`, `rebuild-extension.sh`

Main entry points: [`chrome-extension/page.js`](https://github.com/aditauqir/fyp/blob/main/chrome-extension/page.js) (Page script), [`chrome-extension/background.js`](https://github.com/aditauqir/fyp/blob/main/chrome-extension/background.js) (Background script), [`chrome-extension/manifest.json`](https://github.com/aditauqir/fyp/blob/main/chrome-extension/manifest.json) (MV3 manifest), [`chrome-extension/content.js`](https://github.com/aditauqir/fyp/blob/main/chrome-extension/content.js) (Content script)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_chrome["Chrome / MV3 package"]
  node_chrome_manifest["MV3 manifest<br/>extension manifest<br/>[manifest.json]"]
  node_content["Content script<br/>DOM coordinator<br/>[content.js]"]
  node_page["Page script<br/>page runtime<br/>[page.js]"]
  node_ui_pipeline["Mobile UI transforms<br/>transformation pipeline<br/>[content.js]"]
  node_playback["Playback and captions<br/>media control<br/>[page.js]"]
  node_adblock["YouTube ad blocking<br/>player/network integration<br/>[page.js]"]
  node_background["Background script<br/>extension state<br/>[background.js]"]
  node_popup["Popup UI<br/>extension UI<br/>[popup.html]"]
  node_popup_logic["Popup controller<br/>popup runtime<br/>[popup.js]"]
end

subgraph group_firefox["Firefox-compatible package"]
  node_firefox_manifest["Firefox manifest<br/>extension manifest<br/>[manifest.json]"]
  node_firefox_content["Firefox content template<br/>DOM coordinator"]
  node_firefox_page["Firefox page script<br/>page runtime<br/>[page.js]"]
end

subgraph group_release["Build and distribution"]
  node_build{{"Rebuild script<br/>packaging pipeline"}}
  node_artifacts["Extension artifacts<br/>ZIP / XPI packages"]
  node_github{{"GitHub Releases<br/>release service"}}
end

node_youtube{{"YouTube desktop app<br/>external web application"}}
node_orion{{"Orion browser<br/>distribution target"}}

node_chrome_manifest -->|"loads"| node_content
node_chrome_manifest -->|"injects"| node_page
node_chrome_manifest -->|"starts"| node_background
node_chrome_manifest -->|"declares"| node_popup
node_content -->|"applies"| node_ui_pipeline
node_content -->|"coordinates with"| node_page
node_content -->|"observes SPA DOM"| node_youtube
node_page -->|"manages"| node_playback
node_page -->|"integrates"| node_adblock
node_page -->|"controls player/app"| node_youtube
node_ui_pipeline -->|"reshapes UI"| node_youtube
node_popup -->|"runs"| node_popup_logic
node_popup_logic -->|"queries and requests checks"| node_background
node_background -->|"checks latest release"| node_github
node_background -->|"returns update state"| node_popup_logic
node_firefox_manifest -->|"loads"| node_firefox_content
node_firefox_manifest -->|"injects"| node_firefox_page
node_firefox_content -->|"adapts DOM"| node_youtube
node_firefox_page -->|"controls player/app"| node_youtube
node_build -->|"emits"| node_artifacts
node_artifacts -->|"published to"| node_github
node_artifacts -->|"sideloaded into"| node_orion
node_github -.->|"release metadata"| node_background

click node_chrome_manifest "https://github.com/aditauqir/fyp/blob/main/chrome-extension/manifest.json"
click node_content "https://github.com/aditauqir/fyp/blob/main/chrome-extension/content.js"
click node_page "https://github.com/aditauqir/fyp/blob/main/chrome-extension/page.js"
click node_ui_pipeline "https://github.com/aditauqir/fyp/blob/main/chrome-extension/content.js"
click node_playback "https://github.com/aditauqir/fyp/blob/main/chrome-extension/page.js"
click node_adblock "https://github.com/aditauqir/fyp/blob/main/chrome-extension/page.js"
click node_background "https://github.com/aditauqir/fyp/blob/main/chrome-extension/background.js"
click node_popup "https://github.com/aditauqir/fyp/blob/main/chrome-extension/popup.html"
click node_popup_logic "https://github.com/aditauqir/fyp/blob/main/chrome-extension/popup.js"
click node_firefox_manifest "https://github.com/aditauqir/fyp/blob/main/firefox-extension/manifest.json"
click node_firefox_content "https://github.com/aditauqir/fyp/blob/main/firefox-extension/content.template.js"
click node_firefox_page "https://github.com/aditauqir/fyp/blob/main/firefox-extension/page.js"
click node_build "https://github.com/aditauqir/fyp/blob/main/rebuild-extension.sh"

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_chrome_manifest,node_content,node_page,node_ui_pipeline,node_playback,node_adblock,node_background,node_popup,node_popup_logic toneBlue
class node_firefox_manifest,node_firefox_content,node_firefox_page toneAmber
class node_build,node_artifacts,node_github toneMint
class node_youtube,node_orion toneNeutral
```

## Components

### Chrome / MV3 package

- [MV3 manifest](https://github.com/aditauqir/fyp/blob/main/chrome-extension/manifest.json): extension manifest · Declares Chrome extension contexts and permissions. · `chrome-extension/manifest.json`
- [Content script](https://github.com/aditauqir/fyp/blob/main/chrome-extension/content.js): DOM coordinator · Adapts YouTube SPA surfaces and coordinates page-facing behavior. · `chrome-extension/content.js`
- [Page script](https://github.com/aditauqir/fyp/blob/main/chrome-extension/page.js): page runtime · Controls YouTube player, network hooks, and page-owned browser APIs. · `chrome-extension/page.js`
- [Mobile UI transforms](https://github.com/aditauqir/fyp/blob/main/chrome-extension/content.js): transformation pipeline · Reapplies responsive player, feed, search, navigation, comments, and action layouts. · `chrome-extension/content.js`
- [Playback and captions](https://github.com/aditauqir/fyp/blob/main/chrome-extension/page.js): media control · Owns inline/background playback, Media Session, and preferred caption-track behavior. · `chrome-extension/page.js`
- [YouTube ad blocking](https://github.com/aditauqir/fyp/blob/main/chrome-extension/page.js): player/network integration · Intercepts YouTube player, network, and overlay ad behavior. · `chrome-extension/page.js`
- [Background script](https://github.com/aditauqir/fyp/blob/main/chrome-extension/background.js): extension state · Handles messages, scheduled release checks, and update badge state. · `chrome-extension/background.js`
- [Popup UI](https://github.com/aditauqir/fyp/blob/main/chrome-extension/popup.html): extension UI · Shows changelog, YouTube navigation, and manual update actions. · `chrome-extension/popup.html`
- [Popup controller](https://github.com/aditauqir/fyp/blob/main/chrome-extension/popup.js): popup runtime · `chrome-extension/popup.js`

### Firefox-compatible package

- [Firefox manifest](https://github.com/aditauqir/fyp/blob/main/firefox-extension/manifest.json): extension manifest · `firefox-extension/manifest.json`
- [Firefox content template](https://github.com/aditauqir/fyp/blob/main/firefox-extension/content.template.js): DOM coordinator · Firefox-compatible variant of the YouTube transformation layer. · `firefox-extension/content.template.js`
- [Firefox page script](https://github.com/aditauqir/fyp/blob/main/firefox-extension/page.js): page runtime · Firefox-compatible playback and ad-block integration. · `firefox-extension/page.js`

### Build and distribution

- [Rebuild script](https://github.com/aditauqir/fyp/blob/main/rebuild-extension.sh): packaging pipeline · Validates generated JavaScript and builds browser release artifacts. · `rebuild-extension.sh`
- **Extension artifacts**: ZIP / XPI packages · Produces recommended Orion ZIP plus Chrome, Firefox, Orion ZIP, and XPI packages.
- **GitHub Releases**: release service · Hosts published packages and latest-version metadata.

### Other components

- **YouTube desktop app**: external web application · Dynamic SPA and playback backend reshaped for mobile use.
- **Orion browser**: distribution target · Uses sideloaded artifacts and requires manual updates.

## Connections

- MV3 manifest → Content script: loads
- MV3 manifest → Page script: injects
- MV3 manifest → Background script: starts
- MV3 manifest → Popup UI: declares
- Content script → Mobile UI transforms: applies
- Content script → Page script: coordinates with
- Content script → YouTube desktop app: observes SPA DOM
- Page script → Playback and captions: manages
- Page script → YouTube ad blocking: integrates
- Page script → YouTube desktop app: controls player/app
- Mobile UI transforms → YouTube desktop app: reshapes UI
- Popup UI → Popup controller: runs
- Popup controller → Background script: queries and requests checks
- Background script → GitHub Releases: checks latest release
- Background script → Popup controller: returns update state
- Firefox manifest → Firefox content template: loads
- Firefox manifest → Firefox page script: injects
- Firefox content template → YouTube desktop app: adapts DOM
- Firefox page script → YouTube desktop app: controls player/app
- Rebuild script → Extension artifacts: emits
- Extension artifacts → GitHub Releases: published to
- Extension artifacts → Orion browser: sideloaded into
- GitHub Releases → Background script: release metadata
