# amirghari/task-beat architecture

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

- Interactive diagram: https://gitdiagram.com/amirghari/task-beat
- Repository: https://github.com/amirghari/task-beat

## Overview

##### Main System Components
- UI Layer: This includes all screens and Compose UI components as found in the “ui” package (e.g., screens such as HomeScreen, ChatScreen, HeartRateScreen, etc.) and the theme components.
- ViewModel Layer: Represented by various viewmodels (e.g., ChatViewModel, HeartRateViewModel, SignInViewModel, and home-related viewmodels) that manage the state and business logic for the UI.
- Data/Repository Layer: Illustrated by repositories in “data” (e.g., DataRepository, OfflineDataRepository) alongside the dependency injection management (AppContainer) that connects UI/viewmodels with data sources.
- Data Storage: Two main parts:
- Local Storage (Room Database) – encapsulating the Room database, DAOs (HealthDao, UserDao), and type converters.
- Remote Storage – using Firebase Firestore and Firebase Authentication for user data syncing and security.
- Network Layer: Includes network call logic such as the Retrofit creation for remote API interactions (e.g., ModelDownloadApi) and any external integrations.
- AI Module: Highlight the use of the Gemini Gemma-2-2B model for health recommendations and task suggestions, which may be coupled with data from both local and remote sources.
- Additional Components: Workers (e.g., FetchAndUpdateDBWorker) to handle background processes and any integration with Firebase Cloud Messaging for notifications.

##### Relationships and Data Flow
- UI components (screens) interacting with their corresponding ViewModels.
- ViewModels retrieving or updating data via the Repository.
- The Repository coordinating communication with both the local Room database and Firebase/remote services.
- The network layer connecting the Repository with external APIs (like for downloading models or AI data).
- The background worker interacting with both the Repository and local storage to keep data in sync.
- AI integration feeding recommendations back into the Repository and ViewModel, influencing UI presentation.

##### Architectural Patterns
- Repository Pattern: Emphasize how data management is abstracted away from the UI, providing a single unified interface over local database and remote APIs.
- Dependency Injection: Indicate how components like AppContainer are used to inject dependencies into various modules.

##### Relevant Technologies and Frameworks
- Use labels for each component such as “Jetpack Compose UI”, “Android ViewModel with LiveData”, “Room Database”, “Firebase Authentication/Firestore”, “Retrofit for API calls”, and “Gemini Gemma-2-2B (AI Integration)”.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        UI["Jetpack Compose UI (Screens)"]:::ui
        LoginUI["Login/Signup Screen"]:::ui
        ChatUI["Chat Screen"]:::ui
        HomeUI["Home Screen"]:::ui
        HealthUI["Heart Rate Screen"]:::ui
    end

    %% ViewModel Layer
    subgraph "ViewModel Layer"
        ChatVM["ChatViewModel"]:::viewmodel
        HeartRateVM["HeartRateViewModel"]:::viewmodel
        SignInVM["SignInViewModel"]:::viewmodel
        HomeVM["HomeViewModel"]:::viewmodel
    end

    %% Data / Repository Layer
    subgraph "Data/Repository Layer"
        Repo["DataRepository & OfflineDataRepository"]:::repo
        DI["AppContainer (Dependency Injection)"]:::repo
    end

    %% Local Storage (Room Database)
    subgraph "Local Storage (Room Database)"
        DB["Room Database"]:::database
        HealthDao["HealthDao"]:::dao
        UserDao["UserDao"]:::dao
        Converters["Converters"]:::dao
    end

    %% Remote Storage (Firebase)
    subgraph "Remote Storage (Firebase)"
        FirebaseAuth["Firebase Authentication/Firestore"]:::external
        FirebaseConfig["Firebase configuration"]:::file
    end

    %% Network Layer
    subgraph "Network Layer"
        Retrofit["Retrofit API Client"]:::network
        ModelDownloadApi["ModelDownloadApi"]:::network
    end

    %% AI Module
    subgraph "AI Module"
        AIModel["Gemini Gemma-2-2B (AI Integration)"]:::ai
        GeminiUi["GemmaUiState"]:::ui
    end

    %% Background Workers
    subgraph "Background Workers"
        Worker["FetchAndUpdateDBWorker"]:::worker
        CustomWorker["CustomWorkerFactory"]:::worker
    end

    %% Connections between layers
    UI -->|"bindsTo"| ChatVM
    UI -->|"bindsTo"| HeartRateVM
    UI -->|"bindsTo"| SignInVM
    UI -->|"bindsTo"| HomeVM

    ChatVM -->|"interactsWith"| Repo
    HeartRateVM -->|"interactsWith"| Repo
    SignInVM -->|"interactsWith"| Repo
    HomeVM -->|"interactsWith"| Repo

    Repo -->|"accesses"| DB
    Repo -->|"accesses"| FirebaseAuth
    Repo -->|"calls"| Retrofit
    Repo -->|"integratesWith"| AIModel

    DB -->|"uses"| HealthDao
    DB -->|"uses"| UserDao
    DB -->|"uses"| Converters

    Retrofit -->|"supports"| ModelDownloadApi

    Worker -->|"syncs"| Repo
    Worker -->|"updates"| DB

    FirebaseAuth -->|"configuredBy"| FirebaseConfig

    DI -->|"injectsInto"| ChatVM
    DI -->|"injectsInto"| HeartRateVM
    DI -->|"injectsInto"| SignInVM
    DI -->|"injectsInto"| HomeVM
    DI -->|"configures"| Repo

    GeminiUi -->|"updatesFrom"| AIModel
    AIModel -->|"feedsTo"| Repo

    %% Styles (colors)
    classDef ui fill:#f9c,stroke:#333,stroke-width:2px;
    classDef viewmodel fill:#bbf,stroke:#333,stroke-width:2px;
    classDef repo fill:#dfd,stroke:#333,stroke-width:2px;
    classDef database fill:#fdd,stroke:#333,stroke-width:2px;
    classDef dao fill:#fdd,stroke:#333,stroke-width:2px;
    classDef external fill:#fb9,stroke:#333,stroke-width:2px;
    classDef network fill:#cff,stroke:#333,stroke-width:2px;
    classDef ai fill:#fcf,stroke:#333,stroke-width:2px;
    classDef worker fill:#ffd,stroke:#333,stroke-width:2px;
    classDef file fill:#eee,stroke:#333,stroke-width:2px;

    %% Click Events
    click UI "https://github.com/amirghari/task-beat/tree/main/app/src/main/java/com/example/taskbeat/ui"
    click ChatVM "https://github.com/amirghari/task-beat/tree/main/app/src/main/java/com/example/taskbeat/ui/viewmodels"
    click Repo "https://github.com/amirghari/task-beat/tree/main/app/src/main/java/com/example/taskbeat/data"
    click DB "https://github.com/amirghari/task-beat/tree/main/app/src/main/java/com/example/taskbeat/database"
    click HealthDao "https://github.com/amirghari/task-beat/tree/main/app/src/main/java/com/example/taskbeat/data"
    click FirebaseConfig "https://github.com/amirghari/task-beat/blob/main/app/google-services.json"
    click Retrofit "https://github.com/amirghari/task-beat/tree/main/app/src/main/java/com/example/taskbeat/network"
    click AIModel "https://github.com/amirghari/task-beat/blob/main/app/src/main/java/com/example/taskbeat/data/Gemma22BModel.kt"
    click GeminiUi "https://github.com/amirghari/task-beat/blob/main/app/src/main/java/com/example/taskbeat/ui/components/chat/GemmaUiState.kt"
    click Worker "https://github.com/amirghari/task-beat/tree/main/app/src/main/java/com/example/taskbeat/workers"
    click CustomWorker "https://github.com/amirghari/task-beat/tree/main/app/src/main/java/com/example/taskbeat/workers"
```
