# comeran/collectmeta architecture

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

- Interactive diagram: https://gitdiagram.com/comeran/collectmeta
- Repository: https://github.com/comeran/collectmeta

## Overview

##### Main Components
- Presentation Layer: This is where the UI resides. It includes Activities, Fragments (for home, detail, search, library, settings, etc.), and ViewModels. They orchestrate user interactions and mediate between the UI and domain layers using MVVM.
- Domain Layer: This layer contains the business logic. It includes domain models (like Book, ApiConfig, etc.), repository interfaces, and use cases (e.g., AddBookUseCase, GetBookDetailsUseCase, etc.). The domain layer is completely independent of the data and presentation layers.
- Data Layer: Responsible for data retrieval and storage. It is split into:
- Local Data: Room database components such as entities, DAOs, converters (for example, BookEntity, ApiConfigEntity, AppDatabase, etc.).
- Remote Data: API clients (GoogleBooksApi, NotionDatabaseApi, OpenLibraryApi) that handle external API calls.
- Data Mappers: Converters between data entities and domain models.
- Repository Implementations: Implementations for the repositories defined in the domain layer.
- Dependency Injection: Dagger Hilt is used (with modules like DatabaseModule, NetworkModule, RepositoryModule) to provide dependencies to different parts of the application.
- Application and Configuration: The application entry point (CollectMetaApplication.kt) sets up the overall configuration for the app.

##### Relationships and Interactions
- The Presentation Layer (UI - Fragments/Activities) communicates with the Domain Layer through ViewModels. ViewModels invoke Use Cases.
- The Domain Layer contains use cases that encapsulate business logic and invoke repository interfaces.
- The Data Layer contains repository implementations that fetch data from local (Room-based DB operations) or remote sources (API calls). Data mappers convert data model objects to domain models.
- Dependency Injection orchestrates the wiring of these components, ensuring that UI components, use cases, repositories, and network/database elements are properly provided.

##### Architectural Patterns & Design Principles
- Clean Architecture: Separation of concerns between Presentation, Domain, and Data layers.
- MVVM: Used in the presentation layer to manage UI state and handle user interactions.
- Repository Pattern: Abstracts data access so that the domain layer is independent of data sources.
- Dependency Injection (using Dagger Hilt): Ensures modularity and testability.
- Separation of local (Room database) and remote (API) data handling.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer: UI & ViewModels"
        homeFrag["HomeFragment (UI)"]
        homeVM["HomeViewModel"]
    end

    %% Domain Layer
    subgraph "Domain Layer: Use Cases & Models"
        addBookUseCase["AddBookUseCase"]
        bookDomain["Book (Domain Model)"]
    end

    %% Data Layer
    subgraph "Data Layer"
        subgraph "Local Data"
            appDB["AppDatabase (Room)"]
            apiConfigEntity["ApiConfigEntity"]
            bookEntity["BookEntity"]
            apiConfigDao["ApiConfigDao"]
            bookDao["BookDao"]
            converters["Converters"]
        end
        subgraph "Remote Data"
            googleBooksApi["GoogleBooksApi"]
            notionDatabaseApi["NotionDatabaseApi"]
            openLibraryApi["OpenLibraryApi"]
            notionDatabaseResponse["NotionDatabaseResponse"]
        end
        subgraph "Data Mappers"
            bookMapper["BookMapper"]
            apiConfigMapper["ApiConfigMapper"]
        end
        subgraph "Repository Implementations"
            bookRepoImpl["BookRepositoryImpl"]
            apiConfigRepoImpl["ApiConfigRepositoryImpl"]
        end
    end

    %% Dependency Injection
    subgraph "Dependency Injection (Dagger Hilt)"
        databaseModule["DatabaseModule"]
        networkModule["NetworkModule"]
        repositoryModule["RepositoryModule"]
    end

    %% Application Entry
    subgraph "Application Entry"
        collectMetaApp["CollectMetaApplication"]
    end

    %% Relationships between layers
    homeFrag -->|"invokes"| homeVM
    homeVM -->|"calls"| addBookUseCase
    addBookUseCase -->|"uses"| bookRepoImpl
    addBookUseCase -->|"operates_on"| bookDomain

    %% Repository interactions with Data Layer
    bookRepoImpl -->|"local_access"| appDB
    bookRepoImpl -->|"remote_call"| googleBooksApi
    bookRepoImpl -->|"maps_data"| bookMapper

    %% Dependency Injection wiring
    databaseModule -->|"provides"| appDB
    databaseModule -->|"provides"| converters
    databaseModule -->|"provides"| apiConfigDao
    databaseModule -->|"provides"| bookDao
    networkModule -->|"provides"| googleBooksApi
    networkModule -->|"provides"| notionDatabaseApi
    networkModule -->|"provides"| openLibraryApi
    repositoryModule -->|"provides"| bookRepoImpl
    repositoryModule -->|"provides"| apiConfigRepoImpl
    collectMetaApp -->|"initializes"| databaseModule
    collectMetaApp -->|"initializes"| networkModule
    collectMetaApp -->|"initializes"| repositoryModule

    %% Class Styles
    class homeFrag,homeVM presentation
    class addBookUseCase,bookDomain domain
    class appDB,apiConfigEntity,bookEntity,apiConfigDao,bookDao,converters dataLocal
    class googleBooksApi,notionDatabaseApi,openLibraryApi,notionDatabaseResponse dataRemote
    class bookMapper,apiConfigMapper mapper
    class bookRepoImpl,apiConfigRepoImpl repository
    class databaseModule,networkModule,repositoryModule di
    class collectMetaApp app

    %% Click Events for Presentation Layer
    click homeFrag "https://github.com/comeran/collectmeta/blob/main/app/src/main/java/com/homeran/collectmeta/ui/home/HomeFragment.kt"
    click homeVM "https://github.com/comeran/collectmeta/blob/main/app/src/main/java/com/homeran/collectmeta/ui/home/HomeViewModel.kt"

    %% Click Events for Domain Layer
    click addBookUseCase "https://github.com/comeran/collectmeta/blob/main/app/src/main/java/com/homeran/collectmeta/domain/usecase/book/AddBookUseCase.kt"
    click bookDomain "https://github.com/comeran/collectmeta/blob/main/app/src/main/java/com/homeran/collectmeta/domain/model/Book.kt"

    %% Click Events for Data Layer - Local Data
    click appDB "https://github.com/comeran/collectmeta/blob/main/app/src/main/java/com/homeran/collectmeta/data/db/AppDatabase.kt"
    click apiConfigEntity "https://github.com/comeran/collectmeta/blob/main/app/src/main/java/com/homeran/collectmeta/data/db/entities/ApiConfigEntity.kt"
    click bookEntity "https://github.com/comeran/collectmeta/blob/main/app/src/main/java/com/homeran/collectmeta/data/db/entities/BookEntity.kt"
    click apiConfigDao "https://github.com/comeran/collectmeta/blob/main/app/src/main/java/com/homeran/collectmeta/data/db/dao/ApiConfigDao.kt"
    click bookDao "https://github.com/comeran/collectmeta/blob/main/app/src/main/java/com/homeran/collectmeta/data/db/dao/BookDao.kt"
    click converters "https://github.com/comeran/collectmeta/blob/main/app/src/main/java/com/homeran/collectmeta/data/db/converters/Converters.kt"

    %% Click Events for Data Layer - Remote Data
    click googleBooksApi "https://github.com/comeran/collectmeta/blob/main/app/src/main/java/com/homeran/collectmeta/data/remote/api/GoogleBooksApi.kt"
    click notionDatabaseApi "https://github.com/comeran/collectmeta/blob/main/app/src/main/java/com/homeran/collectmeta/data/remote/api/NotionDatabaseApi.kt"
    click openLibraryApi "https://github.com/comeran/collectmeta/blob/main/app/src/main/java/com/homeran/collectmeta/data/remote/api/OpenLibraryApi.kt"
    click notionDatabaseResponse "https://github.com/comeran/collectmeta/blob/main/app/src/main/java/com/homeran/collectmeta/data/remote/model/notion/NotionDatabaseResponse.kt"

    %% Click Events for Data Mappers
    click bookMapper "https://github.com/comeran/collectmeta/blob/main/app/src/main/java/com/homeran/collectmeta/data/mapper/BookMapper.kt"
    click apiConfigMapper "https://github.com/comeran/collectmeta/blob/main/app/src/main/java/com/homeran/collectmeta/data/mapper/ApiConfigMapper.kt"

    %% Click Events for Repository Implementations
    click bookRepoImpl "https://github.com/comeran/collectmeta/blob/main/app/src/main/java/com/homeran/collectmeta/data/repository/BookRepositoryImpl.kt"
    click apiConfigRepoImpl "https://github.com/comeran/collectmeta/blob/main/app/src/main/java/com/homeran/collectmeta/data/repository/ApiConfigRepositoryImpl.kt"

    %% Click Events for Dependency Injection
    click databaseModule "https://github.com/comeran/collectmeta/blob/main/app/src/main/java/com/homeran/collectmeta/di/DatabaseModule.kt"
    click networkModule "https://github.com/comeran/collectmeta/blob/main/app/src/main/java/com/homeran/collectmeta/di/NetworkModule.kt"
    click repositoryModule "https://github.com/comeran/collectmeta/blob/main/app/src/main/java/com/homeran/collectmeta/di/RepositoryModule.kt"

    %% Click Event for Application Entry
    click collectMetaApp "https://github.com/comeran/collectmeta/blob/main/app/src/main/java/com/homeran/collectmeta/CollectMetaApplication.kt"

    %% Style Definitions
    classDef presentation fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef domain fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef dataLocal fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef dataRemote fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef mapper fill:#E6E6FA,stroke:#000,stroke-width:2px;
    classDef repository fill:#F4A460,stroke:#000,stroke-width:2px;
    classDef di fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef app fill:#FFB6C1,stroke:#000,stroke-width:2px;
```
