# ftde0/yt2009 architecture

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

- Interactive diagram: https://gitdiagram.com/ftde0/yt2009
- Repository: https://github.com/ftde0/yt2009

## Overview

##### Main Components

- Frontend UI:
- The bulk of the HTML pages (e.g., index.htm, auth.html, account.html, various *.htm files found in the project root and in subdirectories such as mobile and static_pages) power the user-facing interface.
- Assets like CSS, JavaScript, images, and video files are stored under the “assets” folder (and even “player-imgs”, “doc-imgs”). They support dynamic styling, script behavior, and multimedia content.
- Legacy Flash support is installed through multiple SWF files in directories like “alt-swf”, “leanback”, “xl”, etc., integrating with both the legacy HTML interfaces and fallback media players.

- Backend Server:
- The “back” directory contains the Node.js backend files (for example, backend.js, backend_wrap.js, and multiple caching modules under “cache_dir”) that provide server-side logic, API endpoints, and caching for requests.
- It also includes language data, protocol buffers (proto/) for various mobile and annotation functionalities, and numerous modules to support application features.

- Asset Management & Caching:
- The “assets” folder holds downloaded content (images, videos, CSS/JS assets) that are referenced by both the frontend and the backend.
- The “back/cache_dir” folder indicates a caching system managing annotations, playlists, search results, etc.

- Containerization & Deployment:
- A Dockerfile and associated docker-entrypoint scripts signal a containerized deployment option.
- In addition, documentation files like docker.md provide instructions for running the entire system in a Docker container.

- Optional Components:
- The README describes an optional Android app setup (with instructions in apk_setup.md), so it would be good to note the potential integration or parallel deployment path.

##### Relationships and Interactions

- Request Flow:
- The user’s browser (or mobile device) requests pages that are served as static HTML/CSS/JS from the host.
- The Node.js backend (running from the “back” folder) serves dynamic content, processes API calls, handles caching, and likely orchestrates retrieval of assets.
- Assets such as SWF files, images, and media content are served from dedicated asset directories.

- Data Flow & Caching:
- The backend interacts with its caching modules (in “back/cache_dir”) to speed up response times for repeated requests.
- There is also communication between the backend and supplementary modules for processing language data, protocol-based requests (through the proto/ directory), and other video-related functionalities.

- Deployment and External Dependencies:
- Included in the setup are tools like ImageMagick and FFmpeg, which are prerequisites for media processing, likely involved in preparing images and video data.
- Docker is available to simplify the deployment process.

##### Architectural Patterns and Design Principles

- Separation of Concerns:
- There is a clear division between static frontend components (HTML/CSS/JS/assets) and the dynamic backend (Node.js server and caching modules).

- Legacy and Modern Integration:
- Modern deployment is supported via Node.js and Docker, while legacy frontends are maintained through legacy assets (SWF files, older HTML pages).

- Configurability and Extensibility:
- Multiple configuration files (e.g., config_params.md and various JSON config files) ensure that the system can be modified easily.
- Optional setup steps for Android integration illustrate an extensible design.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Browser
    U("User Browser"):::user

    %% Frontend UI Cluster
    subgraph "Frontend UI"
        subgraph "Static Content"
            RootHTML("Root HTML"):::frontend
            Mobile("Mobile"):::frontend
            StaticPages("Static Pages"):::frontend
        end
        subgraph "Legacy Flash"
            AltSWF("ALT SWF"):::legacy
            Leanback("Leanback"):::legacy
            XL("XL Flash"):::legacy
        end
    end

    %% Backend Server Cluster
    subgraph "Backend Server"
        API("API Logic"):::backend
        Cache("Caching Module"):::backend
        Lang("Language Data"):::backend
        Proto("Protocol Buffers"):::backend
    end

    %% Asset Repository Cluster
    subgraph "Asset Repository"
        Assets("Assets"):::assets
        PlayerImgs("Player Images"):::assets
        DocImgs("Document Images"):::assets
    end

    %% Containerization & Deployment Cluster
    subgraph "Containerization & Deployment"
        DockerCont("Docker Container"):::deployment
        Dockerfile("Dockerfile"):::deployment
        EntrypointJS("docker-entrypoint.js"):::deployment
        EntrypointSH("docker-entrypoint.sh"):::deployment
        DockerMD("docker.md"):::deployment
    end

    %% Optional Android Integration
    Android("Android APK Setup"):::optional

    %% Relationships
    U -->|"PageRequest"| RootHTML
    U -->|"AndroidAppRequest"| Android

    %% Frontend to Backend Connections
    RootHTML -->|"API_Call"| API
    Mobile -->|"API_Call"| API
    StaticPages -->|"API_Call"| API
    AltSWF -->|"SupportsUI"| RootHTML
    Leanback -->|"SupportsUI"| RootHTML
    XL -->|"SupportsUI"| RootHTML

    %% Backend Internal Communications
    API -->|"CacheLookup"| Cache
    API -->|"LanguageProc"| Lang
    API -->|"ProtoCall"| Proto

    %% Backend to Asset Repository
    API -->|"AssetRequest"| Assets
    API -->|"AssetRequest"| PlayerImgs
    API -->|"AssetRequest"| DocImgs

    %% Deployment Linkages
    RootHTML -->|"Deployed_in"| DockerCont
    API -->|"Deployed_in"| DockerCont
    Assets -->|"Deployed_in"| DockerCont

    DockerCont -->|"Setup"| Dockerfile
    DockerCont -->|"Setup"| EntrypointJS
    DockerCont -->|"Setup"| EntrypointSH
    DockerCont -->|"Setup"| DockerMD

    %% Styles
    classDef user fill:#f9e79f,stroke:#333,stroke-width:2px;
    classDef frontend fill:#aed6f1,stroke:#333,stroke-width:2px;
    classDef legacy fill:#fdfd96,stroke:#333,stroke-width:2px;
    classDef backend fill:#f1948a,stroke:#333,stroke-width:2px;
    classDef assets fill:#82e0aa,stroke:#333,stroke-width:2px;
    classDef deployment fill:#d7dbdd,stroke:#333,stroke-width:2px;
    classDef optional fill:#f7dc6f,stroke:#333,stroke-width:2px;

    %% Click Events
    click RootHTML "https://github.com/ftde0/yt2009/blob/main/index.htm"
    click Mobile "https://github.com/ftde0/yt2009/tree/main/mobile"
    click StaticPages "https://github.com/ftde0/yt2009/tree/main/static_pages"
    click AltSWF "https://github.com/ftde0/yt2009/tree/main/alt-swf"
    click Leanback "https://github.com/ftde0/yt2009/tree/main/leanback"
    click XL "https://github.com/ftde0/yt2009/blob/main/xl/apiplayer.swf"
    click API "https://github.com/ftde0/yt2009/tree/main/back"
    click Cache "https://github.com/ftde0/yt2009/tree/main/back/cache_dir"
    click Lang "https://github.com/ftde0/yt2009/tree/main/back/language_data"
    click Proto "https://github.com/ftde0/yt2009/tree/main/back/proto"
    click Assets "https://github.com/ftde0/yt2009/tree/main/assets"
    click PlayerImgs "https://github.com/ftde0/yt2009/tree/main/player-imgs"
    click DocImgs "https://github.com/ftde0/yt2009/tree/main/doc-imgs"
    click DockerCont "https://github.com/ftde0/yt2009/tree/main/Dockerfile"
    click Dockerfile "https://github.com/ftde0/yt2009/tree/main/Dockerfile"
    click EntrypointJS "https://github.com/ftde0/yt2009/blob/main/docker-entrypoint.js"
    click EntrypointSH "https://github.com/ftde0/yt2009/blob/main/docker-entrypoint.sh"
    click DockerMD "https://github.com/ftde0/yt2009/blob/main/docker.md"
    click Android "https://github.com/ftde0/yt2009/blob/main/apk_setup.md"
```
