# buggily/enemy architecture

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

## Overview

Based on our analysis of the provided file tree and README, enemy is an Android audio player built as a sample and for personal daily use. It focuses on local audio playback (with comprehensive metadata requirements) and integrates key Android libraries and modern architectural practices such as MVVM, dependency injection (Hilt), Paging3, Jetpack Compose, Media3 for audio, and adaptive layouts. The project is highly modular, with separate modules for core functionality (domain, data, UI, controller, etc.), features (album, browse, controller, playlist, track, etc.), as well as local, external, and infrastructure build components.

- App Module: Represent the primary Android application module (located in “app”) that includes the AndroidManifest, main Activity, Media Service, and basic DI initialization (EnemyApplication.kt). This module is the entry point.
- Core Layers:
- Domain: Represent modules under “core/domain” and “domain/…” – they encapsulate business logic and use-case definitions (e.g., Play, Pause, GetDuration, etc.).
- Data: Include “core/data” which and modules under “data/…” that deal with data structures, network/local data sources, and repositories.
- UI: Include “core/ui” which contains shared UI components, themes, and global UI states.
- Navigation and Paging: The project has dedicated navigation (“core/navigation” and domain/navigation) and paging (“core/paging”) modules that structure the user flows and data loading.
- Builder & Infrastructure: The “builder” module contains custom Gradle convention plugins and properties that are used to enforce consistency in the multi-module structure.

##### Relationships and Architectural Patterns
- The App module depends on feature modules (UI) as well as on core layers.
- Feature modules use ViewModels to interact with the Domain (business logic) layer.
- Domain modules invoke repository interfaces provided by the Data modules.
- Data modules interact with both the local (persistent storage, Room/Database) and external (query sources) modules.
- Navigation modules interact with both the UI and Domain layers to handle app routing.
- Use of MVVM by diagramming the flow: UI Components → ViewModels → Domain (use cases) → Data Sources.

##### Critical Technologies and Technologies per Layer
- For the UI/presentation layer:
- Jetpack Compose, adaptive layouts (WindowSizeClass), Coil for image loading.
- For audio playback:
- Media3 with its mediaservice and media notifications.
- For data handling:
- Paging3 for positional paging.
- For dependency management:
- Hilt for dependency injection.
- For architecture:
- Unidirectional data flow following MVVM.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% App Module Subgraph
    subgraph "App Module"
        EnemyApplication["EnemyApplication (App DI Init)"]:::app
        AndroidManifest["AndroidManifest"]:::app
        EnemyActivity["EnemyActivity"]:::app
        EnemyMediaService["EnemyMediaService"]:::app
    end

    %% Feature Modules Subgraph
    subgraph "Feature Modules"
        %% Album Feature
        AlbumUI["Album Feature UI"]:::feature
        AlbumVM["Album Feature VM"]:::feature
        %% Browse Feature
        BrowseUI["Browse Feature UI"]:::feature
        BrowseVM["Browse Feature VM"]:::feature
        %% Playlist Feature
        PlaylistUI["Playlist Feature UI"]:::feature
        PlaylistVM["Playlist Feature VM"]:::feature
        %% Track Feature
        TrackUI["Track Feature UI"]:::feature
        TrackVM["Track Feature VM"]:::feature
        %% Controller Feature
        ControllerUI["Controller Feature UI"]:::feature
        ControllerVM["Controller Feature VM"]:::feature
    end

    %% Core Modules Subgraph
    subgraph "Core Modules"
        Domain["Domain (Business Logic)"]:::core
        Data["Data (Repositories)"]:::core
        UI["UI (Shared Components)"]:::core
        Navigation["Navigation Module"]:::core
        Paging["Paging Module"]:::core
    end

    %% Local Data Sources Subgraph
    subgraph "Local Data Sources"
        LocalDatabase["Local Database (Core Local)"]:::local
        LocalPlaylist["Local Playlist"]:::local
        LocalTrack["Local Track"]:::local
        LocalPreferences["Local Preferences"]:::local
        LocalResume["Local Resume"]:::local
    end

    %% External Data Sources Subgraph
    subgraph "External Data Sources"
        ExternalAlbum["External Album"]:::external
        ExternalTrack["External Track"]:::external
    end

    %% Dependency Injection Nodes
    AppDI["App DI"]:::di
    CoreDI["Core DI"]:::di

    %% Builder & Infrastructure Node
    Builder["Builder & Infrastructure"]:::infra

    %% External Technologies
    JetpackCompose["Jetpack Compose"]:::tech
    Paging3["Paging3"]:::tech
    Coil["Coil"]:::tech
    Media3Playback["Media3 Audio Playback"]:::tech

    %%----------------------------------------
    %% Connections within App Module
    EnemyApplication -->|"launches"| EnemyActivity
    EnemyApplication -->|"initiates"| EnemyMediaService
    EnemyMediaService -->|"uses"| Media3Playback

    %% App Module to Feature Modules (UI)
    EnemyActivity -->|"opens"| AlbumUI
    EnemyActivity -->|"opens"| BrowseUI
    EnemyActivity -->|"opens"| PlaylistUI
    EnemyActivity -->|"opens"| TrackUI
    EnemyActivity -->|"opens"| ControllerUI

    %% Feature Modules internal flow: UI -> VM
    AlbumUI -->|"binds"| AlbumVM
    BrowseUI -->|"binds"| BrowseVM
    PlaylistUI -->|"binds"| PlaylistVM
    TrackUI -->|"binds"| TrackVM
    ControllerUI -->|"binds"| ControllerVM

    %% Feature VM to Domain Layer (MVVM flow)
    AlbumVM -->|"triggers"| Domain
    BrowseVM -->|"triggers"| Domain
    PlaylistVM -->|"triggers"| Domain
    TrackVM -->|"triggers"| Domain
    ControllerVM -->|"triggers"| Domain

    %% Domain to Data Layer
    Domain -->|"calls"| Data

    %% Data Layer to Local & External Sources
    Data -->|"fetches"| LocalDatabase
    Data -->|"fetches"| LocalPlaylist
    Data -->|"fetches"| LocalTrack
    Data -->|"fetches"| LocalPreferences
    Data -->|"fetches"| LocalResume
    Data -->|"fetches"| ExternalAlbum
    Data -->|"fetches"| ExternalTrack

    %% UI and Navigation flow
    AlbumUI ---|"styled_by"| UI
    BrowseUI ---|"styled_by"| UI
    PlaylistUI ---|"styled_by"| UI
    TrackUI ---|"styled_by"| UI
    ControllerUI ---|"styled_by"| UI
    Navigation -->|"routes_to"| EnemyActivity

    %% Data Paging integration
    Data -->|"paginates_via"| Paging

    %% Dependency Injection edges
    AppDI -->|"injects_into"| EnemyApplication
    AppDI -->|"injects_into"| AlbumVM
    AppDI -->|"injects_into"| BrowseVM
    AppDI -->|"injects_into"| PlaylistVM
    AppDI -->|"injects_into"| TrackVM
    AppDI -->|"injects_into"| ControllerVM
    CoreDI -->|"injects_into"| Domain

    %% Builder & Infrastructure influences
    Builder -->|"configures"| EnemyApplication
    Builder -->|"configures"| Domain
    Builder -->|"configures"| AlbumUI
    Builder -->|"configures"| BrowseUI
    Builder -->|"configures"| PlaylistUI
    Builder -->|"configures"| TrackUI
    Builder -->|"configures"| ControllerUI

    %% External technologies integration
    JetpackCompose -->|"enhances"| UI
    Paging3 -->|"supports"| Paging
    Coil -->|"enhances"| UI

    %%----------------------------------------
    %% Class Definitions for styling
    classDef app fill:#FFEEE6,stroke:#D2691E,stroke-width:2px;
    classDef feature fill:#E6FFED,stroke:#2E8B57,stroke-width:2px;
    classDef core fill:#E6F0FF,stroke:#4169E1,stroke-width:2px;
    classDef local fill:#FFF5BA,stroke:#DAA520,stroke-width:2px;
    classDef external fill:#FFD6E7,stroke:#C71585,stroke-width:2px;
    classDef di fill:#E0BBE4,stroke:#8A2BE2,stroke-width:2px;
    classDef infra fill:#F0FFF0,stroke:#228B22,stroke-width:2px,stroke-dasharray: 5 5;
    classDef tech fill:#F5F5DC,stroke:#8B4513,stroke-width:2px,stroke-dasharray: 3 3;

    %%----------------------------------------
    %% Click Events
    click EnemyApplication "https://github.com/buggily/enemy/blob/main/app/src/main/java/com/buggily/enemy/EnemyApplication.kt"
    click AndroidManifest "https://github.com/buggily/enemy/blob/main/app/src/main/AndroidManifest.xml"
    click EnemyActivity "https://github.com/buggily/enemy/blob/main/app/src/main/java/com/buggily/enemy/EnemyActivity.kt"
    click EnemyMediaService "https://github.com/buggily/enemy/blob/main/app/src/main/java/com/buggily/enemy/EnemyMediaService.kt"
    
    click AlbumUI "https://github.com/buggily/enemy/tree/main/feature/album"
    click AlbumVM "https://github.com/buggily/enemy/tree/main/feature/album"
    click BrowseUI "https://github.com/buggily/enemy/tree/main/feature/browse"
    click BrowseVM "https://github.com/buggily/enemy/tree/main/feature/browse"
    click PlaylistUI "https://github.com/buggily/enemy/tree/main/feature/playlist"
    click PlaylistVM "https://github.com/buggily/enemy/tree/main/feature/playlist"
    click TrackUI "https://github.com/buggily/enemy/tree/main/feature/track"
    click TrackVM "https://github.com/buggily/enemy/tree/main/feature/track"
    click ControllerUI "https://github.com/buggily/enemy/tree/main/feature/controller"
    click ControllerVM "https://github.com/buggily/enemy/tree/main/feature/controller"
    
    click Domain "https://github.com/buggily/enemy/tree/main/core/domain"
    click Data "https://github.com/buggily/enemy/tree/main/core/data"
    click UI "https://github.com/buggily/enemy/tree/main/core/ui"
    click Navigation "https://github.com/buggily/enemy/tree/main/core/navigation"
    click Paging "https://github.com/buggily/enemy/tree/main/core/paging"
    
    click LocalDatabase "https://github.com/buggily/enemy/tree/main/core/local"
    click LocalPlaylist "https://github.com/buggily/enemy/tree/main/local/playlist"
    click LocalTrack "https://github.com/buggily/enemy/tree/main/local/track"
    click LocalPreferences "https://github.com/buggily/enemy/tree/main/local/preferences"
    click LocalResume "https://github.com/buggily/enemy/tree/main/local/resume"
    
    click ExternalAlbum "https://github.com/buggily/enemy/tree/main/external/album"
    click ExternalTrack "https://github.com/buggily/enemy/tree/main/external/track"
    
    click Builder "https://github.com/buggily/enemy/tree/main/builder"
    
    click AppDI "https://github.com/buggily/enemy/tree/main/app/src/main/java/com/buggily/enemy/di"
    click CoreDI "https://github.com/buggily/enemy/blob/main/core/domain/src/main/java/com/buggily/enemy/core/domain/di/CoreDomainModule.kt"
```
