# imjyotiraditya/echoirx architecture

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

## Overview

##### Project Type & Purpose
- The project is an Android mobile application focused on downloading high-quality music. It supports various audio qualities (Hi-Res Lossless, CD-quality, Dolby Atmos, etc.) and uses Material Design 3 principles for a modern UI/UX.
- The README clarifies that Echoir handles background downloads, metadata embedding, and even employs a custom-built minimal version of ffmpeg-kit for media processing (especially for Hi-Res content).

##### File Structure
- At the top level, you have configuration files (gradle scripts, .gitignore, etc.), and the heart of the project is in the “app” directory.
- Within “app/src/main/java/app/echoirx”, the code is organized into several layers:
a. Data Layer:
- Contains packages such as “data/local” (with the Room database, DAOs, type converters), “data/remote” (with ApiService, DTOs, mappers), “data/media” (handling audio preview, ffmpeg processing), “data/notification” (download notifications) and “data/worker” (download workers and queue management).
b. Domain Layer:
- Contains “domain/model” representing core business models (Download, QualityConfig, etc.), “domain/repository” interfaces, and “domain/usecase” classes encapsulating business logic.
c. Presentation Layer:
- Comprises packages for screens (home, details, search, settings), navigation components, UI components, and theming, all of which follow principles typical of an MVVM architecture.
d. Dependency Injection (DI):
- The “di” package prepares modules for the database, network, repository, and worker, likely leveraging a DI framework to provide dependencies.
- There are Android-specific folders (e.g., res/) and testing directories ensuring coverage and resource management.

a. User Interface (Presentation Layer):
- Screens (HomeScreen, DetailsScreen, SearchScreen, SettingsScreen, etc.)
- Components (custom UI components like DownloadBottomSheet, TrackCover, Navigation bars)
- ViewModels (associated with each screen to handle state and business logic)
b. Domain Layer:
- Use Cases (e.g., AlbumTracksUseCase, SearchUseCase, ProcessDownloadUseCase, etc.)
- Domain Models (Download, PlaybackResponse, etc.)
- Repository Interfaces (DownloadRepository, SearchRepository, SettingsRepository)
c. Data Layer:
- Local Database:
- AppDatabase, DAO interfaces (DownloadDao), converters (Converters.kt)
- Remote Data:
- API services (ApiService), DTOs and their mappers (PlaybackMapper, SearchResultMapper)
- Media Handling:
- AudioPreviewPlayer, FFmpegProcessor, MetadataManager (specifically tailored for handling media and high-quality content)
- Worker or Background Processing:
- DownloadWorker, DownloadQueueManager, DownloadWorkUtil (for download management and continuing tasks in the background)
d. Dependency Injection:
- DI Modules (NetworkModule, RepositoryModule, WorkerModule, DatabaseModule) that wire dependencies for the above components.
e. External Libraries/Dependencies:
- Customized ffmpeg-kit (found in the libs directory) that is used by the FFmpegProcessor for processing Hi-Res audio segments.

##### Illustrating Relationships and Interactions
- UI components (screens and ViewModels) invoke Domain Use Cases.
- Use Cases interact with Repository Interfaces to fetch or persist data.
- Repository implementations aggregate data sources from:
- Remote APIs (via ApiService, mapping response DTOs to domain models)
- Local database (using DAOs and type converters)
- Media processing components (for Hi-Res audio handling and background processing)
- The worker module manages background download tasks and works with DownloadNotificationManager for user notifications.
- DI modules provide the necessary objects to each layer (e.g., the NetworkModule creates the ApiService instance, which is injected into the repository).

##### Architectural Patterns and Design Principles
- The structure follows an MVVM-like architecture with clear separation between Presentation, Domain, and Data.
- The use of Clean Architecture principles is visible, where business logic in use cases is separated from data fetch and UI rendering logic.
- The project also leverages a modular design where each layer (data, domain, presentation) is isolated, along with dependency injection to manage cross-layer concerns.
- Error handling, asynchronous operations (using Android’s worker framework), and reactive UI state management (ViewModels) are likely part of the design.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "User Interface (Presentation Layer)"
        UI_Screens["UI Screens (Home, Details, Search, Settings)"]:::ui
        UI_View["UI Components & ViewModels"]:::ui
    end

    %% Domain Layer
    subgraph "Domain Layer"
        UseCases["Use Cases (AlbumTracks, Search, ProcessDownload)"]:::domain
        DomainModels["Domain Models (Download, PlaybackResponse, etc.)"]:::domain
        Repos["Repository Interfaces (DownloadRepository, etc.)"]:::domain
    end

    %% Data Layer
    subgraph "Data Layer"
        subgraph "Local Database"
            LocalDB["AppDatabase, DownloadDao, Converters"]:::data
        end
        subgraph "Remote API & Data"
            RemoteAPI["ApiService, DTOs, Mappers"]:::data
        end
        subgraph "Media Handling"
            MediaHandling["AudioPreviewPlayer, FFmpegProcessor, MetadataManager"]:::data
        end
        subgraph "Worker/Background Processing"
            Worker["DownloadWorker, DownloadQueueManager, DownloadWorkUtil"]:::data
        end
        subgraph "Download Notifications"
            Notifications["DownloadNotificationManager"]:::data
        end
    end

    %% Dependency Injection
    subgraph "Dependency Injection"
        DI_Modules["DI Modules (NetworkModule, RepositoryModule, WorkerModule, DatabaseModule)"]:::di
    end

    %% External Libraries
    subgraph "External Libraries"
        FFmpeg["Custom ffmpeg-kit"]:::external
    end

    %% Connections from Presentation to Domain
    UI_Screens -->|"invokes"| UseCases
    UI_View   -->|"triggers"| UseCases

    %% Domain interactions
    UseCases -->|"calls"| Repos

    %% Repository interactions with Data Layer
    Repos -->|"fetches from"| LocalDB
    Repos -->|"fetches from"| RemoteAPI
    Repos -->|"processes via"| MediaHandling
    Repos -->|"delegates to"| Worker
    Repos -->|"notifies via"| Notifications

    %% External dependency integration
    FFmpeg -->|"integrated into"| MediaHandling

    %% Dependency Injection wiring
    DI_Modules -->|"provides to"| UseCases
    DI_Modules -->|"provides to"| Repos
    DI_Modules -->|"provides to"| LocalDB
    DI_Modules -->|"provides to"| RemoteAPI
    DI_Modules -->|"provides to"| MediaHandling
    DI_Modules -->|"provides to"| Worker
    DI_Modules -->|"provides to"| Notifications

    %% Click Events
    click UI_Screens "https://github.com/imjyotiraditya/echoirx/tree/main/app/src/main/java/app/echoirx/presentation"
    click UseCases "https://github.com/imjyotiraditya/echoirx/tree/main/app/src/main/java/app/echoirx/domain"
    click LocalDB "https://github.com/imjyotiraditya/echoirx/tree/main/app/src/main/java/app/echoirx/data/local"
    click RemoteAPI "https://github.com/imjyotiraditya/echoirx/tree/main/app/src/main/java/app/echoirx/data/remote"
    click MediaHandling "https://github.com/imjyotiraditya/echoirx/tree/main/app/src/main/java/app/echoirx/data/media"
    click Worker "https://github.com/imjyotiraditya/echoirx/tree/main/app/src/main/java/app/echoirx/data/worker"
    click Notifications "https://github.com/imjyotiraditya/echoirx/tree/main/app/src/main/java/app/echoirx/data/notification"
    click DI_Modules "https://github.com/imjyotiraditya/echoirx/tree/main/app/src/main/java/app/echoirx/di"
    click FFmpeg "https://github.com/imjyotiraditya/echoirx/blob/main/libs/ffmpeg-kit.aar"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef domain fill:#98FB98,stroke:#000,stroke-width:1px;
    classDef data fill:#FFA500,stroke:#000,stroke-width:1px;
    classDef di fill:#DA70D6,stroke:#000,stroke-width:1px;
    classDef external fill:#FFB6C1,stroke:#000,stroke-width:1px;
```
