# dmoyahur/moviesapp architecture

> Architecture diagram of the GitHub repository dmoyahur/moviesapp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dmoyahur/moviesapp
- Repository: https://github.com/dmoyahur/moviesapp

## Overview

##### Main Components
- App Module – Represents the entry point for the Android application. It includes the application class, main activity, and navigation logic.
- Feature Modules – These include separate modules for “movies”, “detail”, and “search”. Each feature module encapsulates the UI (View), ViewModel, and use-case logic.
- Data Modules – Divided into several parts:
– Data – Repository, local, remote, and test submodules.
– Data – Repository module exposes interfaces for fetching data from both local (Room based) and remote (Retrofit, OkHttp) sources.
– Data – Remote handles API calls to TMDb and includes mappers for API responses.
– Data – Local manages caching with Room and handles database queries via DAO classes.
- Model Module – Contains domain-level models that are used to represent movies and error states throughout the app.
- Build-Logic Module – Contains custom Gradle scripts and plugins which standardize build conventions and rules across all modules.
- TestShared Module – Holds common testing utilities, test runners, and shared test rules for both unit testing and UI testing.

##### Relationships and Data Flow
- User interactions in the View (components in the feature modules) send events to the ViewModel.
- The ViewModel responds by invoking use cases, which act as a proxy, calling repository interfaces defined in the Data Repository module.
- The Repository abstracts data retrieval: it decides whether to fetch from the Local data source (cache via Room) or the Remote data source (API calls via Retrofit).
- Once data is fetched, it goes through mapping layers (e.g., converting DTOs to domain models in the Model module) before being sent back to the ViewModel.
- The ViewModel then updates the UI state (using state flows or LiveData) which the View listens to for re-rendering.

##### Architectural Patterns and Design Principles
- Modularization – Distinct modules should be depicted with clear boundaries. Show dependencies between modules (e.g., Feature modules depend on Data, Model and Common modules; Data Repository depends on both the Remote and Local modules).
- Use-case abstraction – Although a separate use-case (domain) module isn’t present, each feature directly contains use-case classes, so indicate that the use-case functions are interposed between the ViewModel and Repository.
- Data Mapping – Emphasize the transformation of remote data to local models, especially within the Data – Remote and Data – Local modules.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI/Presentation Layer
    subgraph "UI/Presentation Layer"
        A["App Module"]:::app
        FM["Feature: Movies"]:::feature
        FD["Feature: Detail"]:::feature
        FS["Feature: Search"]:::feature
    end

    %% Domain/Logic Layer
    subgraph "Domain/Logic Layer"
        VM["ViewModel & Use Cases"]:::domain
        RI["Repository Interfaces"]:::domain
    end

    %% Data Layer
    subgraph "Data Layer"
        DR["Data - Repository Module"]:::data
        DRemote["Data - Remote Module"]:::data
        DLocal["Data - Local Module"]:::data
        DTest["Data - Test Module"]:::data
    end

    %% Supporting Modules
    subgraph "Supporting Modules"
        M["Model Module"]:::support
        C["Common Module"]:::support
        BL["Build-Logic Module"]:::support
        TS["TestShared Module"]:::support
    end

    %% External Dependencies
    subgraph "External Dependencies"
        Hilt["Hilt"]:::external
        Retrofit["Retrofit"]:::external
        Room["Room"]:::external
        Coil["Coil"]:::external
    end

    %% Connections from UI to Domain/Logic
    A -->|"navigates_to"| FM
    A -->|"navigates_to"| FD
    A -->|"navigates_to"| FS

    FM -->|"triggers"| VM
    FD -->|"triggers"| VM
    FS -->|"triggers"| VM

    %% Domain/Logic interactions
    VM -->|"invokes"| RI
    RI -->|"delegates_to"| DR
    RI -->|"updates"| VM

    %% Data Layer interactions
    DR -->|"fetches_from"| DRemote
    DR -->|"fetches_from"| DLocal
    DRemote -->|"maps_to"| M
    DLocal -->|"maps_to"| M
    DR -->|"tests_with"| DTest

    %% External Dependencies interactions
    A ---|"uses"| Hilt
    Hilt ---|"injects_into"| VM

    DRemote ---|"uses"| Retrofit
    DLocal ---|"uses"| Room

    FM ---|"loads_images"| Coil
    FD ---|"loads_images"| Coil
    FS ---|"loads_images"| Coil

    DTest ---|"supported_by"| TS

    %% Supporting Modules usage in UI
    FM ---|"utilizes"| C
    FD ---|"utilizes"| C
    FS ---|"utilizes"| C

    %% Styling for layers
    classDef app fill:#e1bee7,stroke:#4a148c,stroke-width:2px;
    classDef feature fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef domain fill:#c8e6c9,stroke:#1b5e20,stroke-width:2px;
    classDef data fill:#ffe0b2,stroke:#e65100,stroke-width:2px;
    classDef support fill:#fff9c4,stroke:#f9a825,stroke-width:2px;
    classDef external fill:#ffcdd2,stroke:#b71c1c,stroke-width:2px;

    %% Click Events
    click A "https://github.com/dmoyahur/moviesapp/tree/main/app/src/main/java/com/dmoyahur/moviesapp"
    click FM "https://github.com/dmoyahur/moviesapp/tree/main/feature/movies"
    click FD "https://github.com/dmoyahur/moviesapp/tree/main/feature/detail"
    click FS "https://github.com/dmoyahur/moviesapp/tree/main/feature/search"
    click DLocal "https://github.com/dmoyahur/moviesapp/tree/main/data/local"
    click DRemote "https://github.com/dmoyahur/moviesapp/tree/main/data/remote"
    click DR "https://github.com/dmoyahur/moviesapp/tree/main/data/repository"
    click DTest "https://github.com/dmoyahur/moviesapp/tree/main/data/test"
    click M "https://github.com/dmoyahur/moviesapp/tree/main/model"
    click C "https://github.com/dmoyahur/moviesapp/tree/main/common"
    click BL "https://github.com/dmoyahur/moviesapp/tree/main/build-logic"
    click TS "https://github.com/dmoyahur/moviesapp/tree/main/testShared"
```
