# jellyfin/jellyfin-androidtv architecture

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

- Interactive diagram: https://gitdiagram.com/jellyfin/jellyfin-androidtv
- Repository: https://github.com/jellyfin/jellyfin-androidtv

## Overview

##### Main Components

a. Core Application Layer:
- Application (JellyfinApplication.kt)
- Authentication System
- UI/Presentation Layer
- Playback System
- Preferences Management

b. External Integrations:
- Jellyfin Server API
- Media3/ExoPlayer
- Android TV Framework
- Content Providers

##### Architectural Patterns to Highlight

- MVVM Architecture (ViewModels present in UI components)
- Repository Pattern (visible in auth/repository and data/repository)
- Plugin Architecture (especially for playback)
- Dependency Injection (using Koin, visible in di/ directory)

##### Key Components Breakdown

Frontend (UI Layer):
**[Android TV Leanback Framework]**
- ↓
**[UI Components]**
- Browsing
- Playback
- Search
- Preferences
- Home Screen

Core Services:
**[Authentication]  [Playback]  [Preferences]**
- ↓             ↓            ↓
**[Repositories] → [Services] ← [Data Stores]**

Playback System:
**[Playback Manager]**
- ↓
**[Media Backends] → [Stream Resolvers]**
- ↓
**[ExoPlayer/Media3]**

##### Implementation Details

- Component Name     |

- Key Responsibilities |
- Main Classes         |
- Dependencies         |

##### Data Flow Indicators

- User interaction flow
- Authentication flow
- Media playback flow
- Data synchronization
- API communications

##### External Services

- Component types
- Special indicators

This system design should emphasize the TV-centric nature of the application while showing how it integrates with the Jellyfin ecosystem. The modular nature of the playback system and the authentication framework should be prominently featured as they are core to the application's functionality.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and classes
    classDef ui fill:#3498db,stroke:#2980b9,color:white
    classDef core fill:#2ecc71,stroke:#27ae60,color:white
    classDef external fill:#e67e22,stroke:#d35400,color:white
    classDef data fill:#9b59b6,stroke:#8e44ad,color:white
    classDef media fill:#e74c3c,stroke:#c0392b,color:white

    %% Main Application
    MainApp["JellyfinApplication"]:::core
    click MainApp "https://github.com/jellyfin/jellyfin-androidtv/blob/master/app/src/main/java/org/jellyfin/androidtv/JellyfinApplication.kt"

    %% External Services
    subgraph External
        JellyfinServer["Jellyfin Server"]:::external
        AndroidTV["Android TV Framework"]:::external
        ContentProviders["Content Providers"]:::external
        click ContentProviders "https://github.com/jellyfin/jellyfin-androidtv/blob/master/app/src/main/java/org/jellyfin/androidtv/integration/MediaContentProvider.kt"
    end

    %% UI Layer
    subgraph UI
        HomeScreen["Home Screen"]:::ui
        click HomeScreen "https://github.com/jellyfin/jellyfin-androidtv/tree/master/app/src/main/java/org/jellyfin/androidtv/ui/home/"
        BrowsingUI["Browsing"]:::ui
        click BrowsingUI "https://github.com/jellyfin/jellyfin-androidtv/tree/master/app/src/main/java/org/jellyfin/androidtv/ui/browsing/"
        PlaybackUI["Playback UI"]:::ui
        click PlaybackUI "https://github.com/jellyfin/jellyfin-androidtv/tree/master/app/src/main/java/org/jellyfin/androidtv/ui/playback/"
        SearchUI["Search"]:::ui
        click SearchUI "https://github.com/jellyfin/jellyfin-androidtv/tree/master/app/src/main/java/org/jellyfin/androidtv/ui/search/"
        PreferencesUI["Preferences UI"]:::ui
        click PreferencesUI "https://github.com/jellyfin/jellyfin-androidtv/tree/master/app/src/main/java/org/jellyfin/androidtv/ui/preference/"
    end

    %% Core Services
    subgraph Core
        AuthSystem["Authentication System"]:::core
        click AuthSystem "https://github.com/jellyfin/jellyfin-androidtv/tree/master/app/src/main/java/org/jellyfin/androidtv/auth/"
        PlaybackSystem["Playback System"]:::core
        click PlaybackSystem "https://github.com/jellyfin/jellyfin-androidtv/tree/master/playback/"
        PreferencesSystem["Preferences Management"]:::core
        click PreferencesSystem "https://github.com/jellyfin/jellyfin-androidtv/tree/master/preference/"
    end

    %% Data Layer
    subgraph Data
        AuthRepo["Auth Repository"]:::data
        click AuthRepo "https://github.com/jellyfin/jellyfin-androidtv/tree/master/app/src/main/java/org/jellyfin/androidtv/auth/repository/"
        DataRepo["Data Repository"]:::data
        click DataRepo "https://github.com/jellyfin/jellyfin-androidtv/tree/master/app/src/main/java/org/jellyfin/androidtv/data/repository/"
        DataModels["Data Models"]:::data
        click DataModels "https://github.com/jellyfin/jellyfin-androidtv/tree/master/app/src/main/java/org/jellyfin/androidtv/data/model/"
    end

    %% Playback Components
    subgraph Playback
        PlaybackCore["Playback Core"]:::media
        click PlaybackCore "https://github.com/jellyfin/jellyfin-androidtv/tree/master/playback/core/"
        ExoPlayer["ExoPlayer Integration"]:::media
        click ExoPlayer "https://github.com/jellyfin/jellyfin-androidtv/tree/master/playback/media3/exoplayer/"
        MediaSession["Media Session"]:::media
        click MediaSession "https://github.com/jellyfin/jellyfin-androidtv/tree/master/playback/media3/session/"
        JellyfinIntegration["Jellyfin Integration"]:::media
        click JellyfinIntegration "https://github.com/jellyfin/jellyfin-androidtv/tree/master/playback/jellyfin/"
    end

    %% DI System
    DI["Dependency Injection (Koin)"]:::core
    click DI "https://github.com/jellyfin/jellyfin-androidtv/tree/master/app/src/main/java/org/jellyfin/androidtv/di/"

    %% Relationships
    MainApp --> DI
    DI --> AuthSystem
    DI --> PlaybackSystem
    DI --> PreferencesSystem

    AuthSystem --> AuthRepo
    AuthRepo --> JellyfinServer

    PlaybackSystem --> PlaybackCore
    PlaybackCore --> ExoPlayer
    PlaybackCore --> MediaSession
    PlaybackCore --> JellyfinIntegration
    JellyfinIntegration --> JellyfinServer

    HomeScreen & BrowsingUI & SearchUI --> DataRepo
    DataRepo --> JellyfinServer
    DataRepo --> DataModels

    PlaybackUI --> PlaybackSystem
    PreferencesUI --> PreferencesSystem

    ContentProviders --> DataRepo

    %% Legend
    subgraph Legend
        UI_Legend["UI Components"]:::ui
        Core_Legend["Core Services"]:::core
        External_Legend["External Services"]:::external
        Data_Legend["Data Components"]:::data
        Media_Legend["Media Components"]:::media
    end
```
