# okemwag/moneywise architecture

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

- Interactive diagram: https://gitdiagram.com/okemwag/moneywise
- Repository: https://github.com/okemwag/moneywise

## Overview

##### Main Components

A. Application Layers (Use distinct vertical sections):
- Presentation Layer (Top)
- Domain Layer (Middle)
- Data Layer (Bottom)

B. Key Components in Each Layer:
1. Presentation Layer:
- Activities & Fragments (BudgetFragment, SavingsFragment)
- ViewModels (Budgeting ViewModel)
- UI Components (Jetpack Compose elements)
- Theme & Resources

2. Domain Layer:
- Use Cases (AddBudgetUseCase, GetSavingsUseCase, etc.)
- Domain Models (Budget, Savings)
- Repository Interfaces (BudgetRepository, SavingsRepository)

3. Data Layer:
- Repository Implementations
- Local Data Sources (Room Database)
- Remote Data Sources (API Services)
- Data Models (Entities)

##### Component Relationships

- Data flow between layers (always flowing inward toward domain layer)
- Dependencies between components
- Use case interactions
- Repository pattern implementation

##### Detailed Component Breakdown

A. UI Layer:
**[MainActivity] → [BudgetFragment, SavingsFragment]**
- ↓
**[ViewModels (Budgeting)]**
- ↓
**[UI State Management]**

B. Domain Layer:
**[Use Cases]**
- ↓
**[Domain Models]**
- ↓
**[Repository Interfaces]**

C. Data Layer:
**[Repository Implementations]**
- ↙           ↘
**[Local DB]    [Remote API]**
**(Room)        (Retrofit)**

##### Additional Elements

- Dependency Injection flow (Hilt)
- Database schema for Room
- API endpoints for remote services
- Asynchronous operations (Coroutines/Flow)

##### Notes for Implementation

- Use clear, readable fonts
- Version information
- Notes about key architectural decisions
- Error handling flow
- Threading boundaries

##### View state management through ViewModels

Remember to maintain a balance between detail and clarity, focusing on the architectural decisions that make this app unique, such as the separation of budget and savings features while sharing common architectural patterns.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef presentation fill:#e1f5fe,stroke:#01579b
    classDef domain fill:#e8f5e9,stroke:#1b5e20
    classDef data fill:#fff3e0,stroke:#e65100
    classDef database fill:#f5f5f5,stroke:#212121
    classDef api fill:#fce4ec,stroke:#880e4f

    %% Presentation Layer
    subgraph PresentationLayer["Presentation Layer"]
        MainActivity["MainActivity"]
        BudgetFragment["Budget Fragment"]
        SavingsFragment["Savings Fragment"]
        BudgetingViewModel["Budgeting ViewModel"]
        UIState["UI State Management"]
        ThemeComponents["Theme Components"]
    end

    %% Domain Layer
    subgraph DomainLayer["Domain Layer"]
        subgraph UseCases["Use Cases"]
            AddBudgetUC["Add Budget Use Case"]
            GetBudgetUC["Get Budget Use Case"]
            AddSavingsUC["Add Savings Use Case"]
            GetSavingsUC["Get Savings Use Case"]
        end

        subgraph DomainModels["Domain Models"]
            BudgetModel["Budget Model"]
            SavingsModel["Savings Model"]
        end

        subgraph Repositories["Repository Interfaces"]
            BudgetRepo["Budget Repository"]
            SavingsRepo["Savings Repository"]
        end
    end

    %% Data Layer
    subgraph DataLayer["Data Layer"]
        subgraph RepoImpl["Repository Implementations"]
            BudgetRepoImpl["Budget Repository Impl"]
            SavingsRepoImpl["Savings Repository Impl"]
        end

        subgraph LocalData["Local Data Sources"]
            BudgetDB["Budget Database"]
            BudgetDao["Budget DAO"]
            SavingsDao["Savings DAO"]
        end

        subgraph RemoteData["Remote Data Sources"]
            BudgetAPI["Budget API Service"]
            SavingsAPI["Savings API Service"]
        end

        subgraph DataModels["Data Models"]
            BudgetEntity["Budget Entity"]
            SavingsEntity["Savings Entity"]
        end
    end

    %% Relationships
    MainActivity --> BudgetFragment
    MainActivity --> SavingsFragment
    BudgetFragment --> BudgetingViewModel
    SavingsFragment --> BudgetingViewModel
    BudgetingViewModel --> UIState
    
    BudgetingViewModel --> AddBudgetUC
    BudgetingViewModel --> GetBudgetUC
    BudgetingViewModel --> AddSavingsUC
    BudgetingViewModel --> GetSavingsUC

    AddBudgetUC --> BudgetRepo
    GetBudgetUC --> BudgetRepo
    AddSavingsUC --> SavingsRepo
    GetSavingsUC --> SavingsRepo

    BudgetRepo --> BudgetModel
    SavingsRepo --> SavingsModel

    BudgetRepoImpl --> BudgetRepo
    SavingsRepoImpl --> SavingsRepo

    BudgetRepoImpl --> BudgetDB
    BudgetRepoImpl --> BudgetAPI
    SavingsRepoImpl --> BudgetDB
    SavingsRepoImpl --> SavingsAPI

    BudgetDB --> BudgetDao
    BudgetDB --> SavingsDao

    %% Styling
    class MainActivity,BudgetFragment,SavingsFragment,BudgetingViewModel,UIState,ThemeComponents presentation
    class AddBudgetUC,GetBudgetUC,AddSavingsUC,GetSavingsUC,BudgetModel,SavingsModel,BudgetRepo,SavingsRepo domain
    class BudgetRepoImpl,SavingsRepoImpl,BudgetDB,BudgetDao,SavingsDao,BudgetAPI,SavingsAPI,BudgetEntity,SavingsEntity data

    %% Click Events
    click MainActivity "https://github.com/Okemwag/MoneyWise/blob/main/app/src/main/java/com/okemwag/moneywise/presentation/ui/activities/MainActivity.kt"
    click BudgetFragment "https://github.com/Okemwag/MoneyWise/blob/main/app/src/main/java/com/okemwag/moneywise/presentation/ui/fragments/BudgetFragment.kt"
    click SavingsFragment "https://github.com/Okemwag/MoneyWise/blob/main/app/src/main/java/com/okemwag/moneywise/presentation/ui/fragments/SavingsFragment.kt"
    click BudgetingViewModel "https://github.com/Okemwag/MoneyWise/blob/main/app/src/main/java/com/okemwag/moneywise/presentation/viewmodels/Budgeting.kt"
    click ThemeComponents "https://github.com/Okemwag/MoneyWise/tree/main/app/src/main/java/com/okemwag/moneywise/presentation/theme"
    click BudgetModel "https://github.com/Okemwag/MoneyWise/blob/main/app/src/main/java/com/okemwag/moneywise/domain/models/Budget.kt"
    click SavingsModel "https://github.com/Okemwag/MoneyWise/blob/main/app/src/main/java/com/okemwag/moneywise/domain/models/Savings.kt"
    click BudgetRepo "https://github.com/Okemwag/MoneyWise/blob/main/app/src/main/java/com/okemwag/moneywise/domain/repository/BudgetRepository.kt"
    click SavingsRepo "https://github.com/Okemwag/MoneyWise/blob/main/app/src/main/java/com/okemwag/moneywise/domain/repository/SavingsRepository.kt"
    click AddBudgetUC "https://github.com/Okemwag/MoneyWise/blob/main/app/src/main/java/com/okemwag/moneywise/domain/usecases/AddBudgetUseCase.kt"
    click AddSavingsUC "https://github.com/Okemwag/MoneyWise/blob/main/app/src/main/java/com/okemwag/moneywise/domain/usecases/AddSavingsUseCase.kt"
    click GetBudgetUC "https://github.com/Okemwag/MoneyWise/blob/main/app/src/main/java/com/okemwag/moneywise/domain/usecases/GetBudgetUseCase.kt"
    click GetSavingsUC "https://github.com/Okemwag/MoneyWise/blob/main/app/src/main/java/com/okemwag/moneywise/domain/usecases/GetSavingsUseCase.kt"
    click BudgetRepoImpl "https://github.com/Okemwag/MoneyWise/blob/main/app/src/main/java/com/okemwag/moneywise/data/repository/BudgetRepositoryImpl.kt"
    click SavingsRepoImpl "https://github.com/Okemwag/MoneyWise/blob/main/app/src/main/java/com/okemwag/moneywise/data/repository/SavingsRepositoryImpl.kt"
    click BudgetDB "https://github.com/Okemwag/MoneyWise/blob/main/app/src/main/java/com/okemwag/moneywise/data/datasource/local/BudgetDatabase.kt"
    click BudgetDao "https://github.com/Okemwag/MoneyWise/blob/main/app/src/main/java/com/okemwag/moneywise/data/datasource/local/BudgetDao.kt"
    click SavingsDao "https://github.com/Okemwag/MoneyWise/blob/main/app/src/main/java/com/okemwag/moneywise/data/datasource/local/SavingsDao.kt"
    click BudgetAPI "https://github.com/Okemwag/MoneyWise/blob/main/app/src/main/java/com/okemwag/moneywise/data/datasource/remote/BudgetApiService.kt"
    click SavingsAPI "https://github.com/Okemwag/MoneyWise/blob/main/app/src/main/java/com/okemwag/moneywise/data/datasource/remote/SavingsApiService.kt"
    click BudgetEntity "https://github.com/Okemwag/MoneyWise/blob/main/app/src/main/java/com/okemwag/moneywise/data/models/BudgetEntity.kt"
    click SavingsEntity "https://github.com/Okemwag/MoneyWise/blob/main/app/src/main/java/com/okemwag/moneywise/data/models/SavingsEntity.kt"
```
