# freetubeapp/freetube architecture

> Architecture diagram of the GitHub repository freetubeapp/freetube, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/freetubeapp/freetube
- Repository: https://github.com/freetubeapp/freetube

## Overview

##### Main Components
- Electron Main Process:
– Located in the “src/main” folder (e.g., index.js, ImageCache.js, poTokenGenerator.js).
– Manages the application lifecycle (window creation and process management) and core operations like caching or update-related tasks.
- Renderer Process (UI):
– Found in the “src/renderer” folder.
– Contains UI views, components (mostly .vue with accompanying CSS/JS), state management store (modules in “src/renderer/store”), router configuration, and helper functions.
- Data and API Layers:
– The “src/datastores” and “src/helpers/api” directories indicate modules handling data extraction, API calls (connecting to YouTube via built-in extractor or the Invidious API), and local data management (for subscriptions, history, etc.).
- Build and Configuration:
– Look at the “_scripts” directory, several Webpack configuration files, Babel configuration (.babelrc), ESLint and stylelint configuration, and GitHub Actions workflows. These form the build, linting, and deployment orchestration.
- Localization & Static Assets:
– Directories such as “static/locales” and “static/geolocations” hold the translation and region-specific files.
– The “static” folder also contains assets like JSON configuration for external players.
- External Integrations:
– Integration with Invidious API (as noted in the README) and support for browser extensions (redirect links) are key external elements informing the app’s connectivity and privacy features.

##### Out the Relationships and Interactions
- Between Main and Renderer Processes:
- Data Flow from UI to Data Stores/API:
– Show how user interactions in the Renderer (via Vue components and state managed by Vuex or similar) trigger calls to helper modules and API endpoints (both the built-in extractor and Invidious alternative).
- Build Pipeline and Configuration:
– Represent build components (Webpack bundlers, Babel transpilation, ESLint checks) and Continuous Integration (GitHub Actions) as separate pipeline stages that produce or test the application snapshots.
- Localization and Assets Handling:
– Indicate how static assets and localization files feed into the UI components to render multiple languages and regional settings.

##### Architectural Patterns & Design Principles
- Electron’s Separation of Concerns:
- Modular Component Design in the Renderer:
– The directory structure of “components”, “views” and “store” demonstrates an organized MV* (or modular) approach. Show these as subcomponents feeding into the overall renderer UI.
- Extensibility Points & API Abstraction:
– The extraction and proxy settings as well as configurable external API integrations (e.g., Invidious) hint at well-defined extension points. Represent these as gateway modules interfacing with external services.
- Build & Deployment Automation:

##### Technologies and Frameworks to Call Out
- Electron for cross-platform desktop deployments.
- Vue (and possibly React elements, though the predominant usage of .vue files suggests Vue) for the renderer components.
- Webpack, Babel, ESLint, and Stylelint for building, transpiling, and enforcing code style.
- GitHub Actions (CI/CD) to automate builds, tests, releases, and dependency management.
- The Invidious API (as an optional data source) and internal video extraction mechanisms.
- Localization frameworks, indicated by region-specific YAML and JSON files.

##### Specific Elements
- Labels:
– For each component, such as “Electron Main Process”, “Renderer Process (UI)”, “Data Store”, “API Extractor”, “Localization Module”, “Build Pipeline”, and “External Integrations (Invidious, Proxy Settings)”.
– Illustrate communication channels (e.g., IPC between main and renderer, API fetch calls from helper modules).
- Annotations:
– Add notes indicating the purpose of each module (e.g., “Handles user authentication and window management” for the Main Process, “Manages UI state and component composition” for the Renderer).

##### Final Assembly
- Electron Main Process (with components like ImageCache, poTokenGenerator)
- Renderer Process (subdivided into Views, Components, Store, Router)
- API/Data and External Services (showing connectors for YouTube extraction and localization)
- A side or bottom section that outlines the build toolchain and continuous integration components that automatically test, lint, and build the codebase (referencing files in “_scripts”, GitHub Actions workflows, package.json).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Backend (Electron Main Process)
    subgraph "Backend (Electron Main Process)"
        b1["Main (index.js)"]:::backend
        b2["Image Cache (ImageCache.js)"]:::backend
        b3["PO Token Generator (poTokenGenerator.js)"]:::backend
    end

    %% Frontend (Renderer Process)
    subgraph "Frontend (Renderer Process)"
        f1["UI (Renderer)"]:::frontend
        f2["Components"]:::frontend
        f3["Views"]:::frontend
        f4["Store"]:::frontend
        f5["Router"]:::frontend
        f6["Helpers (API)"]:::frontend
    end

    %% Data & API Layers
    subgraph "Data & API Layers"
        d1["Datastores"]:::api
        d2["Invidious API"]:::api
        d3["Player Cache"]:::api
    end

    %% Build & Configuration
    subgraph "Build & Configuration"
        build1["Webpack BotGuard"]:::build
        build2["Webpack Main"]:::build
        build3["Webpack Renderer"]:::build
        build4["CI/CD Workflows"]:::build
        build5["Lint & Config Files"]:::build
    end

    %% Localization & Static Assets
    subgraph "Localization & Static Assets"
        ls1["Locales"]:::static
        ls2["Geolocations"]:::static
        ls3["External Player Map"]:::static
        ls4["Manifest"]:::static
        ls5["Invidious Instances"]:::static
    end

    %% Connections Between Major Components
    b1 -->|"IPC"| f1
    %% Internal connections in Backend
    b2 -->|"Service"| b1
    b3 -->|"Service"| b1

    %% Renderer internal structure
    f1 --> f2
    f1 --> f3
    f1 --> f4
    f1 --> f5
    f1 --> f6

    %% Renderer communicates with Data & API Layers
    f1 -->|"UserAction"| d1
    f1 -->|"APICall"| d2
    f1 -->|"CacheLookup"| d3

    %% Helpers in Renderer interface with API modules
    f6 -->|"HelperCall"| d2
    f6 -->|"HelperCall"| d3

    %% Renderer loads Localization & Static Assets
    f1 -->|"Loads"| ls1
    f1 -->|"Loads"| ls2
    f1 -->|"Loads"| ls3
    f1 -->|"Loads"| ls4
    f1 -->|"Loads"| ls5

    %% Build pipeline influences Backend and Renderer
    build1 -->|"Build"| b1
    build2 -->|"Build"| b1
    build3 -->|"Build"| f1
    build4 -->|"CI/CD"| b1
    build4 -->|"CI/CD"| f1
    build5 -->|"Config"| f1

    %% Click Events
    click b1 "https://github.com/freetubeapp/freetube/blob/development/src/main/index.js"
    click b2 "https://github.com/freetubeapp/freetube/blob/development/src/main/ImageCache.js"
    click b3 "https://github.com/freetubeapp/freetube/blob/development/src/main/poTokenGenerator.js"
    click f1 "https://github.com/freetubeapp/freetube/tree/development/src/renderer"
    click f2 "https://github.com/freetubeapp/freetube/tree/development/src/renderer/components"
    click f3 "https://github.com/freetubeapp/freetube/tree/development/src/renderer/views"
    click f4 "https://github.com/freetubeapp/freetube/tree/development/src/renderer/store"
    click f5 "https://github.com/freetubeapp/freetube/tree/development/src/renderer/router"
    click f6 "https://github.com/freetubeapp/freetube/tree/development/src/renderer/helpers/api"
    click d1 "https://github.com/freetubeapp/freetube/tree/development/src/datastores"
    click d2 "https://github.com/freetubeapp/freetube/blob/development/src/renderer/helpers/api/invidious.js"
    click d3 "https://github.com/freetubeapp/freetube/blob/development/src/renderer/helpers/api/PlayerCache.js"
    click build1 "https://github.com/freetubeapp/freetube/blob/development/_scripts/webpack.botGuardScript.config.js"
    click build2 "https://github.com/freetubeapp/freetube/blob/development/_scripts/webpack.main.config.js"
    click build3 "https://github.com/freetubeapp/freetube/blob/development/_scripts/webpack.renderer.config.js"
    click build4 "https://github.com/freetubeapp/freetube/tree/development/.github/workflows"
    click build5 "https://github.com/freetubeapp/freetube/blob/development/.babelrc"
    click ls1 "https://github.com/freetubeapp/freetube/tree/development/static/locales"
    click ls2 "https://github.com/freetubeapp/freetube/tree/development/static/geolocations"
    click ls3 "https://github.com/freetubeapp/freetube/blob/development/static/external-player-map.json"
    click ls4 "https://github.com/freetubeapp/freetube/blob/development/static/manifest.json"
    click ls5 "https://github.com/freetubeapp/freetube/blob/development/static/invidious-instances.json"

    %% Styles
    classDef backend fill:#f9c74f,stroke:#333,stroke-width:2px;
    classDef frontend fill:#90be6d,stroke:#333,stroke-width:2px;
    classDef api fill:#f94144,stroke:#333,stroke-width:2px;
    classDef build fill:#577590,stroke:#333,stroke-width:2px;
    classDef static fill:#f3722c,stroke:#333,stroke-width:2px;
```
