# danielkosgei/ingrediet architecture

> Architecture diagram of the GitHub repository danielkosgei/ingrediet, 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/danielkosgei/ingrediet
- Repository: https://github.com/danielkosgei/ingrediet

## Overview

##### Project Type and Purpose
- The project is an Android mobile application built with Jetpack Compose.
- It follows an MVVM architecture pattern with clear separations in the UI, domain, and data layers.
- The app leverages external services via Supabase for backend data (user authentication, recipe data, etc.) and integrates with multiple APIs (Spoonacular, TheMealDb, OpenFoodFacts, and custom KenyanFoodsService) for recipe-related data.

##### File Structure
- Top-Level Directories:
- The root contains build scripts, Gradle wrappers, and essentials for an Android project.
- The “app” directory holds the application-specific code including source code under “app/src/main/java”.
- The “supabase” directory indicates backend infrastructure with SQL migration files for setting up user profiles, recipes, ingredients, etc.
- Inside the app source, the code is further organized into:
- data (models, network managers, API service implementations, repositories)
- feature (modular implementations for different parts of the app like authentication, recipe details, meal planner, favorites, shopping list, and profile)
- ui and theme (Jetpack Compose UI components and design themes)
- There is a test structure as well, indicating unit and UI testing efforts.

a. Main Components to Include:
- Android Client – This is the mobile application layer.
- UI Layer (Jetpack Compose Screens): Home Screen, Recipe Detail Screen, Login/Register, and additional screens for favorites, meal planning, shopping, etc.
- ViewModel Layer: Implements MVVM with various view models (e.g., MealPlannerViewModel, FavoritesViewModel, etc.).
- Data Layer:
- Models: Domain models like Recipe, Profile, and UserMealPlan.
- Repositories: Responsible for managing data interactions (e.g., RecipeRepository, ProfileRepository, ShoppingListRepository, MealPlanRepository).
- Network Service Layer: Contains API interfaces (e.g., SpoonacularService, RecipeService, TheMealDbService, KenyanFoodsService) and network managers (AuthManager, CacheManager, SessionManager).
- Supabase Client: Integration with Supabase for backend operations like user management and recipe storage.
- External Services and APIs:
- Supabase Backend: Handles database, authentication, and server-side business logic.
- Other Third-Party APIs: Spoonacular for nutrient and recipe info, OpenFoodFacts, TheMealDb, and specialized services for Kenyan foods.
b. Relationships and Interactions:
- UI components interact with their respective ViewModels.
- ViewModels use repositories to access data, abstracting away the source (local or remote).
- Repositories interact with the network layer (using SupabaseClient and RESTful API services) for data fetching and updating.
- CacheManager and SessionManager manage state, session, and caching concerns between the mobile client and backend services.
c. Architectural Patterns and Principles:
- MVVM: Clearly separates view and business logic.
- Repository Pattern: Used to abstract data sources.
- Dependency Injection (even though the “di” package isn’t fully shown in the file tree, it is standard in such architectures).
- Use of Coroutines & Flow for asynchronous data operations.
d. Relevant Technologies:
- Kotlin, Jetpack Compose, Material 3
- Supabase as the cloud backend
- Integration with external APIs using Retrofit or similar HTTP client libraries
- Gradle for build automation

##### Emphasizing Details
- That every architectural element—from the hosting of source code like “data,” “feature,” and “ui” modules to the integration of Supabase through SQL migrations—is depicted.
- Clearly articulate the data flow:
User Actions (UI) → ViewModel (Business Logic) → Repository (Data Management) → Network/API Modules → Backend (Supabase & Third-party services) → Data returned back through the same layers.
- Detail any caching or session handling, as these are crucial for network operations in mobile contexts.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Mobile Application Layer
    subgraph "Mobile Application"
        AC["Android Client"]:::mobile
        UI["UI Layer (Jetpack Compose Screens & Theme)"]:::mobile
        VM["ViewModel Layer (Business Logic)"]:::mobile
    end

    %% Data Layer
    subgraph "Data Layer"
        M["Models"]:::data
        R["Repositories"]:::data
        subgraph "Network Services"
            SC["Supabase Client"]:::network
            NM["Network Managers (Auth,Cache,Session)"]:::network
            API["API Service Implementations"]:::network
        end
    end

    %% External Services
    subgraph "External Services"
        SB["Supabase Backend"]:::external
        TP["Third Party APIs (Spoonacular,TheMealDb,OpenFoodFacts,KenyanFoodsService)"]:::external
    end

    %% Relationships
    UI -->|"triggers"| VM
    VM -->|"calls"| R
    R -->|"maps"| M
    R -->|"syncs"| SC
    R -->|"manages"| NM
    R -->|"fetches"| API
    API -->|"API_call"| TP
    SC -->|"DB_ops"| SB

    %% Styling Classes
    classDef mobile fill:#b3e5fc,stroke:#0288d1,stroke-width:2px;
    classDef data fill:#c5e1a5,stroke:#558b2f,stroke-width:2px;
    classDef network fill:#ffcc80,stroke:#f57c00,stroke-width:2px;
    classDef external fill:#ef9a9a,stroke:#c62828,stroke-width:2px;

    %% Click Events
    click AC "https://github.com/danielkosgei/ingrediet/blob/main/app/src/main/java/com/thenewkenya/ingrediet/MainActivity.kt"
    click UI "https://github.com/danielkosgei/ingrediet/tree/main/app/src/main/java/com/thenewkenya/ingrediet/ui"
    click VM "https://github.com/danielkosgei/ingrediet/tree/main/app/src/main/java/com/thenewkenya/ingrediet/feature"
    click M "https://github.com/danielkosgei/ingrediet/tree/main/app/src/main/java/com/thenewkenya/ingrediet/data/model"
    click R "https://github.com/danielkosgei/ingrediet/tree/main/app/src/main/java/com/thenewkenya/ingrediet/data/repository"
    click SC "https://github.com/danielkosgei/ingrediet/blob/main/app/src/main/java/com/thenewkenya/ingrediet/data/network/SupabaseClient.kt"
    click NM "https://github.com/danielkosgei/ingrediet/tree/main/app/src/main/java/com/thenewkenya/ingrediet/data/network"
    click API "https://github.com/danielkosgei/ingrediet/tree/main/app/src/main/java/com/thenewkenya/ingrediet/data/network/api"
    click SB "https://github.com/danielkosgei/ingrediet/tree/main/supabase"
```
