# lucas-haux/recipe_app architecture

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

- Interactive diagram: https://gitdiagram.com/lucas-haux/recipe_app
- Repository: https://github.com/lucas-haux/recipe_app

## Overview

##### Main Components
- Cross-Platform Flutter UI: Covers all the visual components and presentation logic. The “lib/ui” folder is subdivided into areas such as “home”, “recipe”, “search”, and “search_results”. Each section likely manages its own viewmodels (see *.g.dart files generated for view models) and widgets.
- Data Layer: Found in “lib/data” where you have models (in data/model), repositories (for favorites, recipes, search parameters, and theme management), and services (e.g., recipe search, full info, similar recipes). This layer abstracts data fetching and local caching.
- Domain Layer: Located in “lib/domain”, it defines business logic and models (including enums and built models for favorites, recipes, etc.), common to the overall application logic.
- Platform-Specific Implementations: Directories like android, ios, macos, windows, linux, and web encapsulate the platform-specific bootstrap and configuration (e.g., Android Manifest, Xcode projects, CMake for desktop) which integrate with the core Flutter engine.

##### Relationships and Interactions
- The UI layer interacts with the ViewModel classes that, in turn, retrieve data via the Data Repositories.
- Repositories in the data layer call the services (which could interface with APIs or local storage) and transform the raw data into domain models.
- The domain layer serves as the glue, defining entities and behaviors that are shared by both the UI and the data layers.
- Each platform directory encapsulates the specific runtime configuration and build settings necessary to run the shared Flutter code on that platform.

##### Important Architectural Patterns
- Clean Architecture: Evident from the separation into UI, data, and domain layers.
- MVVM (Model-View-ViewModel): The presence of view models (with generated “g.dart” files) and separate UI components indicates a distinct MVVM pattern for state management and view updates.
- Code Generation: The existence of generated files (e.g., “*.g.dart” files in both repositories and viewmodels) suggests the use of JSON serialization, dependency injection, or other automated code generation tools to simplify data transformations.

##### Relevant Technologies & Frameworks
- Flutter framework for building cross-platform UIs.
- Dart as the programming language, evident from the file extensions (e.g., .dart) and project structure.
- Platform-specific configurations (e.g., Android’s Gradle files, iOS’s Xcode projects, etc.) which enable the Flutter engine to run on various operating systems.
- Additional plugins or libraries may be involved (inferred from generated repository code and service implementations) that support network requests, state management, or dependency injection.

- Grouping by layers: group all UI-related components together; all data-related items (repositories, models, services) together; and show the platform bootstraps separately.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Shared Code (lib)
    subgraph "Shared Code (lib)"
        %% UI Layer
        subgraph "UI Layer"
            U["Flutter UI"]:::ui
        end
        %% ViewModels
        subgraph "ViewModels"
            HVM["Home ViewModel"]:::ui
            RVM["Recipe ViewModel"]:::ui
            SVM["Search View Model"]:::ui
            SRVM["Search Results ViewModel"]:::ui
        end
        %% Data Layer
        subgraph "Data Layer"
            DR["Repositories"]:::data
            DS["Services"]:::data
            DM["Models"]:::data
        end
        %% Domain Layer
        subgraph "Domain Layer"
            D["Domain Models"]:::domain
        end
    end

    %% Platform-Specific Implementations
    subgraph "Platform-Specific Implementations"
        A["Android"]:::platform
        I["iOS"]:::platform
        M["macOS"]:::platform
        W["Windows"]:::platform
        L["Linux"]:::platform
        Web["Web"]:::platform
    end

    %% Relationships: UI to ViewModels
    U -->|"calls"| HVM
    U -->|"calls"| RVM
    U -->|"calls"| SVM
    U -->|"calls"| SRVM

    %% Relationships: ViewModels to Data Repositories
    HVM -->|"fetches"| DR
    RVM -->|"fetches"| DR
    SVM -->|"fetches"| DR
    SRVM -->|"fetches"| DR

    %% Relationships: Data Layer internal flow
    DR -->|"invokes"| DS
    DS -->|"transforms"| DM
    DM -->|"maps_to"| D

    %% Relationships: UI runs on Platforms
    U -->|"runs_on"| A
    U -->|"runs_on"| I
    U -->|"runs_on"| M
    U -->|"runs_on"| W
    U -->|"runs_on"| L
    U -->|"runs_on"| Web

    %% Click Events for Shared Code
    click U "https://github.com/lucas-haux/recipe_app/tree/main/lib/ui"
    click HVM "https://github.com/lucas-haux/recipe_app/blob/main/lib/ui/home/home_viewmodel.g.dart"
    click RVM "https://github.com/lucas-haux/recipe_app/blob/main/lib/ui/recipe/recipe_viewmodel.g.dart"
    click SVM "https://github.com/lucas-haux/recipe_app/blob/main/lib/ui/search/search_view_model.g.dart"
    click SRVM "https://github.com/lucas-haux/recipe_app/blob/main/lib/ui/search_results/search_results_view_model.g.dart"
    click DR "https://github.com/lucas-haux/recipe_app/tree/main/lib/data/repositories"
    click DS "https://github.com/lucas-haux/recipe_app/tree/main/lib/data/services"
    click DM "https://github.com/lucas-haux/recipe_app/tree/main/lib/data/model"
    click D "https://github.com/lucas-haux/recipe_app/tree/main/lib/domain"

    %% Click Events for Platform-Specific Implementations
    click A "https://github.com/lucas-haux/recipe_app/blob/main/android/app/src/main/AndroidManifest.xml"
    click I "https://github.com/lucas-haux/recipe_app/blob/main/ios/Runner/AppDelegate.swift"
    click M "https://github.com/lucas-haux/recipe_app/blob/main/macos/Runner/AppDelegate.swift"
    click W "https://github.com/lucas-haux/recipe_app/blob/main/windows/runner/main.cpp"
    click L "https://github.com/lucas-haux/recipe_app/blob/main/linux/main.cc"
    click Web "https://github.com/lucas-haux/recipe_app/blob/main/web/index.html"

    %% Styles using Nord color palette
    classDef platform fill:#3B4252,stroke:#81A1C1,stroke-width:2px,color:#D8DEE9;
    classDef ui fill:#5E81AC,stroke:#81A1C1,stroke-width:2px,color:#ECEFF4;
    classDef data fill:#81A1C1,stroke:#81A1C1,stroke-width:2px,color:#ECEFF4;
    classDef domain fill:#88C0D0,stroke:#81A1C1,stroke-width:2px,color:#ECEFF4;
```
