# valterandremachado/recipecraze architecture

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

- Interactive diagram: https://gitdiagram.com/valterandremachado/recipecraze
- Repository: https://github.com/valterandremachado/recipecraze

## Overview

##### Main Components
- UI Layer (View):
– Derived from the “Recipe Craze/MyApp” and “Recipe Craze/View” folders.
– Contains screen components for Authentication (LoginVC, SignupVC, ForgotPasswordVC, OnboardingVC), Home (HomeVC, FoodInfoVC, OnScreenStepsVC), Categories (CategoryVC, CategoryDetailsVC), Favorites (FavoriteVC), and Search (SearchVC).
- ViewModel Layer:
– Located in the “Recipe Craze/ViewModel” directory.
– Contains specific view models like CategoryViewModel, RecipeViewModel, UserAuthViewModel, and UserRegistrationViewModel that mediate between the UI and data models.
- Model / Data Layer:
– Found primarily in the “Recipe Craze/Model” folder.
– Holds entities like Recipe, CategoryModel, FavoritedRecipe, and also service classes such as RecipeService and CategoryService for fetching/parsing data from the JSON API (using URLSession).
- Persistence Layer:
– Two subparts:
° Core Data: Managed in “Recipe Craze/CoreData” and extensions/models like FavoritedRecipeToCD, PersistenceManager.swift, and the CoreDataModel.
° Realm Database: Indicated under “Recipe Craze/RealDatabase” including RealmService and RecipeRealmObject.
- External Services & Networking:
– Networking components are implied in the Model layer (JSON API parsing via URLSession and usage of JSONSerialization).
– Firebase services (for Auth and Database, as mentioned in the README) need to be represented as external services.
- Utilities & Helpers:
– Utilities in “Recipe Craze/utils” (e.g., Extensions, SpeechService, custom UI components, feedback generators) serve as supporting components across the project.

##### Relationships and Interactions
- UI components (Views and View Controllers) interact with their corresponding ViewModels.
- The ViewModels handle business logic and coordinate with the Models/Services:
– They request data from the network using URLSession.
– They handle persistence by communicating with the Core Data and Realm layers.
- The Models also interact directly with the external services like Firebase for authentication and real-time database updates.
- Utility classes provide cross-cutting support (e.g., UI feedback, custom behaviors) to both the UI and business logic layers.

##### Architectural Patterns and Design Principles
- The MVVM Pattern: Clearly separate the View (UI), ViewModels (presentation logic), and Models (data and business logic).
- Data Persistence Separation: Highlight the use of Core Data for storing favorited recipes along with an alternative Realm-based persistence layer.
- External Integration: Show how external services (Firebase for auth and data, JSON API via URLSession) integrate with the core application.

##### Including Relevant Technologies, Frameworks, and Libraries
- UIKit is the framework used for the UI layer.
- Core Data and Realm represent local data persistence.
- Firebase (Auth and Database) is integrated for user management and remote data service.
- The project uses URLSession for network calls and JSONSerialization for API data parsing.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "User Interface"
        UI_MyApp["Application Entry (MyApp)"]:::ui
        UI_View["View Components (View)"]:::ui
        UI_Auth["Auth Screens (LoginVC, SignupVC, ForgotPasswordVC, OnboardingVC)"]:::ui
        UI_Home["Home Screens (HomeVC, FoodInfoVC, OnScreenStepsVC)"]:::ui
        UI_Category["Category Screens (CategoryVC, CategoryDetailsVC)"]:::ui
        UI_Favorites["Favorites Screen (FavoriteVC)"]:::ui
        UI_Search["Search Screen (SearchVC)"]:::ui
    end

    %% ViewModel Layer
    subgraph "ViewModel Layer"
        VM_Category["CategoryViewModel"]:::viewmodel
        VM_Recipe["RecipeViewModel"]:::viewmodel
        VM_UserAuth["UserAuthViewModel"]:::viewmodel
        VM_UserReg["UserRegistrationViewModel"]:::viewmodel
    end

    %% Model / Data Layer
    subgraph "Models & Services"
        M_CategoryModel["CategoryModel"]:::model
        M_Recipe["Recipe"]:::model
        M_RecipeService["RecipeService"]:::model
        M_CategoryService["CategoryService"]:::model
        M_FavoritedRecipe["FavoritedRecipe"]:::model
        M_Protocols["Protocols"]:::model
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        subgraph "Core Data"
            P_PersistenceManager["PersistenceManager"]:::persistence
            P_CoreDataModel["CoreDataModel"]:::persistence
            P_FavRecipeClass["FavoritedRecipeToCD Class"]:::persistence
            P_FavRecipeProps["FavoritedRecipeToCD Properties"]:::persistence
        end
        subgraph "Realm Database"
            P_RealmService["RealmService"]:::persistence
            P_RecipeRealm["RecipeRealmObject"]:::persistence
        end
    end

    %% External Services & Networking
    subgraph "External Services & Networking"
        EX_Network["JSON API (URLSession, JSONSerialization)"]:::external
        EX_FirebaseAuth["Firebase Auth"]:::external
        EX_FirebaseDB["Firebase Database"]:::external
    end

    %% Utilities & Helpers
    subgraph "Utilities & Helpers"
         U_Utilities["Utilities (Extensions, SpeechService, etc.)"]:::utils
    end

    %% Connections from UI Layer to ViewModel Layer
    UI_Auth -->|"triggers"| VM_UserAuth
    UI_Auth -->|"triggers"| VM_UserReg
    UI_Home -->|"triggers"| VM_Recipe
    UI_Category -->|"triggers"| VM_Category
    UI_Favorites -->|"triggers"| VM_Recipe
    UI_Search -->|"triggers"| VM_Recipe
    UI_MyApp --> UI_Auth
    UI_MyApp --> UI_Home
    UI_View --> UI_Category
    UI_View --> UI_Favorites
    UI_View --> UI_Search

    %% Connections from ViewModels to Models & Services
    VM_Category -->|"fetches"| M_CategoryModel
    VM_Category -->|"invokes"| M_CategoryService
    VM_Recipe -->|"fetches"| M_Recipe
    VM_Recipe -->|"invokes"| M_RecipeService
    VM_UserAuth -->|"auth logic"| M_Protocols
    VM_UserReg -->|"registration logic"| M_Protocols

    %% Connections from Models & Services to Persistence and External
    M_RecipeService -->|"calls"| EX_Network
    M_CategoryService -->|"calls"| EX_Network
    M_FavoritedRecipe -->|"persists"| P_PersistenceManager
    M_FavoritedRecipe -->|"persists"| P_RealmService
    VM_UserAuth -->|"authenticates"| EX_FirebaseAuth
    M_RecipeService -->|"syncs"| EX_FirebaseDB

    %% Utilities support both UI and ViewModels
    U_Utilities ---|"enhances"| UI_MyApp
    U_Utilities ---|"enhances"| VM_Recipe

    %% Click Events for Component Mapping
    click UI_MyApp "https://github.com/valterandremachado/recipecraze/tree/master/Recipe Craze/MyApp"
    click UI_View "https://github.com/valterandremachado/recipecraze/tree/master/Recipe Craze/View"
    click VM_Category "https://github.com/valterandremachado/recipecraze/blob/master/Recipe Craze/ViewModel/CategoryViewModel.swift"
    click VM_Recipe "https://github.com/valterandremachado/recipecraze/blob/master/Recipe Craze/ViewModel/RecipeViewModel.swift"
    click VM_UserAuth "https://github.com/valterandremachado/recipecraze/blob/master/Recipe Craze/ViewModel/UserAuthViewModel.swift"
    click VM_UserReg "https://github.com/valterandremachado/recipecraze/blob/master/Recipe Craze/ViewModel/UserRegistrationViewModel.swift"
    click M_CategoryModel "https://github.com/valterandremachado/recipecraze/blob/master/Recipe Craze/Model/CategoryModel.swift"
    click M_Recipe "https://github.com/valterandremachado/recipecraze/blob/master/Recipe Craze/Model/Recipe.swift"
    click M_RecipeService "https://github.com/valterandremachado/recipecraze/blob/master/Recipe Craze/Model/RecipeService.swift"
    click M_CategoryService "https://github.com/valterandremachado/recipecraze/blob/master/Recipe Craze/Model/CategoryService.swift"
    click M_FavoritedRecipe "https://github.com/valterandremachado/recipecraze/blob/master/Recipe Craze/Model/FavoritedRecipe.swift"
    click M_Protocols "https://github.com/valterandremachado/recipecraze/blob/master/Recipe Craze/Model/Protocols.swift"
    click P_PersistenceManager "https://github.com/valterandremachado/recipecraze/blob/master/Recipe Craze/CoreData/PersistenceManager.swift"
    click P_CoreDataModel "https://github.com/valterandremachado/recipecraze/blob/master/Recipe Craze/CoreData/CoreDataModel.xcdatamodeld"
    click P_FavRecipeClass "https://github.com/valterandremachado/recipecraze/blob/master/Recipe Craze/CoreData/FavoritedRecipeToCD+CoreDataClass.swift"
    click P_FavRecipeProps "https://github.com/valterandremachado/recipecraze/blob/master/Recipe Craze/CoreData/FavoritedRecipeToCD+CoreDataProperties.swift"
    click P_RealmService "https://github.com/valterandremachado/recipecraze/blob/master/Recipe Craze/RealDatabase/RealmService.swift"
    click P_RecipeRealm "https://github.com/valterandremachado/recipecraze/blob/master/Recipe Craze/RealDatabase/RecipeRealmObject.swift"
    click EX_FirebaseAuth "https://github.com/valterandremachado/recipecraze/blob/master/Recipe Craze/MyApp/GoogleService-Info.plist"
    click EX_FirebaseDB "https://github.com/valterandremachado/recipecraze/blob/master/Recipe Craze/MyApp/GoogleService-Info.plist"
    click U_Utilities "https://github.com/valterandremachado/recipecraze/tree/master/Recipe Craze/utils"

    %% Styles
    classDef ui fill:#F4CCCC,stroke:#cc0000,stroke-width:2px;
    classDef viewmodel fill:#C9DAF8,stroke:#1155CC,stroke-width:2px;
    classDef model fill:#FFF2CC,stroke:#e69138,stroke-width:2px;
    classDef persistence fill:#D9EAD3,stroke:#6AA84F,stroke-width:2px;
    classDef external fill:#D0E0E3,stroke:#3C78D8,stroke-width:2px;
    classDef utils fill:#EAD1DC,stroke:#B8549E,stroke-width:2px;
```
