# poksyy/copay-app-frontend architecture

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

- Interactive diagram: https://gitdiagram.com/poksyy/copay-app-frontend
- Repository: https://github.com/poksyy/copay-app-frontend

## Overview

##### Project Type and Purpose
- This is an Android mobile application built with Kotlin and Jetpack Compose that serves as the frontend for a collaborative expense management solution.
- The application supports user authentication, expense splitting, group management, collaborative gifts, and price comparisons, with server-side logic handled by a separate backend repository.

##### Key Architectural Components
- UI / Presentation Layer:
- Components: Activities and Compose-based screens (e.g., SplashScreen, HubScreen, various Auth screens like LoginScreen, RegisterStepOneScreen, etc.).
- Reusable UI components (BottomNavigationBar, Buttons, InputField) and theme configurations.
- Navigation:
- Represented by components such as CopayNavHost and NavRoutes, which drive screen transitions.
- ViewModel / Business Logic Layer:
- Contains view models like AuthViewModel, ForgotPasswordViewModel, and SplashViewModel.
- Accompanied by factories (AuthViewModelFactory, ForgotPasswordViewModelFactory) to manage lifecycle-related aspects.
- Repository/Data Layer:
- Encapsulated in UserRepository and PasswordRepository, which abstract data access and business logic.
- Service / API Interaction Layer:
- Components like AuthService, ApiService, and RetrofitInstance manage network communications.
- DTOs (request and response classes) like UserLoginRequestDTO, ForgotPasswordDTO, JwtResponse, etc., facilitate data transfer between the mobile app and the backend.
- Utility/Support Components:
- Utility classes such as DataStoreManager and ConnectionManager help manage device storage and network connectivity.
- Additional classes for validation (UserValidation) and state management (e.g., AuthState) round out the architecture.

##### Relationships and Data Flow
- User Interaction: The end user interacts with the UI components.
- UI to ViewModel: The UI layers send user events to appropriate view models.
- ViewModel to Repository: View models mediate between the UI and repository layers, enforcing business logic.
- Repository to Service: Repositories call service methods to interact with remote APIs via Retrofit.
- External Backend: Represents the server-side component (mentioned in the README) that processes requests and manages user data.
- Utility Services: Global components (like DataStoreManager) assist across layers (e.g., managing token persistence or network state).

##### Architectural Patterns & Technologies
- The application follows an MVVM (Model-View-ViewModel) architecture.
- The repository pattern abstracts data sources and encapsulates business logic.
- Retrofit is used for network communication.
- The navigation is handled using the Jetpack Compose navigation component.
- Kotlin and Jetpack Compose are the core development technologies.

## Diagram (Mermaid)

```mermaid
flowchart TD
    U["User"]:::external

    subgraph "UI / Presentation"
        MA["MainActivity"]:::ui
        SS["SplashScreen"]:::ui
        HS["HubScreen"]:::ui
        AS["Auth Screens"]:::ui
        UIComp["Reusable UI Components"]:::ui
        Theme["Theme Configurations"]:::ui
    end

    subgraph "Navigation"
        CNH["CopayNavHost"]:::nav
        NR["Navigation Routes"]:::nav
    end

    subgraph "ViewModel / Business Logic"
        AuthVM["AuthViewModel"]:::viewModel
        FPVM["ForgotPasswordViewModel"]:::viewModel
        SplashVM["SplashViewModel"]:::viewModel
        AuthVMF["AuthViewModelFactory"]:::viewModel
        FPVMF["ForgotPasswordViewModelFactory"]:::viewModel
    end

    subgraph "Repository / Data"
        UR["UserRepository"]:::repo
        PR["PasswordRepository"]:::repo
    end

    subgraph "Service / API"
        ASrv["ApiService"]:::service
        RI["RetrofitInstance"]:::service
        AUTHSrv["AuthService"]:::service
        subgraph "DTOs"
            ReqDTO["Request DTOs"]:::service
            ResDTO["Response DTOs"]:::service
        end
        RH["ResponseHandler"]:::service
    end

    subgraph "Utilities"
        DSM["DataStoreManager"]:::utils
        CM["ConnectionManager"]:::utils
        AST["AuthState"]:::utils
        UV["UserValidation"]:::utils
    end

    EB["External Backend"]:::external

    %% User interacts with UI components
    U -->|"interacts"| MA
    U -->|"interacts"| SS
    U -->|"interacts"| HS
    U -->|"interacts"| AS

    %% UI --> Navigation (for screen transitions)
    MA -->|"navigatesTo"| CNH
    AS -->|"navigatesVia"| CNH
    HS -->|"navigatesVia"| NR

    %% UI sends events to ViewModel layer
    MA -->|"triggers"| AuthVM
    SS -->|"triggers"| SplashVM
    AS -->|"triggers"| FPVM

    %% ViewModel uses Factories (for lifecycle management)
    AuthVM --- AuthVMF
    FPVM --- FPVMF

    %% ViewModel calls Repository methods
    AuthVM -->|"calls"| UR
    FPVM -->|"calls"| PR

    %% Repository interacts with Service/API
    UR -->|"fetchesFrom"| ASrv
    PR -->|"fetchesFrom"| ASrv

    %% Service layer uses Retrofit and communicates with external backend
    ASrv -->|"uses"| RI
    RI -->|"communicatesWith"| EB
    AUTHSrv -->|"communicatesVia"| RI
    RH -->|"handles"| ASrv

    %% Service layer also uses DTOs for data transfer
    ASrv --- ReqDTO
    ASrv --- ResDTO

    %% Utilities support various layers
    DSM ---|"supports"| AuthVM
    CM ---|"supports"| RI
    AST ---|"managesStateFor"| FPVM
    UV ---|"validates"| AS

    %% Styling classes
    classDef ui fill:#c7f0db,stroke:#0b3d91,stroke-width:2px;
    classDef nav fill:#e1d9f0,stroke:#6a0dad,stroke-width:2px;
    classDef viewModel fill:#d0e6f6,stroke:#1a73e8,stroke-width:2px;
    classDef repo fill:#fff3cd,stroke:#ffbf00,stroke-width:2px;
    classDef service fill:#f8d7da,stroke:#c82333,stroke-width:2px;
    classDef utils fill:#e2e3e5,stroke:#555,stroke-width:2px;
    classDef external fill:#ffebcd,stroke:#8b4513,stroke-width:2px;

    %% Click Events - UI / Presentation Layer
    click MA "https://github.com/poksyy/copay-app-frontend/blob/master/app/src/main/java/com/copay/app/MainActivity.kt"
    click SS "https://github.com/poksyy/copay-app-frontend/blob/master/app/src/main/java/com/copay/app/ui/screen/SplashScreen.kt"
    click HS "https://github.com/poksyy/copay-app-frontend/blob/master/app/src/main/java/com/copay/app/ui/screen/HubScreen.kt"
    click AS "https://github.com/poksyy/copay-app-frontend/tree/master/app/src/main/java/com/copay/app/ui/screen/auth/"
    click UIComp "https://github.com/poksyy/copay-app-frontend/tree/master/app/src/main/java/com/copay/app/ui/components/"
    click Theme "https://github.com/poksyy/copay-app-frontend/tree/master/app/src/main/java/com/copay/app/ui/theme/"

    %% Click Events - Navigation
    click CNH "https://github.com/poksyy/copay-app-frontend/blob/master/app/src/main/java/com/copay/app/navigation/CopayNavHost.kt"
    click NR "https://github.com/poksyy/copay-app-frontend/blob/master/app/src/main/java/com/copay/app/navigation/NavRoutes.kt"

    %% Click Events - ViewModel / Business Logic
    click AuthVM "https://github.com/poksyy/copay-app-frontend/blob/master/app/src/main/java/com/copay/app/viewmodel/AuthViewModel.kt"
    click FPVM "https://github.com/poksyy/copay-app-frontend/blob/master/app/src/main/java/com/copay/app/viewmodel/ForgotPasswordViewModel.kt"
    click SplashVM "https://github.com/poksyy/copay-app-frontend/blob/master/app/src/main/java/com/copay/app/viewmodel/SplashViewModel.kt"
    click AuthVMF "https://github.com/poksyy/copay-app-frontend/blob/master/app/src/main/java/com/copay/app/factory/AuthViewModelFactory.kt"
    click FPVMF "https://github.com/poksyy/copay-app-frontend/blob/master/app/src/main/java/com/copay/app/factory/ForgotPasswordViewModelFactory.kt"

    %% Click Events - Repository / Data
    click UR "https://github.com/poksyy/copay-app-frontend/blob/master/app/src/main/java/com/copay/app/repository/UserRepository.kt"
    click PR "https://github.com/poksyy/copay-app-frontend/blob/master/app/src/main/java/com/copay/app/repository/PasswordRepository.kt"

    %% Click Events - Service / API
    click ASrv "https://github.com/poksyy/copay-app-frontend/blob/master/app/src/main/java/com/copay/app/config/ApiService.kt"
    click RI "https://github.com/poksyy/copay-app-frontend/blob/master/app/src/main/java/com/copay/app/config/RetrofitInstance.kt"
    click AUTHSrv "https://github.com/poksyy/copay-app-frontend/blob/master/app/src/main/java/com/copay/app/service/AuthService.kt"
    click ReqDTO "https://github.com/poksyy/copay-app-frontend/tree/master/app/src/main/java/com/copay/app/dto/request/"
    click ResDTO "https://github.com/poksyy/copay-app-frontend/blob/master/app/src/main/java/com/copay/app/dto/response/JwtResponse.kt"
    click RH "https://github.com/poksyy/copay-app-frontend/blob/master/app/src/main/java/com/copay/app/service/ResponseHandler.kt"

    %% Click Events - Utilities
    click DSM "https://github.com/poksyy/copay-app-frontend/blob/master/app/src/main/java/com/copay/app/utils/DataStoreManager.kt"
    click CM "https://github.com/poksyy/copay-app-frontend/blob/master/app/src/main/java/com/copay/app/utils/ConnectionManager.kt"
    click AST "https://github.com/poksyy/copay-app-frontend/blob/master/app/src/main/java/com/copay/app/utils/state/AuthState.kt"
    click UV "https://github.com/poksyy/copay-app-frontend/blob/master/app/src/main/java/com/copay/app/validation/UserValidation.kt"
```
