# anandnet/harmony-music architecture

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

## Overview

##### Main Components
- UI/Presentation Layer:
- Represented by the “lib/ui” folder, which contains various screens (Home, Player, Search, Settings, Artists, etc.), widgets, and navigation controllers.
- That the UI layer is responsible for rendering views and handling user interactions.

- Domain/Models Layer:
- Shown in the “lib/models” directory (album, artist, playlist, quick picks, etc.).
- These components encapsulate the core data structures that represent music items, playlists, and related entities.

- Service/Business Logic Layer:
- Located in “lib/services”, with modules for audio handling, background tasks, downloading, permission handling, interfacing with Piped (for playlist integrations), and more.
- This layer acts as the intermediary between the UI and the data/persistence layers. Also, it encapsulates external API calls (like youtube_explode_dart for retrieving song URLs).

- Data Persistence/Local Storage:
- The project uses Hive (and hive_flutter) for offline database functionality. Represent this as a “Local Storage / Persistence” component.
- Interactions between the business logic layer and local storage where caching and offline mapping occur.

- Native Bindings & Platform-Specific Code:
- Although much of the UI and business logic are in Dart, there are narrow pockets that handle integrations with Android (in “android” folder and “lib/native_bindings/”) and platform-specific configuration files for iOS, Linux, Windows, and macOS.
- That platform-specific adjustments (like background music handling, Android Auto support, and system tray integration for desktop) extend the core functionality.

- External Services / Third-Party Integrations:
- External APIs and libraries that provide actual streaming services (YouTube content via youtube_explode_dart; audio playback with just_audio, media_kit; background handling via audio_service) should be represented.
- Also mention service dependencies like Piped for playlist integration and LRCLIB for synced lyrics.

##### Defining Relationships and Interactions
- How the Service layer communicates with the Models to construct data objects and then either fetch data from external APIs or cache locally in Hive.
- For platform-specific components, show an interface or adapter pattern where the uniform business logic layer calls into distinct native implementations (especially for audio playback on different platforms).

##### Highlighting Architectural Patterns and Design Principles
- That the app follows a layered architecture where presentation, logic, and data are decoupled.
- Separation of concerns between platform-agnostic Flutter code (in lib/) and platform-specific implementations (in android, ios, windows, etc.).

##### Including Relevant Technologies, Frameworks, and Libraries
- Flutter – the cross-platform UI framework.
- Get (from the pubspec) for state management/dependency injection.
- just_audio, media_kit, and audio_service for audio playback and background handling.
- youtube_explode_dart for content access from YouTube.
- Hive for local data storage.
- Native integration code for handling Android-specific features (e.g., Android Auto, notifications) and corresponding counterparts for desktop and iOS/macOS.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "UI/Presentation Layer"
        UI["UI/Presentation (lib/ui)"]:::uiStyle
    end

    subgraph "Service/Business Logic Layer"
        Services["Service/Business Logic (lib/services)"]:::serviceStyle
    end

    subgraph "Domain/Models Layer"
        Models["Domain/Models (lib/models)"]:::modelStyle
    end

    subgraph "Data Persistence"
        Persistence["Local Storage (Hive)"]:::storageStyle
    end

    subgraph "Native Bindings & Platform-Specific Code"
        NativeBindings["Native Bindings (lib/native_bindings)"]:::nativeStyle
        Android["Android-Specific (android/)"]:::nativeStyle
        iOS["iOS-Specific (ios/)"]:::nativeStyle
        Linux["Linux-Specific (linux/)"]:::nativeStyle
        Windows["Windows-Specific (windows/)"]:::nativeStyle
        macOS["macOS-Specific (macos/)"]:::nativeStyle
    end

    subgraph "External Services / Third-Party Integrations"
        YouTube["YouTube API (youtube_explode_dart)"]:::externalStyle
        Piped["Piped Service"]:::externalStyle
        Audio["Audio Playback (just_audio, media_kit, audio_service)"]:::externalStyle
        LRCLIB["LRCLIB (Lyrics)"]:::externalStyle
    end

    %% Connections
    UI -->|"triggers"| Services
    Services -->|"manages_data_via"| Models
    Services -->|"caches_to"| Persistence
    Services -->|"calls"| YouTube
    Services -->|"integrates_with"| Piped
    Services -->|"calls"| Audio
    Services -->|"calls"| LRCLIB
    Services -->|"interfaces_with"| NativeBindings
    NativeBindings -->|"android_features"| Android
    NativeBindings -->|"ios_features"| iOS
    NativeBindings -->|"linux_features"| Linux
    NativeBindings -->|"windows_features"| Windows
    NativeBindings -->|"macos_features"| macOS

    %% Click Events
    click UI "https://github.com/anandnet/harmony-music/tree/main/lib/ui"
    click Models "https://github.com/anandnet/harmony-music/tree/main/lib/models"
    click Services "https://github.com/anandnet/harmony-music/tree/main/lib/services"
    click NativeBindings "https://github.com/anandnet/harmony-music/tree/main/lib/native_bindings"
    click Android "https://github.com/anandnet/harmony-music/tree/main/android/"
    click iOS "https://github.com/anandnet/harmony-music/tree/main/ios/"
    click Linux "https://github.com/anandnet/harmony-music/tree/main/linux/"
    click Windows "https://github.com/anandnet/harmony-music/tree/main/windows/"
    click macOS "https://github.com/anandnet/harmony-music/tree/main/macos/"

    %% Classes and Styles
    classDef uiStyle fill:#C6E2FF,stroke:#0277BD,stroke-width:2px;
    classDef serviceStyle fill:#FFECB3,stroke:#F9A825,stroke-width:2px;
    classDef modelStyle fill:#C8E6C9,stroke:#388E3C,stroke-width:2px;
    classDef storageStyle fill:#F8BBD0,stroke:#C2185B,stroke-width:2px;
    classDef nativeStyle fill:#D1C4E9,stroke:#512DA8,stroke-width:2px;
    classDef externalStyle fill:#FFCDD2,stroke:#C62828,stroke-width:2px;
```
