# chuymaster/thaivtuberranking-frontend architecture

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

- Interactive diagram: https://gitdiagram.com/chuymaster/thaivtuberranking-frontend
- Repository: https://github.com/chuymaster/thaivtuberranking-frontend

## Overview

##### Main Components Identification
- Frontend (Flutter UI):
- Presentational components are located under lib/pages (with subdirectories like channel, home, live, video_ranking, etc.) and include UI widgets, pages, and components.
- Administrative UI components found under lib/admin (pages for authentication, channel management, channel requests).
- Business Logic / View Models:
- Each feature (channel, channel ranking, channel registration, live, etc.) has its corresponding view model (e.g., channel_view_model.dart, home_view_model.dart, video_ranking_view_model.dart). These encapsulate UI state and business logic.
- Data Layer / Repositories:
- The repositories in each domain (e.g., channel_repository, channel_management_repository, channel_request_repository, video_ranking_repository) abstract API calls and local data manipulations.
- Service Layer:
- Shared services like analytics, URL launching, routing, and environment settings are implemented under lib/services.
- State Management / Providers:
- Global state and data are provided via lib/providers (e.g., channel_list_provider).
- Localization:
- The localization support is managed in lib/l10n and lib/gen_l10n using generated localization files plus a helper class (L10n).
- Configuration and Build:
- Build/deployment related files include Makefile, CI/CD pipelines in .github workflows, and web configuration in the web folder.
- Testing:
- Corresponding unit and widget tests are located in the test directory.

##### Relationships and Interactions
- The UI (Flutter widgets) interacts with the corresponding View Models which encapsulate the business logic.
- View Models call into Repositories that manage data fetching and processing from APIs or local data.
- Providers supply shared data, as seen in the channel_list provider.
- Services (analytics, routing, URL launching) support cross-cutting concerns and interact with both UI and backend endpoints.
- Localization modules (lib/l10n and gen_l10n) are integrated into UI widgets to manage language and translations.
- Administrative components are separated logically and may have distinct routing and authentication mechanisms, as evidenced by the different directories under lib/admin.

##### Architectural Patterns and Design Principles
- MVVM Pattern: Clear separation between UI (views) and business logic (view models).
- Repository Pattern: Abstraction of network/data operations to dedicated repository classes.
- Modular Design: Separation of concerns across pages, components, services, and providers.
- Localization and Internationalization: Central management of multi-language support.
- Automated Testing and CI/CD: Presence of tests, GitHub workflows for build, test, and deployment.

##### Technologies, Frameworks, and Libraries
- Flutter for Web (UI framework).
- Dart as the programming language.
- Mocking via Mockito (for unit tests).
- GitHub Actions for CI/CD automation, along with Netlify for deployment.
- Built-in localization framework provided by Flutter, leveraging ARB files.
- Firebase options file indicates potential integration for analytics or authentication.
- The Makefile for local command tasks and build orchestration.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        UI1["Channel Page"]:::ui
        UI2["Home Page"]:::ui
        UI3["Live Page"]:::ui
        UI4["Video Ranking Page"]:::ui
        UI5["Channel Registration Page"]:::ui
        UI6["Error Page"]:::ui
        subgraph "Admin UI"
            UI7["Admin Authentication"]:::uiAdmin
            UI8["Channel Management UI"]:::uiAdmin
            UI9["Channel Requests UI"]:::uiAdmin
        end
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        VM1["Channel ViewModel"]:::vm
        VM2["Home ViewModel"]:::vm
        VM3["Live ViewModel"]:::vm
        VM4["Video Ranking ViewModel"]:::vm
        VM5["Channel Registration ViewModel"]:::vm
        VM6["Admin Channel Management ViewModel"]:::vm
        VM7["Admin Channel Request ViewModel"]:::vm
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        REP1["Channel Repository"]:::repo
        REP2["Channel Registration Repository"]:::repo
        REP3["Live Repository"]:::repo
        REP4["Video Ranking Repository"]:::repo
        REP5["Admin Channel Management Repository"]:::repo
        REP6["Admin Channel Request Repository"]:::repo
        REP7["Channel List Repository"]:::repo
    end

    %% Service Layer
    subgraph "Service Layer"
        SVC1["Analytics Service"]:::service
        SVC2["URL Launcher Service"]:::service
        SVC3["Environment Settings"]:::service
        SVC4["Routing Service"]:::service
    end

    %% State Management / Providers
    subgraph "State Management / Providers"
        PROV1["Channel List Provider"]:::provider
        PROV2["Locale Provider"]:::provider
    end

    %% Localization & Configuration
    subgraph "Localization & Config"
        LOC1["Localization (l10n)"]:::localization
        LOC2["Generated Localization (gen_l10n)"]:::localization
        CFG1["Makefile"]:::config
        CFG2["GitHub Workflows"]:::config
        CFG3["Web Config"]:::config
    end

    %% Testing
    subgraph "Testing"
        TEST1["Tests"]:::test
    end

    %% Connections from Presentation to Business Logic
    UI1 -->|"calls"| VM1
    UI2 -->|"calls"| VM2
    UI3 -->|"calls"| VM3
    UI4 -->|"calls"| VM4
    UI5 -->|"calls"| VM5
    UI8 -->|"calls"| VM6
    UI9 -->|"calls"| VM7

    %% Connections from Business Logic to Data Access
    VM1 -->|"data"| REP1
    VM5 -->|"data"| REP2
    VM3 -->|"data"| REP3
    VM4 -->|"data"| REP4
    VM6 -->|"data"| REP5
    VM7 -->|"data"| REP6

    %% Provider supplies shared state to UI (example connection)
    PROV1 -->|"provides"| UI1
    PROV1 -->|"provides"| UI2

    %% UI interacts with Localization
    UI1 -.-> LOC1
    UI2 -.-> LOC1
    UI3 -.-> LOC1
    UI4 -.-> LOC1
    UI5 -.-> LOC1
    UI6 -.-> LOC1
    UI7 -.-> LOC1
    UI8 -.-> LOC1
    UI9 -.-> LOC1

    %% UI and others leverage Services (e.g., routing)
    UI1 -.-> SVC4
    UI2 -.-> SVC4
    UI3 -.-> SVC4

    %% Build / Config influences Testing
    CFG1 --> TEST1
    CFG2 --> TEST1

    %% Providers: Locale Provider example interaction with UI
    PROV2 -.-> UI1

    %% Style Classes
    classDef ui fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef uiAdmin fill:#BB8FCE,stroke:#6C3483,stroke-width:2px;
    classDef vm fill:#FAD7A0,stroke:#B7950B,stroke-width:2px;
    classDef repo fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
    classDef service fill:#D4E6F1,stroke:#2874A6,stroke-width:2px;
    classDef provider fill:#A3E4D7,stroke:#117864,stroke-width:2px;
    classDef localization fill:#F5CBA7,stroke:#7D6608,stroke-width:2px;
    classDef config fill:#82E0AA,stroke:#196F3D,stroke-width:2px;
    classDef test fill:#F1948A,stroke:#922B21,stroke-width:2px;

    %% Click Events for Frontend UI Pages
    click UI1 "https://github.com/chuymaster/thaivtuberranking-frontend/blob/main/lib/pages/channel/channel_page.dart"
    click UI2 "https://github.com/chuymaster/thaivtuberranking-frontend/blob/main/lib/pages/home/home_page.dart"
    click UI3 "https://github.com/chuymaster/thaivtuberranking-frontend/blob/main/lib/pages/live/live_page.dart"
    click UI4 "https://github.com/chuymaster/thaivtuberranking-frontend/blob/main/lib/pages/video_ranking/video_ranking_page.dart"
    click UI5 "https://github.com/chuymaster/thaivtuberranking-frontend/blob/main/lib/pages/channel_registration/channel_registration_page.dart"
    click UI6 "https://github.com/chuymaster/thaivtuberranking-frontend/blob/main/lib/pages/error/error_page.dart"

    %% Click Events for Administrative UI Components
    click UI7 "https://github.com/chuymaster/thaivtuberranking-frontend/blob/main/lib/admin/admin_auth_gate/admin_auth_gate_page.dart"
    click UI8 "https://github.com/chuymaster/thaivtuberranking-frontend/blob/main/lib/admin/channel_management/channel_management_page.dart"
    click UI9 "https://github.com/chuymaster/thaivtuberranking-frontend/blob/main/lib/admin/channel_request/channel_request_page.dart"

    %% Click Events for Business Logic / View Models
    click VM1 "https://github.com/chuymaster/thaivtuberranking-frontend/blob/main/lib/pages/channel/channel_view_model.dart"
    click VM2 "https://github.com/chuymaster/thaivtuberranking-frontend/blob/main/lib/pages/home/home_view_model.dart"
    click VM3 "https://github.com/chuymaster/thaivtuberranking-frontend/blob/main/lib/pages/live/live_view_model.dart"
    click VM4 "https://github.com/chuymaster/thaivtuberranking-frontend/blob/main/lib/pages/video_ranking/video_ranking_view_model.dart"
    click VM5 "https://github.com/chuymaster/thaivtuberranking-frontend/blob/main/lib/pages/channel_registration/channel_registration_view_model.dart"
    click VM6 "https://github.com/chuymaster/thaivtuberranking-frontend/blob/main/lib/admin/channel_management/channel_management_view_model.dart"
    click VM7 "https://github.com/chuymaster/thaivtuberranking-frontend/blob/main/lib/admin/channel_request/channel_request_view_model.dart"

    %% Click Events for Data Layer / Repositories
    click REP1 "https://github.com/chuymaster/thaivtuberranking-frontend/blob/main/lib/pages/channel/channel_repository.dart"
    click REP2 "https://github.com/chuymaster/thaivtuberranking-frontend/blob/main/lib/pages/channel_registration/channel_registration_repository.dart"
    click REP3 "https://github.com/chuymaster/thaivtuberranking-frontend/blob/main/lib/pages/live/live_repository.dart"
    click REP4 "https://github.com/chuymaster/thaivtuberranking-frontend/blob/main/lib/pages/video_ranking/video_ranking_repository.dart"
    click REP5 "https://github.com/chuymaster/thaivtuberranking-frontend/blob/main/lib/admin/channel_management/channel_management_repository.dart"
    click REP6 "https://github.com/chuymaster/thaivtuberranking-frontend/blob/main/lib/admin/channel_request/channel_request_repository.dart"
    click REP7 "https://github.com/chuymaster/thaivtuberranking-frontend/blob/main/lib/providers/channel_list/channel_list_repository.dart"

    %% Click Events for Service Layer
    click SVC1 "https://github.com/chuymaster/thaivtuberranking-frontend/blob/main/lib/services/analytics.dart"
    click SVC2 "https://github.com/chuymaster/thaivtuberranking-frontend/blob/main/lib/services/url_launcher.dart"
    click SVC3 "https://github.com/chuymaster/thaivtuberranking-frontend/blob/main/lib/services/environment_setting.dart"
    click SVC4 "https://github.com/chuymaster/thaivtuberranking-frontend/blob/main/lib/services/route/router.dart"

    %% Click Events for Providers
    click PROV1 "https://github.com/chuymaster/thaivtuberranking-frontend/blob/main/lib/providers/channel_list/channel_list_provider.dart"
    click PROV2 "https://github.com/chuymaster/thaivtuberranking-frontend/blob/main/lib/providers/locale_provider.dart"

    %% Click Events for Localization & Configuration
    click LOC1 "https://github.com/chuymaster/thaivtuberranking-frontend/tree/main/lib/l10n"
    click LOC2 "https://github.com/chuymaster/thaivtuberranking-frontend/tree/main/lib/gen_l10n"
    click CFG1 "https://github.com/chuymaster/thaivtuberranking-frontend/tree/main/Makefile"
    click CFG2 "https://github.com/chuymaster/thaivtuberranking-frontend/tree/main/.github/workflows"
    click CFG3 "https://github.com/chuymaster/thaivtuberranking-frontend/tree/main/web"

    %% Click Event for Testing
    click TEST1 "https://github.com/chuymaster/thaivtuberranking-frontend/tree/main/test"
```
