# glymehrvrd/yt-sub-bot architecture

> Architecture diagram of the GitHub repository glymehrvrd/yt-sub-bot, 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/glymehrvrd/yt-sub-bot
- Repository: https://github.com/glymehrvrd/yt-sub-bot

## Overview

##### Project Type and Purpose
- Although the README mentions “Vue 3 + TypeScript + Vite,” the file tree indicates a structure more typical of a Next.js application (with an “app” folder containing layout.tsx, page.tsx, and an “api” directory with route handlers). In addition, the “lib” folder contains business logic modules (downloader, subtitle-manager, translator, tts, utils) suggesting that this application involves media processing (likely handling subtitles, translations, text-to-speech, and downloads).
- Therefore, treat the project as a full-stack web application that leverages a modern React-based framework (Next.js) to provide both client-side UI components and server-side API routes for multimedia processing tasks.

##### File Structure
- Frontend (Client/UI):
– All UI components live under the “app” directory: “page.tsx” (landing page), “layout.tsx”, and additional React components in “app/components” (e.g., FileList, Toast, UrlForm).
– “app/globals.css” is used for styling.
– “app/services” and “app/types” indicate where client-specific business logic and TypeScript type definitions are maintained.
- Backend (API/Server):
– The “app/api” directory (e.g., “app/api/subtitle/route.ts”) suggests serverless functions or API endpoints that facilitate operations such as handling subtitle data.
- Core Business Logic:
– The “lib” directory contains modules that perform the heavy lifting like downloading, subtitle management, translation, and text-to-speech (tts) functionality.
- Testing & Documentation:
– The “__tests__” directory includes test files (e.g., “tts.test.ts”) to verify functionality.
– The “docs” directory (e.g., “docs/task-system.md”) likely provides further system-level insights.
- Configuration & Infrastructure:
– Files like “Dockerfile”, “.dockerignore”, “next.config.mjs”, “tsconfig.json”, “package.json”, and “jest.config.ts” indicate support for containerization, TypeScript configuration, and testing.

##### Main Components & Their Relationships
a. Frontend/UI:
– The main application view is powered by Next.js components (layout.tsx, page.tsx, & other UI components).
– Client-side services (in “app/services”) act as wrappers or connectors to the backend APIs.
b. Backend/API:
– API endpoints in “app/api/…” serve as the communication stroke between the user interface and the core business logic.
– These endpoints call upon the modules in “lib” to perform operations such as downloading media files, managing subtitles, translating text, and generating text-to-speech outputs.
c. Core Business Logic:
– The “lib” directory contains separate modules responsible for different aspects of processing. For example, the subtitle-manager handles subtitle operations, while tts.ts manages speech synthesis.
d. Supporting Infrastructure:
– Containerization via Docker (Dockerfile and .dockerignore) allows for a consistent runtime environment.
– Testing is conducted through Jest (jest.config.ts and __tests__ folder) ensuring code reliability.

- Create distinct blocks for each area:
- A "Client" block representing the Next.js frontend (including components and services).
- A "Backend API" block showing routes under “app/api” which interact with the core processing modules.
- A "Business Logic" block representing modules in the “lib” folder (downloader, subtitle-manager, translator, tts, utils).
- Infrastructure-related blocks for "Testing", "Configuration", and "Docker/Deployment".
- How user requests flow from the UI to the API endpoints.
- That API handlers call the modules in “lib” to perform their tasks, and the results are returned back to the UI.
- Interactions:
- For example, a request from a “UrlForm” component might trigger a service call (from “app/services”) that interacts with an API endpoint (in “app/api/subtitle/route.ts”), which then invokes “translator.ts” or “tts.ts” in “lib”.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        Layout["Layout (UI)"]:::frontend
        Page["Page (UI)"]:::frontend
        subgraph "UI Components"
            FileList["FileList Component"]:::frontend
            Toast["Toast Component"]:::frontend
            UrlForm["UrlForm Component"]:::frontend
        end
        GlobalCSS["Global Styles"]:::frontend
    end

    %% Client-Side Services
    subgraph "Client-Side Services"
        APISvc["API Service"]:::frontend
        Types["Types"]:::frontend
    end

    %% Backend API
    subgraph "Backend API"
        SubtitleAPI["Subtitle API Route"]:::backend
    end

    %% Core Business Logic
    subgraph "Core Business Logic"
        Downloader["Downloader Module"]:::core
        SubtitleManager["Subtitle Manager Module"]:::core
        Translator["Translator Module"]:::core
        TTS["TTS Module"]:::core
        Utils["Utils Module"]:::core
    end

    %% Infrastructure
    subgraph "Infrastructure"
        Testing["Testing Infrastructure"]:::infra
        Documentation["Documentation"]:::infra
        Dockerfile["Dockerfile"]:::infra
        Dockerignore[".dockerignore"]:::infra
        NextConfig["next.config.mjs"]:::infra
        Tsconfig["tsconfig.json"]:::infra
        JestConfig["jest.config.ts"]:::infra
    end

    %% Data Flow Connections
    %% Frontend interactions
    Page -->|"triggers"| FileList
    UrlForm -->|"submits data"| APISvc
    APISvc -->|"API call"| SubtitleAPI

    %% API calling Core Business Logic
    SubtitleAPI -->|"invokes"| Downloader
    SubtitleAPI -->|"invokes"| SubtitleManager
    SubtitleAPI -->|"invokes"| Translator
    SubtitleAPI -->|"invokes"| TTS
    SubtitleAPI -->|"invokes"| Utils

    %% Response Flow
    SubtitleAPI -->|"response"| APISvc
    APISvc -->|"updates UI"| FileList

    %% Styling Connections (Infrastructure supports all layers)
    Dockerfile -.-> Layout
    Dockerignore -.-> Page
    NextConfig -.-> SubtitleAPI
    Tsconfig -.-> APISvc
    JestConfig -.-> Testing

    %% Class Definitions
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef core fill:#FFA500,stroke:#000,stroke-width:1px;
    classDef infra fill:#DDA0DD,stroke:#000,stroke-width:1px;

    %% Click Events for Frontend Components
    click Layout "https://github.com/glymehrvrd/yt-sub-bot/blob/master/app/layout.tsx"
    click Page "https://github.com/glymehrvrd/yt-sub-bot/blob/master/app/page.tsx"
    click FileList "https://github.com/glymehrvrd/yt-sub-bot/blob/master/app/components/FileList.tsx"
    click Toast "https://github.com/glymehrvrd/yt-sub-bot/blob/master/app/components/Toast.tsx"
    click UrlForm "https://github.com/glymehrvrd/yt-sub-bot/blob/master/app/components/UrlForm.tsx"
    click GlobalCSS "https://github.com/glymehrvrd/yt-sub-bot/blob/master/app/globals.css"

    %% Click Events for Client-Side Services
    click APISvc "https://github.com/glymehrvrd/yt-sub-bot/blob/master/app/services/api.ts"
    click Types "https://github.com/glymehrvrd/yt-sub-bot/blob/master/app/types/files.ts"

    %% Click Event for Backend API
    click SubtitleAPI "https://github.com/glymehrvrd/yt-sub-bot/blob/master/app/api/subtitle/route.ts"

    %% Click Events for Core Business Logic Modules
    click Downloader "https://github.com/glymehrvrd/yt-sub-bot/blob/master/lib/downloader.ts"
    click SubtitleManager "https://github.com/glymehrvrd/yt-sub-bot/blob/master/lib/subtitle-manager.ts"
    click Translator "https://github.com/glymehrvrd/yt-sub-bot/blob/master/lib/translator.ts"
    click TTS "https://github.com/glymehrvrd/yt-sub-bot/blob/master/lib/tts.ts"
    click Utils "https://github.com/glymehrvrd/yt-sub-bot/blob/master/lib/utils.ts"

    %% Click Events for Infrastructure
    click Testing "https://github.com/glymehrvrd/yt-sub-bot/blob/master/__tests__/tts.test.ts"
    click Documentation "https://github.com/glymehrvrd/yt-sub-bot/blob/master/docs/task-system.md"
    click Dockerfile "https://github.com/glymehrvrd/yt-sub-bot/tree/master/Dockerfile"
    click Dockerignore "https://github.com/glymehrvrd/yt-sub-bot/blob/master/.dockerignore"
    click NextConfig "https://github.com/glymehrvrd/yt-sub-bot/blob/master/next.config.mjs"
    click Tsconfig "https://github.com/glymehrvrd/yt-sub-bot/blob/master/tsconfig.json"
    click JestConfig "https://github.com/glymehrvrd/yt-sub-bot/blob/master/jest.config.ts"
```
