# crackededed/xtra architecture

> Architecture diagram of the GitHub repository crackededed/xtra, 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/crackededed/xtra
- Repository: https://github.com/crackededed/xtra

## Overview

Based on your project’s file tree and README, you are working with Xtra for Twitch – an Android application that provides a Twitch player and browser. The application is clearly segmented using standard Android architectural patterns, likely favoring an MVVM (Model-View-ViewModel) style with data repositories, dependency injection, and separate API and database layers.

##### Main Components

a. User Interface (UI) Layer:
- Android Activities and Fragments (e.g., LoginActivity, MainActivity; numerous Fragments for chat, clips, streams, media viewing, settings, etc.).
- Custom UI components and views (e.g., CustomPlayerView, SliderLayout, and various custom adapters for lists and navigation).

b. Presentation/Logic Layer:
- ViewModels for each UI section (e.g., MainViewModel, ChatViewModel, PlayerViewModel) that manage state and business logic.
- UI adapters and controllers that mediate between views and models.

c. Data Repository Layer:
- Repository classes (e.g., ApiRepository, AuthRepository, GraphQLRepository) that abstract data fetching and manipulation.
- Data sources under the “datasource” package that likely separate network data from local database fetches.

d. Network/API Layer:
- API integrations with Twitch using GraphQL and REST endpoints (e.g., GraphQLApi, HelixApi, IdApi, UsherApi).
- GraphQL query files utilized for fetching Twitch data (media, user details, streams, chat info, etc.).
- External WebSocket and HTTP clients for real-time chat or live notifications (e.g., ChatReadWebSocket, EventSubWebSocket).

e. Local Persistence Layer:
- SQLite/Room-based database (evident from the “db” package, DAOs such as BookmarksDao, LocalFollowChannelDao, and the AppDatabase definition).
- Migration schemas in the “schemas” directory, showing different database version files.

f. Dependency Injection Configuration:
- DI modules (DatabaseModule, XtraModule) defining how dependencies are provided throughout the app.

g. Media Playback & Downloading:
- Player and download components including workers like VideoDownloadWorker and classes under the “player” package to manage low latency streaming and player settings.
- Integration with HLS playlist parsing (HlsPlaylistParser) and m3u8 utilities for streaming.

h. External Services & Libraries:
- External libraries like Glide (XtraGlideModule) and Coil for image caching.
- Integration with fastlane (for release metadata) which suggests CI/CD deployment flows (reflected in the .github/workflows/android.yml).

##### Relationships and Interactions

- UI components invoke ViewModels that, in turn, interact with the Repository layer.
- The Repository layer aggregates data from the Network/API/GraphQL sources and the Local Persistence (DAOs/Database).
- API layer components interact with external Twitch services using GraphQL queries and REST endpoints.
- Dependency injection spans across all layers ensuring that repositories, network clients, and data sources are correctly provided.
- Worker processes ( download workers, live notification worker) operate in the background to handle asynchronous tasks and notifications.

##### Architectural Patterns

- MVVM Pattern: Clearly visible with Activities/Fragments, ViewModels (managing UI-specific logic), and repositories handling data.
- Repository Pattern: Repositories abstract both remote and local data sources.
- Dependency Injection: DI modules streamline the provisioning and management of dependencies.
- Separation of Concerns: Distinct packages for API, db, models, ui, and utilities ensure that business logic, UI, and data are decoupled.

##### Relevant Technologies

- Android SDK and Android Architecture Components (LiveData, ViewModel).
- GraphQL via the defined *.graphql files for backend querying.
- Room/SQLite for database persistence.
- Gradle for builds (build.gradle.kts) and fastlane for deployment automation.
- External libraries (Glide, Coil, m3u8 processing utilities).

##### Elements

- UI components → ViewModels → Repositories.
- Repositories breaking into branches for "Remote API" (GraphQL/Helix) and "Local Database" (DAOs/Room).
- Dependency injection wiring between modules.
- Background processing components (DownloadWorker, NotificationWorker) interacting with both repositories and service endpoints.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "UI Layer"
        UI1["LoginActivity"]:::UI
        UI2["MainActivity"]:::UI
        UI3["PlayerFragment"]:::UI
        UI4["ChatFragment"]:::UI
        UI5["CustomPlayerView"]:::UI
        UI6["SlidingLayout"]:::UI
    end

    subgraph "Presentation/Logic Layer"
        VM1["MainViewModel"]:::Presentation
        VM2["ChatViewModel"]:::Presentation
        VM3["PlayerViewModel"]:::Presentation
        VM4["Other ViewModels"]:::Presentation
    end

    subgraph "Data Repository Layer"
        REPO1["ApiRepository"]:::Repository
        REPO2["AuthRepository"]:::Repository
        REPO3["GraphQLRepository"]:::Repository
        REPO4["Other Repositories"]:::Repository
    end

    subgraph "Network/API Layer"
        API1["GraphQLApi"]:::Network
        API2["HelixApi"]:::Network
        API3["IdApi"]:::Network
        API4["UsherApi"]:::Network
        API5["GraphQL Queries"]:::Network
    end

    subgraph "Local Persistence Layer"
        DB1["AppDatabase"]:::Persistence
        DAO1["BookmarksDao"]:::Persistence
        DAO2["LocalFollowsChannelDao"]:::Persistence
        DBM["Migration Schemas"]:::Persistence
    end

    subgraph "Dependency Injection"
        DI1["DatabaseModule"]:::DI
        DI2["XtraModule"]:::DI
    end

    subgraph "Media Playback & Downloading"
        MEDIA1["HlsPlaylistParser"]:::Media
        MEDIA2["VideoDownloadWorker"]:::Media
        MEDIA3["StreamDownloadWorker"]:::Media
    end

    subgraph "External Services & CI/CD"
        EXT1["XtraGlideModule"]:::External
        EXT2["fastlane"]:::External
        EXT3["GitHub Workflow"]:::External
    end

    %% UI Layer triggers Presentation Layer
    UI1 -->|"triggers"| VM1
    UI2 -->|"triggers"| VM1
    UI3 -->|"triggers"| VM3
    UI4 -->|"triggers"| VM2

    %% Presentation Layer fetches data from Repository Layer
    VM1 -->|"fetches"| REPO1
    VM2 -->|"fetches"| REPO3
    VM3 -->|"fetches"| REPO1
    VM4 -->|"manages"| REPO4

    %% Repository Layer interacts with Network/API Layer
    REPO1 -->|"calls"| API1
    REPO2 -->|"authenticates"| API3
    REPO3 -->|"calls"| API1
    REPO4 -->|"aggregates"| API2
    REPO3 -->|"uses"| API5

    %% Repository Layer stores data in Persistence Layer
    REPO1 -->|"stores"| DB1
    REPO3 -->|"stores"| DB1
    DAO1 --> DB1
    DAO2 --> DB1

    %% Dependency Injection provides dependencies across Layers
    DI1 -->|"provides"| DB1
    DI2 -->|"provides"| REPO1
    DI2 -->|"provides"| REPO2
    DI2 -->|"provides"| REPO3

    %% Media components interact with Repository for downloads
    MEDIA1 -->|"parses"| MEDIA2
    MEDIA2 -->|"downloads"| REPO1
    MEDIA3 -->|"downloads"| REPO1

    %% External services enhance UI and support CI/CD
    EXT1 -->|"enhancesUI"| UI2
    EXT2 -->|"automates"| EXT3
    EXT3 -->|"triggersBuilds"| EXT2

    %% Class definitions for styling
    classDef UI fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef Presentation fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef Repository fill:#FFFF99,stroke:#333,stroke-width:2px;
    classDef Network fill:#F08080,stroke:#333,stroke-width:2px;
    classDef Persistence fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef DI fill:#FFA500,stroke:#333,stroke-width:2px;
    classDef Media fill:#D3D3D3,stroke:#333,stroke-width:2px;
    classDef External fill:#FAFAD2,stroke:#333,stroke-width:2px;

    %% Click Events
    click UI1 "https://github.com/crackededed/xtra/blob/master/app/src/main/java/com/github/andreyasadchy/xtra/ui/login/LoginActivity.kt"
    click UI2 "https://github.com/crackededed/xtra/blob/master/app/src/main/java/com/github/andreyasadchy/xtra/ui/main/MainActivity.kt"
    click UI3 "https://github.com/crackededed/xtra/blob/master/app/src/main/java/com/github/andreyasadchy/xtra/ui/player/PlayerFragment.kt"
    click UI4 "https://github.com/crackededed/xtra/blob/master/app/src/main/java/com/github/andreyasadchy/xtra/ui/chat/ChatFragment.kt"
    click UI5 "https://github.com/crackededed/xtra/blob/master/app/src/main/java/com/github/andreyasadchy/xtra/ui/view/CustomPlayerView.kt"
    click UI6 "https://github.com/crackededed/xtra/blob/master/app/src/main/java/com/github/andreyasadchy/xtra/ui/view/SlidingLayout.kt"

    click VM1 "https://github.com/crackededed/xtra/blob/master/app/src/main/java/com/github/andreyasadchy/xtra/ui/main/MainViewModel.kt"
    click VM2 "https://github.com/crackededed/xtra/blob/master/app/src/main/java/com/github/andreyasadchy/xtra/ui/chat/ChatViewModel.kt"
    click VM3 "https://github.com/crackededed/xtra/blob/master/app/src/main/java/com/github/andreyasadchy/xtra/ui/player/PlayerViewModel.kt"

    click REPO1 "https://github.com/crackededed/xtra/blob/master/app/src/main/java/com/github/andreyasadchy/xtra/repository/ApiRepository.kt"
    click REPO2 "https://github.com/crackededed/xtra/blob/master/app/src/main/java/com/github/andreyasadchy/xtra/repository/AuthRepository.kt"
    click REPO3 "https://github.com/crackededed/xtra/blob/master/app/src/main/java/com/github/andreyasadchy/xtra/repository/GraphQLRepository.kt"

    click API1 "https://github.com/crackededed/xtra/blob/master/app/src/main/java/com/github/andreyasadchy/xtra/api/GraphQLApi.kt"
    click API2 "https://github.com/crackededed/xtra/blob/master/app/src/main/java/com/github/andreyasadchy/xtra/api/HelixApi.kt"
    click API3 "https://github.com/crackededed/xtra/blob/master/app/src/main/java/com/github/andreyasadchy/xtra/api/IdApi.kt"
    click API4 "https://github.com/crackededed/xtra/blob/master/app/src/main/java/com/github/andreyasadchy/xtra/api/UsherApi.kt"
    click API5 "https://github.com/crackededed/xtra/tree/master/app/src/main/graphql/com/github/andreyasadchy/xtra/"

    click DB1 "https://github.com/crackededed/xtra/blob/master/app/src/main/java/com/github/andreyasadchy/xtra/db/AppDatabase.kt"
    click DAO1 "https://github.com/crackededed/xtra/blob/master/app/src/main/java/com/github/andreyasadchy/xtra/db/BookmarksDao.kt"
    click DAO2 "https://github.com/crackededed/xtra/blob/master/app/src/main/java/com/github/andreyasadchy/xtra/db/LocalFollowsChannelDao.kt"
    click DBM "https://github.com/crackededed/xtra/tree/master/app/schemas/com.github.andreyasadchy.xtra.db.AppDatabase/"

    click DI1 "https://github.com/crackededed/xtra/blob/master/app/src/main/java/com/github/andreyasadchy/xtra/di/DatabaseModule.kt"
    click DI2 "https://github.com/crackededed/xtra/blob/master/app/src/main/java/com/github/andreyasadchy/xtra/di/XtraModule.kt"

    click MEDIA1 "https://github.com/crackededed/xtra/blob/master/app/src/main/java/com/github/andreyasadchy/xtra/player/lowlatency/HlsPlaylistParser.java"
    click MEDIA2 "https://github.com/crackededed/xtra/blob/master/app/src/main/java/com/github/andreyasadchy/xtra/ui/download/VideoDownloadWorker.kt"
    click MEDIA3 "https://github.com/crackededed/xtra/blob/master/app/src/main/java/com/github/andreyasadchy/xtra/ui/download/StreamDownloadWorker.kt"

    click EXT1 "https://github.com/crackededed/xtra/blob/master/app/src/main/java/com/github/andreyasadchy/xtra/XtraGlideModule.kt"
    click EXT2 "https://github.com/crackededed/xtra/tree/master/fastlane/"
    click EXT3 "https://github.com/crackededed/xtra/blob/master/.github/workflows/android.yml"
```
