# hamzashabbir07/foodapp architecture

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

- Interactive diagram: https://gitdiagram.com/hamzashabbir07/foodapp
- Repository: https://github.com/hamzashabbir07/foodapp

## Overview

##### Project type and purpose
- From the file tree and the minimal README (“FoodApp”), we see this is an Android mobile application (“RecipeApp”) written in Kotlin.
- Its purpose is to fetch recipe and category data from a remote API, cache/store it in a local Room database, and display it in various Activities using RecyclerViews.

##### File structure
- Top‐level “app” module: contains build.gradle, src (main & test), res, AndroidManifest.
- Under app/src/main/java/com/codingwithme/recipeapp:
- UI layer: BaseActivity, SplashActivity, HomeActivity, DetailActivity, plus adapter package (MainCategoryAdapter, SubCategoryAdapter)
- Data access: dao package (RecipeDao), database package (RecipeDatabase)
- Entities: data classes under entities, plus converter subpackage for Room type converters
- Network: interfaces package (GetDataService), retofitclient package (RetrofitClientInstance)
- There is no separate backend; the remote service is an external recipes API.

##### Key technical stack
- Presentation: Android Activities, XML layouts, RecyclerViews & Adapters
- Local persistence: Room database (RecipeDatabase, RecipeDao, Entities, Converters)
- Networking: Retrofit (RetrofitClientInstance), JSON mapping to data classes (MealResponse, CategoryItems, etc.)
- Gradle build system

a. Presentation Layer
- Activities (Splash → Home → Detail)
- RecyclerView Adapters (MainCategoryAdapter, SubCategoryAdapter)
b. Data Layer
- Local Room Database (RecipeDatabase)
- DAO (RecipeDao)
- Entities & Converters
c. Network Layer
- RetrofitClientInstance (singleton HTTP client)
- GetDataService interface (endpoints for categories, meals)
d. External Service
- Third‐party Recipe API (over HTTPS)

##### Relationships and data flows
- SplashActivity triggers the initial data load.
- On API response → map JSON to data classes (e.g., CategoryItems, MealResponse)
- Persist via RecipeDao into RecipeDatabase
- HomeActivity reads categories/meals
- Adapter binds data to RecyclerView
- On item click → navigate to DetailActivity
- DetailActivity may fetch a single recipe (either via API or local cache)

##### Architectural patterns/design principles
- Layered architecture: Presentation ↔ Data ↔ Network
- Singletons for shared resources (RetrofitClientInstance, RecipeDatabase)
- Separation of concerns: UI does not directly parse JSON; uses network and DAO abstractions
- Use of data classes and type converters for immutability and database storage

- Zone 1 (UI): Splash, Home, Detail, Adapters
- Zone 2 (Local Data): RecipeDatabase + DAO + Entities
- Zone 3 (Network): RetrofitClientInstance + GetDataService
- Zone 4 (External): Recipe API
- Component’s name, role, and dependencies are explicit

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        SplashActivity["SplashActivity"]:::ui
        HomeActivity["HomeActivity"]:::ui
        DetailActivity["DetailActivity"]:::ui
        BaseActivity["BaseActivity"]:::ui
        MainCategoryAdapter["MainCategoryAdapter"]:::ui
        SubCategoryAdapter["SubCategoryAdapter"]:::ui
    end

    %% Local Data Layer
    subgraph "Local Data Layer"
        direction TB
        RecipeDatabase[(RecipeDatabase)]:::data
        RecipeDao["RecipeDao"]:::data
        subgraph "Entities & Converters"
            direction TB
            Category["Category"]:::data
            CategoryItems["CategoryItems"]:::data
            Meal["Meal"]:::data
            MealResponse["MealResponse"]:::data
            MealsItems["MealsItems"]:::data
            Recipes["Recipes"]:::data
            CategoryListConverter["CategoryListConverter"]:::data
            MealListConverter["MealListConverter"]:::data
        end
    end

    %% Network Layer
    subgraph "Network Layer"
        direction TB
        RetrofitClientInstance["RetrofitClientInstance"]:::network
        GetDataService["GetDataService"]:::network
    end

    %% External Service
    ExternalAPI[(Recipe API)]:::external

    %% Data Flows
    SplashActivity -->|"fetchCategories()"| RetrofitClientInstance
    RetrofitClientInstance --> GetDataService
    GetDataService -->|"GET /categories & /meals"| ExternalAPI
    ExternalAPI --> GetDataService
    GetDataService -->|"map JSON"| CategoryItems
    CategoryItems -->|"insertCategories()"| RecipeDao
    RecipeDao --> RecipeDatabase

    HomeActivity -->|"getAllCategories()"| RecipeDao
    RecipeDao --> CategoryItems
    CategoryItems --> MainCategoryAdapter
    MainCategoryAdapter --> SubCategoryAdapter
    HomeActivity -->|"navigateTo(DetailActivity)"| DetailActivity

    DetailActivity -->|"getRecipeById()"| RecipeDao
    DetailActivity -->|"fetch if missing"| GetDataService

    %% Click Events
    click SplashActivity "https://github.com/hamzashabbir07/foodapp/blob/main/app/src/main/java/com/codingwithme/recipeapp/SplashActivity.kt"
    click HomeActivity "https://github.com/hamzashabbir07/foodapp/blob/main/app/src/main/java/com/codingwithme/recipeapp/HomeActivity.kt"
    click DetailActivity "https://github.com/hamzashabbir07/foodapp/blob/main/app/src/main/java/com/codingwithme/recipeapp/DetailActivity.kt"
    click BaseActivity "https://github.com/hamzashabbir07/foodapp/blob/main/app/src/main/java/com/codingwithme/recipeapp/BaseActivity.kt"
    click MainCategoryAdapter "https://github.com/hamzashabbir07/foodapp/blob/main/app/src/main/java/com/codingwithme/recipeapp/adapter/MainCategoryAdapter.kt"
    click SubCategoryAdapter "https://github.com/hamzashabbir07/foodapp/blob/main/app/src/main/java/com/codingwithme/recipeapp/adapter/SubCategoryAdapter.kt"
    click RecipeDatabase "https://github.com/hamzashabbir07/foodapp/blob/main/app/src/main/java/com/codingwithme/recipeapp/database/RecipeDatabase.kt"
    click RecipeDao "https://github.com/hamzashabbir07/foodapp/blob/main/app/src/main/java/com/codingwithme/recipeapp/dao/RecipeDao.kt"
    click Category "https://github.com/hamzashabbir07/foodapp/blob/main/app/src/main/java/com/codingwithme/recipeapp/entities/Category.kt"
    click CategoryItems "https://github.com/hamzashabbir07/foodapp/blob/main/app/src/main/java/com/codingwithme/recipeapp/entities/CategoryItems.kt"
    click Meal "https://github.com/hamzashabbir07/foodapp/blob/main/app/src/main/java/com/codingwithme/recipeapp/entities/Meal.kt"
    click MealResponse "https://github.com/hamzashabbir07/foodapp/blob/main/app/src/main/java/com/codingwithme/recipeapp/entities/MealResponse.kt"
    click MealsItems "https://github.com/hamzashabbir07/foodapp/blob/main/app/src/main/java/com/codingwithme/recipeapp/entities/MealsItems.kt"
    click Recipes "https://github.com/hamzashabbir07/foodapp/blob/main/app/src/main/java/com/codingwithme/recipeapp/entities/Recipes.kt"
    click CategoryListConverter "https://github.com/hamzashabbir07/foodapp/blob/main/app/src/main/java/com/codingwithme/recipeapp/entities/converter/CategoryListConverter.kt"
    click MealListConverter "https://github.com/hamzashabbir07/foodapp/blob/main/app/src/main/java/com/codingwithme/recipeapp/entities/converter/MealListConverter.kt"
    click RetrofitClientInstance "https://github.com/hamzashabbir07/foodapp/blob/main/app/src/main/java/com/codingwithme/recipeapp/retofitclient/RetrofitClientInstance.kt"
    click GetDataService "https://github.com/hamzashabbir07/foodapp/blob/main/app/src/main/java/com/codingwithme/recipeapp/interfaces/GetDataService.kt"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#0288D1,stroke-width:1px
    classDef data fill:#E8F5E9,stroke:#388E3C,stroke-width:1px
    classDef network fill:#FFF3E0,stroke:#F57C00,stroke-width:1px
    classDef external fill:#ECEFF1,stroke:#607D8B,stroke-width:1px
```
