# hieuwu/android-groceries-store architecture

> Architecture diagram of the GitHub repository hieuwu/android-groceries-store, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hieuwu/android-groceries-store
- Repository: https://github.com/hieuwu/android-groceries-store

## Overview

##### Project Type & Purpose
- This is a full-stack mobile application (“Groceries Store”) built on Android.
- Purpose: enable users to browse products, manage a shopping cart, create orders, plan meals, and receive notifications. It demonstrates modern Android development (Clean Architecture, MVVM, Use Cases) and leverages Supabase as a backend.

##### File Structure Analysis
- Top level: build scripts, CI configs, docs, database dumps.
- “app/src/main/java/com/hieuwu/groceriesstore” subdivides into:
- presentation/ – UI layer (Activities, Fragments, Composables, ViewModels)
- domain/ – business logic (use cases, models, use case interfaces + implementations)
- data/ – repository implementations, local database (Room) DAOs/entities, network layer (Retrofit, DTOs)
- di/ – Hilt modules for providing dependencies (Database, Repositories, Use Cases, Dispatchers, Supabase, SharedPrefs)
- utilities/ & works/ – helpers (e.g., for FCM, WorkManager jobs)
- Assets and resources under res/ (layouts, navigation graphs, drawables, animations).
- Configs: google-services.json, Supabase config in DI module.
- Tests under app/src/test for unit testing domain use cases.

##### README Insights
- Architecture claims: Clean Architecture with Use Case pattern and MVVM.
- Technologies: Kotlin, Hilt, Room, Retrofit2, Moshi, Supabase, Firebase Cloud Messaging, WorkManager, Jetpack Compose UI elements.

a. Main Components
- Mobile Client UI (Presentation Layer)
- ViewModel Layer
- Domain Layer (Use Cases)
- Data Layer
- Local Data Source: Room Database + DAOs
- Remote Data Source: Supabase REST API via Retrofit/Moshi
- Dependency Injection (Hilt Modules)
- Background Workers: WorkManager jobs (e.g., RefreshDatabaseWork)
- Notification Service: Firebase Cloud Messaging
- External Services: Supabase backend, Firebase Cloud Messaging

b. Relationships & Interactions
- UI → ViewModel (state & events)
- ViewModel → Use Cases (invoke business logic)
- Use Cases → Repository Interface → Repository Implementation
- Repository Implementation chooses between Local (Room) or Remote (Supabase via ApiService)
- DI Graph wires up all interfaces to implementations
- WorkManager triggers background sync → Data Layer → updates local DB
- FCM receives push → Notification Service → UI or Data Layer

c. Architectural Patterns & Principles
- Clean Architecture with 3 layers (Presentation / Domain / Data)
- MVVM in Presentation
- Single Responsibility (Use Cases each handle one action)
- Dependency Inversion (repositories, use cases as interfaces injected by Hilt)
- Repository Pattern abstracting data sources
- Jetpack best practices (ViewModel, Lifecycle, Room, WorkManager)

d. Key Technologies & Frameworks
- Kotlin + Coroutines
- Hilt for DI
- Retrofit2 + Moshi for network
- Room for local persistence
- Supabase REST API (Auth, CRUD)
- Firebase Cloud Messaging for notifications
- WorkManager for scheduled database refresh
- Jetpack Compose widgets and XML layouts

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        UI["Mobile Client UI"]:::presentation
        VM["ViewModel"]:::presentation
        NotificationService["FCM Service"]:::presentation
    end

    %% Domain Layer
    subgraph "Domain Layer"
        UC["Use Cases"]:::domain
        Models["Domain Models"]:::domain
    end

    %% Data Layer
    subgraph "Data Layer"
        subgraph "Local Data Source"
            DB["Room Database"]:::data
            DAOs["DAOs & Entities"]:::data
        end
        subgraph "Remote Data Source"
            API["Supabase API (Retrofit/Moshi)"]:::data
            DTOs["DTOs"]:::data
        end
        RepoInterfaces["Repository Interfaces"]:::data
        Repos["Repository Implementations"]:::data
    end

    %% Background Worker
    Worker["WorkManager Job\n(RefreshDatabaseWork)"]:::worker

    %% Dependency Injection
    DI["Hilt DI Modules"]:::di

    %% External Services
    Supabase["Supabase Backend"]:::external
    FCM["Firebase Cloud Messaging"]:::external

    %% Connections
    UI -->|interacts with| VM
    VM -->|invokes| UC
    UC -->|depends on| Models
    UC -->|uses interface| RepoInterfaces
    RepoInterfaces -->|bound to| Repos
    Repos -->|reads/writes| DB
    Repos -->|calls| API
    DB -->|accesses| DAOs
    API -->|transfers via| DTOs
    API -->|HTTP calls| Supabase
    Supabase -->|pushes notifications| FCM
    FCM -->|delivers to| NotificationService
    NotificationService -->|updates| UI
    Worker -->|executes use cases via| Repos
    Worker -->|syncs| DB

    %% DI bindings
    DI -->|provides| VM
    DI -->|provides| UC
    DI -->|provides| RepoInterfaces
    DI -->|provides| Repos
    DI -->|provides| API
    DI -->|provides| DB

    %% Click Events
    click UI "https://github.com/hieuwu/android-groceries-store/tree/main/app/src/main/java/com/hieuwu/groceriesstore/presentation"
    click VM "https://github.com/hieuwu/android-groceries-store/blob/main/app/src/main/java/com/hieuwu/groceriesstore/presentation/cart/CartViewModel.kt"
    click UC "https://github.com/hieuwu/android-groceries-store/tree/main/app/src/main/java/com/hieuwu/groceriesstore/domain/usecases"
    click RepoInterfaces "https://github.com/hieuwu/android-groceries-store/tree/main/app/src/main/java/com/hieuwu/groceriesstore/data/repository"
    click Repos "https://github.com/hieuwu/android-groceries-store/tree/main/app/src/main/java/com/hieuwu/groceriesstore/data/repository/impl"
    click DB "https://github.com/hieuwu/android-groceries-store/blob/main/app/src/main/java/com/hieuwu/groceriesstore/data/database/GroceriesStoreDatabase.kt"
    click DAOs "https://github.com/hieuwu/android-groceries-store/tree/main/app/src/main/java/com/hieuwu/groceriesstore/data/database/dao"
    click API "https://github.com/hieuwu/android-groceries-store/blob/main/app/src/main/java/com/hieuwu/groceriesstore/data/network/ApiService.kt"
    click DTOs "https://github.com/hieuwu/android-groceries-store/tree/main/app/src/main/java/com/hieuwu/groceriesstore/data/network/dto"
    click DI "https://github.com/hieuwu/android-groceries-store/tree/main/app/src/main/java/com/hieuwu/groceriesstore/di"
    click Worker "https://github.com/hieuwu/android-groceries-store/blob/main/app/src/main/java/com/hieuwu/groceriesstore/works/RefreshDatabaseWork.kt"
    click NotificationService "https://github.com/hieuwu/android-groceries-store/blob/main/app/src/main/java/com/hieuwu/groceriesstore/presentation/notification/FirebaseCloudMessageService.kt"

    %% Styles
    classDef presentation fill:#BBDEFB,stroke:#2196F3;
    classDef domain fill:#C8E6C9,stroke:#388E3C;
    classDef data fill:#FFE0B2,stroke:#F57C00;
    classDef external fill:#E1BEE7,stroke:#8E24AA,stroke-dasharray: 5 5;
    classDef worker fill:#FFCCBC,stroke:#D84315;
    classDef di fill:#D7CCC8,stroke:#6D4C41;
```
