# patilshreyas/foodium architecture

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

- Interactive diagram: https://gitdiagram.com/patilshreyas/foodium
- Repository: https://github.com/patilshreyas/foodium

## Overview

##### Project type and purpose
- This is a single-module Android client application (“app” folder) written in Kotlin, following MVVM (Model-View-ViewModel) architecture.
- Purpose: fetch “Posts” from a remote JSON API, persist them in a local SQLite database (using Room), and present them in a Material UI. It’s designed to be offline-capable, synchronized, and demonstrate modern Android development (Coroutines, Flow, Hilt, Retrofit, Coil, etc.).

##### File structure
- Top-level “app” module:
– data/: local (Room schemas, DAOs, DatabaseMigrations), remote (Retrofit API interface), repository (NetworkBoundRepository, PostRepository).
– di/: Hilt modules (ApiModule, DatabaseModule, RepositoryModule).
– model/: data classes (Post, State).
– ui/: presentation code split into base, main (Activity + ViewModel + adapter + viewholder), details (Activity + ViewModel).
– utils/: helper functions (ActivityUtils, NetworkUtils, TimeUtils, ViewUtils).
– resources: layouts, drawables, menus, themes.
- Build/config: Gradle Kotlin DSL scripts, ProGuard rules, GitHub workflows for build, test, lint, and publish.

##### README for additional insights
- Confirms MVVM, Android Architecture Components (LiveData, ViewModel, Room), Coroutines & Flow, dependency injection (Hilt), Retrofit + Moshi, Coil for image loading, Material Components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        MA["MainActivity"]:::presentation
        MVM["MainViewModel"]:::presentation
        PDA["PostDetailsActivity"]:::presentation
        PDVM["PostDetailsViewModel"]:::presentation
        PLA["PostListAdapter"]:::presentation
        PVH["PostViewHolder"]:::presentation
    end

    %% Domain Layer
    subgraph "Domain/Data Layer"
        direction TB
        PR["PostRepository"]:::domain
        NBR["NetworkBoundRepository"]:::domain
        RES["Resource&lt;T&gt;"]:::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        direction TB
        DAO["PostsDao"]:::infra
        DB["FoodiumPostsDatabase"]:::infra
        MIG["DatabaseMigrations"]:::infra
        FS["FoodiumService"]:::infra
    end

    %% External
    subgraph "External"
        direction TB
        API["Dummy JSON API\n(HTTP/JSON)"]:::external
    end

    %% Dependency Injection
    subgraph "Dependency Injection"
        direction TB
        AM["ApiModule"]:::di
        DM["DatabaseModule"]:::di
        RM["RepositoryModule"]:::di
    end

    %% Presentation interactions
    MA -->|"binds to"| MVM
    PDA -->|"binds to"| PDVM
    MA -->|"uses"| PLA
    PLA -->|"creates"| PVH

    %% ViewModel to Repository
    MVM -->|"getPosts()": Flow&lt;Resource&gt;| PR
    PDVM -->|"getPostById(id)"| PR

    %% Repository internals
    PR -->|"extends"| NBR
    PR -->|"uses"| RES
    PR -->|"loadFromDb()": List&lt;Post&gt;| DAO
    PR -->|"fetchPostsFromApi()": List&lt;Post&gt;| FS
    FS -->|"HTTP GET"| API
    PR -->|"insertAll()"| DAO
    DAO -->|"queries"| DB

    %% DI wiring
    AM -->|"provides Retrofit & Moshi"| FS
    DM -->|"provides Database & DAO"| DB
    DM -->|"provides Database & DAO"| DAO
    RM -->|"binds PostRepository"| PR

    %% Models (for context)
    subgraph "Models"
        direction TB
        POST["Post"]:::infra
        STATE["State"]:::infra
    end
    POST --- PR
    STATE --- RES

    %% Click Events
    click MA "https://github.com/patilshreyas/foodium/blob/master/app/src/main/java/dev/shreyaspatil/foodium/ui/main/MainActivity.kt"
    click MVM "https://github.com/patilshreyas/foodium/blob/master/app/src/main/java/dev/shreyaspatil/foodium/ui/main/MainViewModel.kt"
    click PDA "https://github.com/patilshreyas/foodium/blob/master/app/src/main/java/dev/shreyaspatil/foodium/ui/details/PostDetailsActivity.kt"
    click PDVM "https://github.com/patilshreyas/foodium/blob/master/app/src/main/java/dev/shreyaspatil/foodium/ui/details/PostDetailsViewModel.kt"
    click PLA "https://github.com/patilshreyas/foodium/blob/master/app/src/main/java/dev/shreyaspatil/foodium/ui/main/adapter/PostListAdapter.kt"
    click PVH "https://github.com/patilshreyas/foodium/blob/master/app/src/main/java/dev/shreyaspatil/foodium/ui/main/viewholder/PostViewHolder.kt"
    click PR "https://github.com/patilshreyas/foodium/blob/master/app/src/main/java/dev/shreyaspatil/foodium/data/repository/PostRepository.kt"
    click NBR "https://github.com/patilshreyas/foodium/blob/master/app/src/main/java/dev/shreyaspatil/foodium/data/repository/NetworkBoundRepository.kt"
    click RES "https://github.com/patilshreyas/foodium/blob/master/app/src/main/java/dev/shreyaspatil/foodium/data/repository/Resource.kt"
    click DAO "https://github.com/patilshreyas/foodium/blob/master/app/src/main/java/dev/shreyaspatil/foodium/data/local/dao/PostsDao.kt"
    click DB "https://github.com/patilshreyas/foodium/blob/master/app/src/main/java/dev/shreyaspatil/foodium/data/local/FoodiumPostsDatabase.kt"
    click MIG "https://github.com/patilshreyas/foodium/blob/master/app/src/main/java/dev/shreyaspatil/foodium/data/local/DatabaseMigrations.kt"
    click FS "https://github.com/patilshreyas/foodium/blob/master/app/src/main/java/dev/shreyaspatil/foodium/data/remote/api/FoodiumService.kt"
    click AM "https://github.com/patilshreyas/foodium/blob/master/app/src/main/java/dev/shreyaspatil/foodium/di/module/FoodiumApiModule.kt"
    click DM "https://github.com/patilshreyas/foodium/blob/master/app/src/main/java/dev/shreyaspatil/foodium/di/module/FoodiumDatabaseModule.kt"
    click RM "https://github.com/patilshreyas/foodium/blob/master/app/src/main/java/dev/shreyaspatil/foodium/di/module/PostRepositoryModule.kt"
    click POST "https://github.com/patilshreyas/foodium/blob/master/app/src/main/java/dev/shreyaspatil/foodium/model/Post.kt"
    click STATE "https://github.com/patilshreyas/foodium/blob/master/app/src/main/java/dev/shreyaspatil/foodium/model/State.kt"

    %% Styles
    classDef presentation fill:#BBDEFB,stroke:#1E88E5,stroke-width:2px
    classDef domain fill:#C8E6C9,stroke:#43A047,stroke-width:2px
    classDef infra fill:#FFE0B2,stroke:#FB8C00,stroke-width:2px
    classDef external fill:#CFD8DC,stroke:#546E7A,stroke-width:2px
    classDef di fill:#D1C4E9,stroke:#8E24AA,stroke-width:2px
```
