# trducchinh/coffeeapp architecture

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

- Interactive diagram: https://gitdiagram.com/trducchinh/coffeeapp
- Repository: https://github.com/trducchinh/coffeeapp

## Overview

##### Main Components
- User Interface Layer:
- Major screens and fragments (e.g., Sign In, Sign Up, Forgot Password, Home Screen, Detail Screen, Cart Screen, Payment Screen, Favourite Screen, Order History, Profile).
- ViewModel Layer:
- Viewmodels (e.g., HomeViewModel, CartViewModel, OrderHistoryViewModel, UserProfileViewModel, etc.) which act as a mediator between the UI and the data/model layer.
- Model/Data Layer:
- Domain objects such as Coffee, CoffeeBean, CartItem, OrderHistory, Address, and User. These are found under the “model” directory.
- Adapter Components:
- The adapters (e.g., CoffeeAdapter, AddressAdapter, CartAdapter, OrderAdapter, etc.) tie into Android’s RecyclerView to display dynamic lists.
- Utility & Service Integration:
- Utilities (under “utils”) handle tasks like payment operations, database interactions (saving to DB), conversions, and Firebase integration.
- External service components: Retrofit-based API services (e.g., GoongApiService) and Firebase configuration (including Firebase Authentication and Firebase Realtime Database integration).
- Android Infrastructure:
- The Android Manifest, resource files (layouts, anims, drawables), navigation graphs, and Gradle build configuration files are also components ensuring the app is bundled correctly and supports navigation, UI theming, and animations.

##### Relationships and Interactions
- The UI Layer (Activities/Fragments) interacts with the ViewModel layer through observers and data binding.
- The ViewModel layer communicates with the Model/Data layer and uses adapter classes for populating dynamic elements.
- The Model layer holds the data structures that are either loaded from or pushed to the Firebase backend and external services.
- Utility and API service classes (including functions in Retrofit and Firebase connectivity) support both the ViewModel and the Model layers.
- External services (Firebase, Goong Map) are connected to the app through the network module and provided API wrappers.

##### Architectural Patterns and Design Principles
- Presentation Layer (UI)
- Domain Logic Layer (ViewModels)
- Data Layer (Models, external API & database utilities)
- Mention the use of asynchronous programming using Kotlin Coroutines.
- Role of adapters in handling RecyclerViews lists and managing data interaction in the UI.
- Integration points for external services such as Firebase and Goong Map.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "UI Layer (Activities/Fragments)"
        A["Login: Sign In / Sign Up / Forgot Password"]:::ui
        B["Main App: Home, Details, Cart, Order History, Payment, Favourite"]:::ui
        C["Map Interactions"]:::ui
        D["Sidebar/Profile"]:::ui
    end

    %% ViewModel Layer
    subgraph "ViewModel Layer"
        E["HomeViewModel"]:::viewmodel
        F["CartViewModel"]:::viewmodel
        G["OrderHistoryViewModel"]:::viewmodel
        H["UserProfileViewModel"]:::viewmodel
    end

    %% Model / Data Layer
    subgraph "Model / Data Layer"
        I["Coffee"]:::model
        J["CoffeeBean"]:::model
        K["CartItem"]:::model
        L["OrderHistory"]:::model
        M["Address"]:::model
        N["User"]:::model
    end

    %% Adapter Components
    subgraph "Adapter Components"
        O["CoffeeAdapter"]:::adapter
        P["AddressAdapter"]:::adapter
        Q["CartAdapter"]:::adapter
        R["OrderAdapter"]:::adapter
        S["FavouriteAdapter"]:::adapter
        T["OrderDetailAdapter"]:::adapter
    end

    %% Utility & Service Integration
    subgraph "Utility & Service Integration"
        U["Firebase (Auth & Realtime DB)"]:::service
        V["Payment Utilities"]:::service
        W["SaveToDB & Convert"]:::service
        X["GoongApiService (Retrofit)"]:::service
    end

    %% Android Infrastructure
    subgraph "Android Infrastructure"
        Y["AndroidManifest.xml"]:::infrastructure
        Z["Resource Files (layouts, drawables, etc.)"]:::infrastructure
        AA["Gradle Build Configs"]:::infrastructure
    end

    %% UI Layer to ViewModel Layer
    A -->|"data-binding"| E
    B -->|"data-binding"| F
    C -->|"data-binding"| E
    D -->|"data-binding"| H

    %% ViewModel Layer to Model/Data Layer
    E -->|"fetch/update"| I
    F -->|"fetch/update"| K
    G -->|"fetch/update"| L
    H -->|"fetch/update"| N

    %% ViewModel Layer to Adapter Components
    E -->|"populates"| O
    F -->|"populates"| Q
    G -->|"populates"| R
    G -->|"populates"| T
    H -->|"populates"| P
    H -->|"populates"| S

    %% ViewModel calling Utility & Service Integration
    E -->|"calls"| U
    E -->|"calls"| X
    F -->|"calls"| U
    G -->|"calls"| X
    H -->|"calls"| U

    %% Model/Data Layer interaction with Utilities
    I -->|"saves/updates"| W

    %% Android Infrastructure supporting UI components
    Y -.->|"configures"| A
    Z -.->|"resources for"| B
    AA -.->|"builds"| A

    %% Styles
    classDef ui fill:#FDEBD0,stroke:#D35400,stroke-width:2px;
    classDef viewmodel fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
    classDef model fill:#D6EAF8,stroke:#2980B9,stroke-width:2px;
    classDef adapter fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef service fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
    classDef infrastructure fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;

    %% Click Events for UI Layer
    click A "https://github.com/trducchinh/coffeeapp/tree/master/app/src/main/java/com/proptit/btl_oop/ui/login"
    click B "https://github.com/trducchinh/coffeeapp/tree/master/app/src/main/java/com/proptit/btl_oop/ui/main_app"
    click C "https://github.com/trducchinh/coffeeapp/tree/master/app/src/main/java/com/proptit/btl_oop/ui/map"
    click D "https://github.com/trducchinh/coffeeapp/tree/master/app/src/main/java/com/proptit/btl_oop/ui/sidebar/profile"

    %% Click Events for ViewModel Layer
    click E "https://github.com/trducchinh/coffeeapp/blob/master/app/src/main/java/com/proptit/btl_oop/viewmodel/HomeViewModel.kt"
    click F "https://github.com/trducchinh/coffeeapp/blob/master/app/src/main/java/com/proptit/btl_oop/viewmodel/CartViewModel.kt"
    click G "https://github.com/trducchinh/coffeeapp/blob/master/app/src/main/java/com/proptit/btl_oop/viewmodel/OrderHistoryViewModel.kt"
    click H "https://github.com/trducchinh/coffeeapp/blob/master/app/src/main/java/com/proptit/btl_oop/viewmodel/UserProfileViewModel.kt"

    %% Click Events for Model/Data Layer
    click I "https://github.com/trducchinh/coffeeapp/blob/master/app/src/main/java/com/proptit/btl_oop/model/Coffee.kt"
    click J "https://github.com/trducchinh/coffeeapp/blob/master/app/src/main/java/com/proptit/btl_oop/model/CoffeeBean.kt"
    click K "https://github.com/trducchinh/coffeeapp/blob/master/app/src/main/java/com/proptit/btl_oop/model/CartItem.kt"
    click L "https://github.com/trducchinh/coffeeapp/blob/master/app/src/main/java/com/proptit/btl_oop/model/OrderHistory.kt"
    click M "https://github.com/trducchinh/coffeeapp/blob/master/app/src/main/java/com/proptit/btl_oop/model/Address.kt"
    click N "https://github.com/trducchinh/coffeeapp/blob/master/app/src/main/java/com/proptit/btl_oop/model/User.kt"

    %% Click Events for Adapter Components
    click O "https://github.com/trducchinh/coffeeapp/blob/master/app/src/main/java/com/proptit/btl_oop/adapter/CoffeeAdapter.kt"
    click P "https://github.com/trducchinh/coffeeapp/blob/master/app/src/main/java/com/proptit/btl_oop/adapter/AddressAdapter.kt"
    click Q "https://github.com/trducchinh/coffeeapp/blob/master/app/src/main/java/com/proptit/btl_oop/adapter/CartAdapter.kt"
    click R "https://github.com/trducchinh/coffeeapp/blob/master/app/src/main/java/com/proptit/btl_oop/adapter/OrderAdapter.kt"
    click S "https://github.com/trducchinh/coffeeapp/blob/master/app/src/main/java/com/proptit/btl_oop/adapter/FavouriteAdapter.kt"
    click T "https://github.com/trducchinh/coffeeapp/blob/master/app/src/main/java/com/proptit/btl_oop/adapter/OrderDetailAdapter.kt"

    %% Click Events for Utility & Service Integration
    click U "https://github.com/trducchinh/coffeeapp/blob/master/app/src/main/java/com/proptit/btl_oop/utils/Firebase.kt"
    click V "https://github.com/trducchinh/coffeeapp/blob/master/app/src/main/java/com/proptit/btl_oop/utils/Payment.kt"
    click W "https://github.com/trducchinh/coffeeapp/blob/master/app/src/main/java/com/proptit/btl_oop/utils/SaveToDB.kt"
    click X "https://github.com/trducchinh/coffeeapp/blob/master/app/src/main/java/com/proptit/btl_oop/response/GoongApiService.kt"

    %% Click Events for Android Infrastructure
    click Y "https://github.com/trducchinh/coffeeapp/blob/master/app/src/main/AndroidManifest.xml"
    click Z "https://github.com/trducchinh/coffeeapp/tree/master/app/src/main/res"
    click AA "https://github.com/trducchinh/coffeeapp/blob/master/app/build.gradle.kts"
```
