# lamprosgk/recipes-sample architecture

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

- Interactive diagram: https://gitdiagram.com/lamprosgk/recipes-sample
- Repository: https://github.com/lamprosgk/recipes-sample

## Overview

##### Project Type & Purpose
- The project is an Android application utilizing Clean Architecture and MVI. It is modularized into multiple components promoting separation between data handling, business logic, UI, and cross-cutting concerns.
- Key modules include:
- :data – Manages remote/API services, local Room database, dependency injection (e.g., DataModule, DatabaseModule), and repository implementations.
- :domain – Contains the domain models, business rules, and abstract repository definitions (the contract that data module implements).
- :home – Feature-specific module for the recipes list with its own UI layer and use cases (e.g., GetRecipesUseCase).
- :detail – Feature-specific module for the detailed recipe screen including its own use cases and UI (e.g., AddToFavouritesUseCase, RemoveFromFavouritesUseCase).
- :shared – Provides common MVI base classes (MviIntent, MviModel, MviView, MviViewModel) and shared UI components such as error display handling.

##### Analyzing the File Structure
- The presence of directories like “app”, “data”, “domain”, “detail”, “home”, and “shared” confirms a modular architecture.
- Each module contains its own AndroidManifest, build configurations, source code (under src/main/java), and test directories. This reinforces the structure prescribed by Clean Architecture where each module is responsible for its own layer or feature.
- The “data” module specifically holds network, local, and repository folders, indicating the implementation of both remote and offline-first (Room database) data sources.
- The “shared” module provides the core MVI components, which will be utilized by the presentation layers within the “home” and “detail” feature modules.

a. Main Components:
- Application Bootstrap (App Module): Acts as the entry point including application class (RecipesApplication.kt) and the Android manifest.
- Data Layer (Data Module): Further divided into:
▪ Remote Data Source (e.g., RecipesService, RecipesRemoteDataSource)
▪ Local Data Source (e.g., RecipeDao, RecipesLocalDataSource, RecipesDatabase)
▪ Repository Implementation (e.g., RecipesRepositoryImpl)
▪ Network configuration (NetworkConfig, NetworkModule)
- Domain Layer (Domain Module):
▪ Domain Models (e.g., Recipe)
▪ Abstract Repository Interface (e.g., RecipesRepository)
▪ Business Logic encapsulated within use cases.
- Feature Modules:
▪ Home Module: UI for recipes list; contains use cases like GetRecipesUseCase and ViewModel classes.
▪ Detail Module: UI for recipe details; contains use cases for adding/removing favorites and corresponding ViewModels, navigation, and screen classes.
- Presentation Support (Shared Module):
▪ Contains MVI base interfaces/classes that guide the flow of intents, state models, and views.
▪ Provides common UI components for error handling and other shared concerns.

b. Relationships and Data Flow:
- UI Components in Home and Detail modules communicate with their respective ViewModels adopting the MVI pattern (utilizing MVI classes from the shared module).
- ViewModels dispatch intents and receive updated state (MVI model) from the associated use cases.
- Use cases in Home and Detail interact with the Domain layer’s repository interfaces.
- The Domain layer’s repository interfaces are then implemented in the Data module, which fetches data from the remote API or local Room database (offline-first approach).
- Dependencies such as network calls, database operations, and dependency injection modules (in Data and possibly Domain) are clearly delineated.

c. Architectural Patterns & Design Principles:
- Clean Architecture separates concerns among data, domain, and presentation.
- MVI ensures unidirectional data flow: User Intent → ViewModel → State → UI.
- Modularization improves decoupling, testability, and independent deployment of features.
- Offline-first with Room ensures the app functions without constant network connectivity.

d. Relevant Technologies & Frameworks:
- Android (with an emphasis on Kotlin for implementation).
- Room database for offline storage.
- Retrofit or other networking libraries (implied by remote service implementation).
- Dependency Injection via modules in the Data and possibly Domain layers.
- MVI architecture patterns supported by the shared module’s base classes.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Application Bootstrap
    subgraph "Application Bootstrap"
        AppApp["RecipesApplication.kt"]:::appStyle
        MainAct["MainActivity.kt"]:::appStyle
        AndroidManifest["AndroidManifest.xml"]:::appStyle
    end

    %% Shared Module
    subgraph "Shared Module (MVI & UI)"
        MVIIntent["MviIntent"]:::sharedStyle
        MVIModel["MviModel"]:::sharedStyle
        MVIView["MviView"]:::sharedStyle
        MVIViewModel["MviViewModel"]:::sharedStyle
        UError["ErrorMessage"]:::sharedStyle
    end

    %% Home Feature Module
    subgraph "Home Module"
        HS["RecipesScreen"]:::homeStyle
        HV["RecipesViewModel"]:::homeStyle
        HUC["GetRecipesUseCase"]:::homeStyle
    end

    %% Detail Feature Module
    subgraph "Detail Module"
        DS["RecipeDetailScreen"]:::detailStyle
        DV["RecipeDetailViewModel"]:::detailStyle
        DU1["AddToFavouritesUseCase"]:::detailStyle
        DU2["RemoveFromFavouritesUseCase"]:::detailStyle
        DU3["GetRecipeUseCase"]:::detailStyle
    end

    %% Domain Layer
    subgraph "Domain Layer"
        DM["Recipe (Domain Model)"]:::domainStyle
        RI["RecipesRepository (Interface)"]:::domainStyle
        Result["Result Wrapper"]:::domainStyle
    end

    %% Data Layer
    subgraph "Data Layer"
        DSrv["RecipesService"]:::dataStyle
        DRDS["RecipesRemoteDataSource"]:::dataStyle
        LDao["RecipeDao"]:::dataStyle
        LLDS["RecipesLocalDataSource"]:::dataStyle
        LDB["RecipesDatabase"]:::dataStyle
        DRI["RecipesRepositoryImpl"]:::dataStyle
        DDI["DataModule"]:::dataStyle
        DDB["DatabaseModule"]:::dataStyle
    end

    %% Relationships
    %% Application Bootstrap launches UI
    MainAct -->|"launches"| HS
    MainAct -->|"launches"| DS

    %% Shared module supports UI (dotted connections)
    HS ---|"uses_MVI"| MVIIntent
    HS ---|"uses_MVI"| MVIModel
    HV ---|"binds_MVI"| MVIViewModel
    DS ---|"uses_MVI"| MVIView
    DV ---|"binds_MVI"| MVIViewModel

    %% Home Module flow: Screen -> ViewModel -> UseCase
    HS -->|"updates"| HV
    HV -->|"triggers"| HUC

    %% Detail Module flow: Screen -> ViewModel -> UseCases
    DS -->|"updates"| DV
    DV -->|"triggers"| DU1
    DV -->|"triggers"| DU2
    DV -->|"triggers"| DU3

    %% Use Cases interact with Domain Layer
    HUC -->|"calls"| RI
    DU1 -->|"calls"| RI
    DU2 -->|"calls"| RI
    DU3 -->|"calls"| RI

    %% Domain Layer: Repository interface implemented by Data Layer
    RI -->|"implemented_by"| DRI

    %% Data Layer: Repository aggregates data from Remote and Local sources
    DRI -->|"fetches_from"| DSrv
    DRI -->|"fetches_from"| DRDS
    DRI -->|"fetches_from"| LDao
    DRI -->|"fetches_from"| LLDS
    DRI -->|"fetches_from"| LDB

    %% Dependency injection in Data Layer
    DDI -->|"provides"| DSrv
    DDI -->|"provides"| DRDS
    DDI -->|"provides"| DRI
    DDB -->|"provides"| LDao
    DDB -->|"provides"| LLDS
    DDB -->|"provides"| LDB

    %% Domain Layer also produces additional types
    RI -->|"yields"| DM
    RI -->|"yields"| Result

    %% Navigation from Home to Detail
    HS -->|"navigates_to"| DS

    %% Click Events for Application Bootstrap
    click AppApp "https://github.com/lamprosgk/recipes-sample/blob/main/app/src/main/java/com/lamprosgk/recipes/RecipesApplication.kt"
    click MainAct "https://github.com/lamprosgk/recipes-sample/blob/main/app/src/main/java/com/lamprosgk/recipes/MainActivity.kt"
    click AndroidManifest "https://github.com/lamprosgk/recipes-sample/blob/main/app/src/main/AndroidManifest.xml"

    %% Click Events for Data Layer - Remote
    click DSrv "https://github.com/lamprosgk/recipes-sample/blob/main/data/src/main/java/com/lamprosgk/data/remote/RecipesService.kt"
    click DRDS "https://github.com/lamprosgk/recipes-sample/blob/main/data/src/main/java/com/lamprosgk/data/remote/RecipesRemoteDataSource.kt"
    %% Click Events for Data Layer - Local
    click LDao "https://github.com/lamprosgk/recipes-sample/blob/main/data/src/main/java/com/lamprosgk/data/local/RecipeDao.kt"
    click LLDS "https://github.com/lamprosgk/recipes-sample/blob/main/data/src/main/java/com/lamprosgk/data/local/RecipesLocalDataSource.kt"
    click LDB "https://github.com/lamprosgk/recipes-sample/blob/main/data/src/main/java/com/lamprosgk/data/local/RecipesDatabase.kt"
    %% Click Event for Data Layer - Repository Implementation
    click DRI "https://github.com/lamprosgk/recipes-sample/blob/main/data/src/main/java/com/lamprosgk/data/repository/RecipesRepositoryImpl.kt"
    %% Click Events for Data Layer - Dependency Injection Modules
    click DDI "https://github.com/lamprosgk/recipes-sample/blob/main/data/src/main/java/com/lamprosgk/data/di/DataModule.kt"
    click DDB "https://github.com/lamprosgk/recipes-sample/blob/main/data/src/main/java/com/lamprosgk/data/di/DatabaseModule.kt"

    %% Click Events for Domain Layer
    click DM "https://github.com/lamprosgk/recipes-sample/blob/main/domain/src/main/java/com/lamprosgk/domain/model/Recipe.kt"
    click RI "https://github.com/lamprosgk/recipes-sample/blob/main/domain/src/main/java/com/lamprosgk/domain/repository/RecipesRepository.kt"
    click Result "https://github.com/lamprosgk/recipes-sample/blob/main/domain/src/main/java/com/lamprosgk/domain/Result.kt"

    %% Click Events for Home Module
    click HS "https://github.com/lamprosgk/recipes-sample/blob/main/home/src/main/java/com/lamprosgk/home/ui/screens/RecipesScreen.kt"
    click HV "https://github.com/lamprosgk/recipes-sample/blob/main/home/src/main/java/com/lamprosgk/home/ui/screens/RecipesViewModel.kt"
    click HUC "https://github.com/lamprosgk/recipes-sample/blob/main/home/src/main/java/com/lamprosgk/home/usecase/GetRecipesUseCase.kt"

    %% Click Events for Detail Module
    click DS "https://github.com/lamprosgk/recipes-sample/blob/main/detail/src/main/java/com/lamprosgk/detail/ui/screens/RecipeDetailScreen.kt"
    click DV "https://github.com/lamprosgk/recipes-sample/blob/main/detail/src/main/java/com/lamprosgk/detail/ui/screens/RecipeDetailViewModel.kt"
    click DU1 "https://github.com/lamprosgk/recipes-sample/blob/main/detail/src/main/java/com/lamprosgk/detail/usecase/AddToFavouritesUseCase.kt"
    click DU2 "https://github.com/lamprosgk/recipes-sample/blob/main/detail/src/main/java/com/lamprosgk/detail/usecase/RemoveFromFavouritesUseCase.kt"
    click DU3 "https://github.com/lamprosgk/recipes-sample/blob/main/detail/src/main/java/com/lamprosgk/detail/usecase/GetRecipeUseCase.kt"

    %% Click Events for Shared Module
    click MVIIntent "https://github.com/lamprosgk/recipes-sample/blob/main/shared/src/main/java/com/lamprosgk/shared/mvi/MviIntent.kt"
    click MVIModel "https://github.com/lamprosgk/recipes-sample/blob/main/shared/src/main/java/com/lamprosgk/shared/mvi/MviModel.kt"
    click MVIView "https://github.com/lamprosgk/recipes-sample/blob/main/shared/src/main/java/com/lamprosgk/shared/mvi/MviView.kt"
    click MVIViewModel "https://github.com/lamprosgk/recipes-sample/blob/main/shared/src/main/java/com/lamprosgk/shared/mvi/MviViewModel.kt"
    click UError "https://github.com/lamprosgk/recipes-sample/blob/main/shared/src/main/java/com/lamprosgk/shared/ui/ErrorMessage.kt"

    %% Styles
    classDef appStyle fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef sharedStyle fill:#e0e0e0,stroke:#616161,stroke-width:2px;
    classDef homeStyle fill:#ffe0b2,stroke:#bf360c,stroke-width:2px;
    classDef detailStyle fill:#ffcdd2,stroke:#b71c1c,stroke-width:2px;
    classDef domainStyle fill:#fff9c4,stroke:#f9a825,stroke-width:2px;
    classDef dataStyle fill:#c8e6c9,stroke:#2e7d32,stroke-width:2px;
```
