# mhmmdvg/cashier-app architecture

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

- Interactive diagram: https://gitdiagram.com/mhmmdvg/cashier-app
- Repository: https://github.com/mhmmdvg/cashier-app

## Overview

##### Project Type & Purpose
- This is an Android mobile application (written in Kotlin) implementing a cashier system: user authentication, product browsing, order placement, and checkout.

##### High-Level Architecture
- The project follows a layered “Clean Architecture” + MVVM pattern, with these layers:
- UI Layer (Jetpack Compose screens & components)
- Presentation Layer (ViewModels)
- Domain Layer (plain model classes)
- Data Layer (remote APIs, repositories, token/local storage)
- DI Layer (provides and wires dependencies)
- External Services (external REST API)

##### Main Components
- UI Layer
- Composable Components: AsyncImage, CardItem, Search, etc.
- Screens: LoginScreen, HomeScreen, OrderScreen, OrderSuccess, SettingScreen
- Presentation Layer
- LoginViewModel, ProductViewModel
- Domain Layer
- Models: Auth, Product, NavigationItem, Select, etc.
- Data Layer
- Remote API Interfaces: AuthApi, ProductApi (Retrofit)
- Repositories: AuthRepository, ProductRepository
- Local Helpers: TokenManager (stores JWT, e.g., in SharedPreferences)
- Networking: OkHttpClient with AuthInterceptor
- Resource Wrapper: Resource<T> (to standardize success/error/loading)
- DI Layer
- AppModule (provides Retrofit, OkHttpClient, repositories, viewmodels)
- External Services
- REST endpoints for auth and product operations

##### Relationships & Data Flow
1. User interacts with a Composable UI component.
2. UI dispatches events to ViewModel (e.g., LoginViewModel.login(credentials)).
3. ViewModel calls its Repository (AuthRepository.login()).
4. Repository uses Retrofit’s AuthApi to perform HTTP request.
5. OkHttpClient (injected via AppModule) invokes AuthInterceptor, attaching JWT from TokenManager.
6. Retrofit returns API response wrapped in Resource<T>.
7. Repository returns Resource<T> to ViewModel.
8. ViewModel updates its StateFlow/LiveData.
9. UI observes state changes and recomposes.

##### Architectural Patterns & Technologies
- MVVM: clear separation UI <-> ViewModel <-> Model
- Clean Layers: UI, Presentation, Domain, Data, External
- Dependency Injection: Dagger/Hilt (AppModule)
- Networking: Retrofit + OkHttp + AuthInterceptor
- Coroutine-based async calls
- Jetpack Compose for declarative UI

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% UI Layer
    subgraph "UI Layer" 
        direction TB
        AsyncImage["AsyncImage"]:::ui
        CardItem["CardItem"]:::ui
        Search["Search"]:::ui
        LoginScreen["LoginScreen"]:::ui
        HomeScreen["HomeScreen"]:::ui
        ProductEvent["ProductEvent"]:::ui
        OrderScreen["OrderScreen"]:::ui
        OrderSuccess["OrderSuccess"]:::ui
        SettingScreen["SettingScreen"]:::ui
    end

    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        LoginViewModel["LoginViewModel"]:::presentation
        ProductViewModel["ProductViewModel"]:::presentation
    end

    %% Domain Layer
    subgraph "Domain Layer"
        direction TB
        Auth["Auth"]:::domain
        Product["Product"]:::domain
        NavigationItem["NavigationItem"]:::domain
        Select["Select"]:::domain
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        AuthApi["AuthApi (Retrofit)"]:::data
        ProductApi["ProductApi (Retrofit)"]:::data
        AuthRepository["AuthRepository"]:::data
        ProductRepository["ProductRepository"]:::data
        TokenManager["TokenManager"]:::data
        AuthInterceptor["AuthInterceptor"]:::data
        Resource["Resource<T>"]:::data
        OkHttpClient["OkHttpClient"]:::data
        Retrofit["Retrofit"]:::data
    end

    %% DI Layer
    subgraph "DI Layer"
        direction TB
        AppModule["AppModule"]:::di
    end

    %% External Services
    subgraph "External Services"
        direction TB
        RESTAPI["Remote REST API"]:::external
    end

    %% Application Entry
    subgraph "Application Entry"
        direction TB
        CashierApp["CashierApp"]:::infra
        MainActivity["MainActivity"]:::infra
    end

    %% Data Flow
    LoginScreen -->|"dispatches to"| LoginViewModel
    HomeScreen -->|"dispatches to"| ProductViewModel
    LoginViewModel -->|"calls login()"| AuthRepository
    ProductViewModel -->|"calls fetchProducts()"| ProductRepository
    AuthRepository -->|"uses"| AuthApi
    ProductRepository -->|"uses"| ProductApi
    AuthApi -->|"HTTP request"| RESTAPI
    ProductApi -->|"HTTP request"| RESTAPI
    RESTAPI -->|"response"| AuthApi
    RESTAPI -->|"response"| ProductApi
    AuthApi -->|"wraps in Resource"| AuthRepository
    ProductApi -->|"wraps in Resource"| ProductRepository
    AuthRepository -->|"returns Resource"| LoginViewModel
    ProductRepository -->|"returns Resource"| ProductViewModel
    LoginViewModel -->|"updates StateFlow"| LoginScreen
    ProductViewModel -->|"updates StateFlow"| HomeScreen

    %% Networking pipeline
    TokenManager -->|"provides JWT"| AuthInterceptor
    AuthInterceptor -->|"intercepts"| OkHttpClient
    OkHttpClient -->|"used by"| Retrofit
    Retrofit -->|"creates"| AuthApi
    Retrofit -->|"creates"| ProductApi

    %% DI wiring
    AppModule -->|provides| Retrofit
    AppModule -->|provides| OkHttpClient
    AppModule -->|provides| AuthRepository
    AppModule -->|provides| ProductRepository
    AppModule -->|provides| LoginViewModel
    AppModule -->|provides| ProductViewModel
    AppModule -->|provides| TokenManager

    CashierApp --> MainActivity
    MainActivity --> LoginScreen
    MainActivity --> HomeScreen
    MainActivity --> OrderScreen
    MainActivity --> OrderSuccess
    MainActivity --> SettingScreen

    %% Click Events
    click AsyncImage "https://github.com/mhmmdvg/cashier-app/blob/main/app/src/main/java/cashierapp/presentations/ui/components/AsyncImage.kt"
    click CardItem "https://github.com/mhmmdvg/cashier-app/blob/main/app/src/main/java/cashierapp/presentations/ui/components/CardItem.kt"
    click Search "https://github.com/mhmmdvg/cashier-app/blob/main/app/src/main/java/cashierapp/presentations/ui/components/Search.kt"
    click LoginScreen "https://github.com/mhmmdvg/cashier-app/blob/main/app/src/main/java/cashierapp/presentations/ui/screens/screens/auth/LoginScreen.kt"
    click HomeScreen "https://github.com/mhmmdvg/cashier-app/blob/main/app/src/main/java/cashierapp/presentations/ui/screens/screens/home/HomeScreen.kt"
    click ProductEvent "https://github.com/mhmmdvg/cashier-app/blob/main/app/src/main/java/cashierapp/presentations/ui/screens/screens/home/ProductEvent.kt"
    click OrderScreen "https://github.com/mhmmdvg/cashier-app/blob/main/app/src/main/java/cashierapp/presentations/ui/screens/screens/order/OrderScreen.kt"
    click OrderSuccess "https://github.com/mhmmdvg/cashier-app/blob/main/app/src/main/java/cashierapp/presentations/ui/screens/screens/orderSuccess/OrderSuccess.kt"
    click SettingScreen "https://github.com/mhmmdvg/cashier-app/blob/main/app/src/main/java/cashierapp/presentations/ui/screens/screens/settings/SettingScreen.kt"
    click LoginViewModel "https://github.com/mhmmdvg/cashier-app/blob/main/app/src/main/java/cashierapp/presentations/viewmodel/viewmodel/auth/LoginViewModel.kt"
    click ProductViewModel "https://github.com/mhmmdvg/cashier-app/blob/main/app/src/main/java/cashierapp/presentations/viewmodel/viewmodel/home/ProductViewModel.kt"
    click Auth "https://github.com/mhmmdvg/cashier-app/blob/main/app/src/main/java/cashierapp/domain/model/Auth.kt"
    click Product "https://github.com/mhmmdvg/cashier-app/blob/main/app/src/main/java/cashierapp/domain/model/Product.kt"
    click NavigationItem "https://github.com/mhmmdvg/cashier-app/blob/main/app/src/main/java/cashierapp/domain/model/NavigationItem.kt"
    click Select "https://github.com/mhmmdvg/cashier-app/blob/main/app/src/main/java/cashierapp/domain/model/Select.kt"
    click AuthApi "https://github.com/mhmmdvg/cashier-app/blob/main/app/src/main/java/cashierapp/data/remote/api/AuthApi.kt"
    click ProductApi "https://github.com/mhmmdvg/cashier-app/blob/main/app/src/main/java/cashierapp/data/remote/api/ProductApi.kt"
    click AuthRepository "https://github.com/mhmmdvg/cashier-app/blob/main/app/src/main/java/cashierapp/data/remote/repository/AuthRepository.kt"
    click ProductRepository "https://github.com/mhmmdvg/cashier-app/blob/main/app/src/main/java/cashierapp/data/remote/repository/ProductRepository.kt"
    click TokenManager "https://github.com/mhmmdvg/cashier-app/blob/main/app/src/main/java/cashierapp/data/remote/local/TokenManager.kt"
    click Resource "https://github.com/mhmmdvg/cashier-app/blob/main/app/src/main/java/cashierapp/data/resources/Resource.kt"
    click AuthInterceptor "https://github.com/mhmmdvg/cashier-app/blob/main/app/src/main/java/cashierapp/utils/AuthInterceptor.kt"
    click AppModule "https://github.com/mhmmdvg/cashier-app/blob/main/app/src/main/java/cashierapp/di/AppModule.kt"
    click CashierApp "https://github.com/mhmmdvg/cashier-app/blob/main/app/src/main/java/cashierapp/CashierApp.kt"
    click MainActivity "https://github.com/mhmmdvg/cashier-app/blob/main/app/src/main/java/cashierapp/MainActivity.kt"

    %% Styles
    classDef ui fill:#a2d2ff,stroke:#1e3a8a,color:#000
    classDef presentation fill:#bde0fe,stroke:#0077b6,color:#000
    classDef domain fill:#c8e6c9,stroke:#2e7d32,color:#000
    classDef data fill:#ffeb99,stroke:#f9a825,color:#000
    classDef di fill:#ffe0b2,stroke:#ef6c00,color:#000
    classDef external fill:#eeeeee,stroke:#616161,color:#000
    classDef infra fill:#d1c4e9,stroke:#512da8,color:#000
```
