# jeprubio/marvel-compose architecture

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

- Interactive diagram: https://gitdiagram.com/jeprubio/marvel-compose
- Repository: https://github.com/jeprubio/marvel-compose

## Overview

##### Project Type & Purpose
- This is a full-stack mobile application (client-only) that displays Marvel-themed content.
- It uses a modular approach with separate modules for core app functionality (app), feature-specific components (feature-characters and feature-comics), and shared libraries (library-components, library-marvelapi, library-tests).
- The app communicates with external services (Marvel API) using Retrofit and processes network responses with Gson.

##### Analyzing the File Structure
- The top-level “app” directory contains the main Android application, including the Compose UI screens, navigation, and widget implementation.
- “feature-characters” and “feature-comics” modules house feature-specific implementation:
- They include their own presentation (screens, viewmodels), domain (use cases, models), and data layers (repositories, mappers).
- “library-marvelapi” encapsulates the networking logic, API models, and dependency injection for creating API service modules.
- “library-components” provides reusable UI components (like search bars, image loaders, error messages) and theming making use of Jetpack Compose.
- Several testing directories (unit and UI tests) indicate rigorous testing of each layer with frameworks such as JUnit5, Espresso, and Shot.

##### Components
a. Presentation/UI Layer:
- Compose UI Views: MainActivity, navigation components (BottomNavigationBar, NavigationHost, NavigationRailBar), screens for Comic and Character lists/details, widget views.
- Reusable Components: Built in library-components.
b. ViewModel Layer (MVVM):
- Separate ViewModels for character and comic features (HeroListViewModel, DetailsViewModel, ComicListViewModel, ComicDetailsViewModel).
c. Domain Layer:
- Use Cases encapsulated in the usecase subdirectories (e.g., GetCharacterDetailsUseCase, SearchUseCase, GetComicsUseCase).
- Domain Models representing Character, Comic, etc.
d. Data Layer:
- Repositories implementations in each feature module (CharactersRepository, ComicsRepository).
- Data mappers and repository modules.
e. Networking Layer:
- Library-marvelapi handles API calls via Retrofit.
- Contains APIs, network interceptors (MarvelInterceptor, LoggingInterceptor), and exception handling.
f. Dependency Injection:
- Dagger-Hilt is used for DI (see “infrastructure/di” directories in feature modules and library-marvelapi).
g. Testing:
- The test suites (both unit and UI testing) branch out to verify the functionality of each layer.

##### Relationships & Interactions
- UI (Compose screens) observes data from the ViewModel layer.
- The ViewModel layer processes user interactions by triggering domain use cases.
- Domain layer encapsulates business logic and interacts with data repositories.
- Data Repositories fetch data from the network layer (via API calls in library-marvelapi) or local sources (if any caching is implemented).
- Modules interact using dependency injection, ensuring loose coupling.
- External dependencies such as Retrofit, Dagger-Hilt, and third-party libraries (Timber, Coil) should be noted as supporting technologies.

##### Architectural Patterns & Design Principles
- Modularization: Clear separation into app, feature modules, and shared libraries.
- MVVM: Presentation is cleanly separated from business logic.
- Clean Architecture Components: Distinct separation among presentation, domain, and data layers.
- Dependency Injection: Facilitates testability and clear dependencies.
- Use of best practices from recommended Android app architecture.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% App Module
    subgraph "App Module"
        ui["UI (Compose Screens)"]:::ui
        nav["Navigation Components"]:::ui
        ui --> nav
    end

    %% Navigation to Features
    nav -->|"navigatesTo"| charPres["Characters Presentation"]:::feature
    nav -->|"navigatesTo"| comicsPres["Comics Presentation"]:::feature

    %% Feature - Characters Module
    subgraph "Feature - Characters"
        charPres --> charVM["Characters ViewModel"]:::viewmodel
        charVM --> charDom["Characters Domain"]:::domain
        charDom --> charData["Characters Data"]:::data
    end

    %% Feature - Comics Module
    subgraph "Feature - Comics"
        comicsPres --> comicsVM["Comics ViewModel"]:::viewmodel
        comicsVM --> comicsDom["Comics Domain"]:::domain
        comicsDom --> comicsData["Comics Data"]:::data
    end

    %% Networking Layer
    net["Networking API"]:::network

    %% Connect Data Layers to Networking
    charData -->|"fetchesFrom"| net
    comicsData -->|"fetchesFrom"| net

    %% Dependency Injection Modules
    subgraph "Dependency Injection"
        diChar["DI (Characters)"]:::di
        diComics["DI (Comics)"]:::di
        diMarvel["DI (MarvelAPI)"]:::di
    end

    %% DI relationships
    charVM ---|"injects"| diChar
    comicsVM ---|"injects"| diComics
    net ---|"injects"| diMarvel

    %% Reusable UI Components
    reusable["Reusable UI Components"]:::ui
    ui ---|"uses"| reusable

    %% Testing Components
    test["Testing Components"]:::test
    ui --- test
    charVM --- test
    charDom --- test
    comicsVM --- test
    comicsDom --- test
    net --- test

    %% Legend
    subgraph "Legend"
        L1["UI Elements: UI (Compose Screens), Navigation, Reusable UI Components"]:::uiLegend
        L2["Feature Modules: Presentation, ViewModel, Domain, Data"]:::featureLegend
        L3["Networking API (Retrofit & Gson)"]:::networkLegend
        L4["Dependency Injection (Dagger-Hilt)"]:::diLegend
        L5["Testing Components (Unit & UI Tests)"]:::testLegend
    end

    %% Click Events
    click ui "https://github.com/jeprubio/marvel-compose/tree/main/app/src/main/java/com/rumosoft/marvelcompose/presentation"
    click nav "https://github.com/jeprubio/marvel-compose/tree/main/app/src/main/java/com/rumosoft/marvelcompose/presentation/navigation"
    click charPres "https://github.com/jeprubio/marvel-compose/tree/main/feature-characters/src/main/java/com/rumosoft/characters/presentation"
    click charVM "https://github.com/jeprubio/marvel-compose/tree/main/feature-characters/src/main/java/com/rumosoft/characters/presentation/viewmodel"
    click charDom "https://github.com/jeprubio/marvel-compose/tree/main/feature-characters/src/main/java/com/rumosoft/characters/domain"
    click charData "https://github.com/jeprubio/marvel-compose/tree/main/feature-characters/src/main/java/com/rumosoft/characters/data"
    click comicsPres "https://github.com/jeprubio/marvel-compose/tree/main/feature-comics/src/main/java/com/rumosoft/comics/presentation"
    click comicsVM "https://github.com/jeprubio/marvel-compose/tree/main/feature-comics/src/main/java/com/rumosoft/comics/presentation/viewmodel"
    click comicsDom "https://github.com/jeprubio/marvel-compose/tree/main/feature-comics/src/main/java/com/rumosoft/comics/domain"
    click comicsData "https://github.com/jeprubio/marvel-compose/tree/main/feature-comics/src/main/java/com/rumosoft/comics/data"
    click net "https://github.com/jeprubio/marvel-compose/tree/main/library-marvelapi/src/main/java/com/rumosoft/marvelapi/data/network"
    click diChar "https://github.com/jeprubio/marvel-compose/tree/main/feature-characters/src/main/java/com/rumosoft/characters/infrastructure/di"
    click diComics "https://github.com/jeprubio/marvel-compose/tree/main/feature-comics/src/main/java/com/rumosoft/comics/infrastructure/di"
    click diMarvel "https://github.com/jeprubio/marvel-compose/tree/main/library-marvelapi/src/main/java/com/rumosoft/marvelapi/infrastructure/di"
    click reusable "https://github.com/jeprubio/marvel-compose/tree/main/library-components/src/main/java/com/rumosoft/components/presentation/component"
    click reusable "https://github.com/jeprubio/marvel-compose/tree/main/library-components/src/main/java/com/rumosoft/components/presentation/theme"
    click test "https://github.com/jeprubio/marvel-compose/tree/main/app/src/test"
    click test "https://github.com/jeprubio/marvel-compose/tree/main/app/src/androidTest"
    click test "https://github.com/jeprubio/marvel-compose/tree/main/feature-characters/src/test"
    click test "https://github.com/jeprubio/marvel-compose/tree/main/feature-comics/src/test"
    click test "https://github.com/jeprubio/marvel-compose/tree/main/library-tests/src/main/java/com/rumosoft/libraryTests"

    %% Styles
    classDef ui fill:#FAD02E,stroke:#333,stroke-width:2px;
    classDef feature fill:#FFEEAD,stroke:#333,stroke-width:2px;
    classDef viewmodel fill:#AED9E0,stroke:#333,stroke-width:2px;
    classDef domain fill:#FFB6B9,stroke:#333,stroke-width:2px;
    classDef data fill:#C1C8E4,stroke:#333,stroke-width:2px;
    classDef network fill:#D4A5A5,stroke:#333,stroke-width:2px;
    classDef di fill:#BDE0FE,stroke:#333,stroke-width:2px;
    classDef test fill:#C8D5B9,stroke:#333,stroke-width:2px;
    classDef uiLegend fill:#FAD02E,stroke:#333,stroke-width:1px;
    classDef featureLegend fill:#FFEEAD,stroke:#333,stroke-width:1px;
    classDef networkLegend fill:#D4A5A5,stroke:#333,stroke-width:1px;
    classDef diLegend fill:#BDE0FE,stroke:#333,stroke-width:1px;
    classDef testLegend fill:#C8D5B9,stroke:#333,stroke-width:1px;
```
