# yung729/spendsavvy architecture

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

- Interactive diagram: https://gitdiagram.com/yung729/spendsavvy
- Repository: https://github.com/yung729/spendsavvy

## Overview

##### Project Identification
- Project Type & Purpose: SpendSavvy is an Android application aimed at managing and tracking spending and saving habits. The minimal README and the file tree illustrate a mobile app with multiple screens for tasks like adding bills, managing cash accounts, budgeting, and tracking transactions.
- Main Frameworks/Technologies: Kotlin for Android development, Android components (Activities, Fragments, ViewModels), Firebase integration (evidenced by the presence of google-services.json and FireAuth/Firestore repositories), and native Android UI resources.

##### Key Components
a. Presentation Layer:
- Screens/UI: Highlight the numerous screens under the “screen” directory (e.g., LoginScreen, OverviewScreen, WalletScreen, SettingsScreen). These represent the views where users interact.
b. Business Logic Layer:
- ViewModels: Under “viewModels”, there are various view model classes (e.g., BillsViewModel, CategoryViewModel, MainViewModel) that manage UI-related data, following MVVM principles.
c. Data & Domain Layer:
- Models: Located in “models”, these define the data structures (e.g., Bills, Cash, Category, Stock) used throughout the app.
- Repositories: The “repo” directory shows FirestoreRepository and FireAuthRepository for data access and remote operations (likely interacting with Firebase) as well as local persistence, in addition to “data” for category-related data.
d. Database/Storage:
- Local Database: The “db” directory includes DatabaseHelper for managing local data storage.
- Firebase Services: The existence of google-services.json and repository components indicate remote data handling (authentication and Firestore operations).
e. Navigation & Application Infrastructure:
- Navigation: The “navigation” package (containing NavGraph, NetworkHelper, Screen definitions, and ConnectionStatus) is in charge of routing and managing network connectivity cues across various screens.
- Component-based Design: The “components” folder houses AppComponent.kt, which suggests the implementation of dependency injection or similar component management (possibly via Dagger/Hilt).
f. Testing Infrastructure:
- Unit and Instrumentation Tests: The presence of “androidTest” and “test” directories indicates well-organized testing setups.

##### Relationships and Interactions
- User Action Flow: Start at the Presentation Layer (screens/UI), which interacts with the corresponding ViewModels.
- Data Flow: Each ViewModel communicates with the Repository layer to either fetch data from the local Database (via DatabaseHelper) or remote data from Firebase (via FireAuthRepository and FirestoreRepository).
- Navigation & Component Interaction: The Navigation module connects UI screens, while the AppComponent likely facilitates dependency injection by wiring up view models, repositories, and other services.
- Testing: Separate flows for instrumented tests (UI interaction on devices) and unit tests (logic verification).

##### Architectural Patterns & Design Principles
- MVVM Architecture: The clear isolation of UI (screens) from business logic (ViewModels) and data (Models and Repositories) is a classic MVVM approach.
- Repository Pattern: Data access is segregated via repositories that abstract away the details of local vs. remote data.
- Dependency Injection: The presence of an AppComponent hints at using DI to decouple component creation and dependency management.
- Modularity: By separating screens, navigation, data, database, and network components into distinct packages, the design promotes maintainability and scalability.

- Top Layer: Presentation (screens & UI themes).
- Middle Layer: Business logic (ViewModels, navigation).
- Lower Layer: Data (Repositories, Models) and Storage (Local Database; External Services like Firebase).
- Integration highlights such as:
- Testing components (unit tests & instrumentation tests) as separate supportive modules.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        UI_Screens["Screens/UI"]:::presentation
        UI_Themes["UI Themes & Components"]:::presentation
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        VM["ViewModels"]:::business
    end

    %% Data & Domain Layer
    subgraph "Data & Domain Layer"
        Models["Models"]:::data
        CategoryRepo["Category Data Repository"]:::repo
    end

    %% Database & Storage
    subgraph "Database & Storage"
        LocalDB["Local Database"]:::db
        GoogleServices["google-services.json"]:::firebase
        FireAuthRepo["FireAuth Repository"]:::firebase
        FirestoreRepo["Firestore Repository"]:::firebase
    end

    %% Navigation & Infrastructure
    subgraph "Navigation & Infrastructure"
        Navigation["Navigation"]:::navigation
        DI["Dependency Injection (AppComponent)"]:::di
    end

    %% Testing
    subgraph "Testing Infrastructure"
        AndroidTest["AndroidTest"]:::testing
        UnitTest["UnitTest"]:::testing
    end

    %% Connections between layers
    UI_Screens -->|"triggers"| VM
    UI_Screens -->|"routesVia"| Navigation
    UI_Themes -->|"styles"| UI_Screens

    VM -->|"fetchesData"| CategoryRepo

    CategoryRepo -->|"localAccess"| LocalDB
    CategoryRepo -->|"remoteAuth"| FireAuthRepo
    CategoryRepo -->|"remoteStore"| FirestoreRepo
    CategoryRepo -->|"definesTypes"| Models

    DI -->|"injectsDepsTo"| VM
    DI -->|"injectsDepsTo"| CategoryRepo
    Navigation -->|"navigates"| UI_Screens

    %% Class Definitions for colors
    classDef presentation fill:#FFDDC1,stroke:#D5835A,stroke-width:2px;
    classDef business fill:#C1FFD7,stroke:#5AD583,stroke-width:2px;
    classDef data fill:#C1D4FF,stroke:#5A73D5,stroke-width:2px;
    classDef repo fill:#E4C1FF,stroke:#A85AD5,stroke-width:2px;
    classDef db fill:#FFF5BA,stroke:#D5A85A,stroke-width:2px;
    classDef firebase fill:#FFB3C1,stroke:#D55A73,stroke-width:2px;
    classDef navigation fill:#C1FFFF,stroke:#5AD5D5,stroke-width:2px;
    classDef di fill:#FFD1DC,stroke:#D55A8A,stroke-width:2px;
    classDef testing fill:#E0E0E0,stroke:#A0A0A0,stroke-width:2px;

    %% Click Events
    click UI_Screens "https://github.com/yung729/spendsavvy/tree/master/app/src/main/java/com/example/spendsavvy/screen"
    click UI_Themes "https://github.com/yung729/spendsavvy/tree/master/app/src/main/java/com/example/spendsavvy/ui/theme"
    click VM "https://github.com/yung729/spendsavvy/tree/master/app/src/main/java/com/example/spendsavvy/viewModels"
    click Models "https://github.com/yung729/spendsavvy/tree/master/app/src/main/java/com/example/spendsavvy/models"
    click CategoryRepo "https://github.com/yung729/spendsavvy/tree/master/app/src/main/java/com/example/spendsavvy/data"
    click LocalDB "https://github.com/yung729/spendsavvy/blob/master/app/src/main/java/com/example/spendsavvy/db/DatabaseHelper.kt"
    click GoogleServices "https://github.com/yung729/spendsavvy/blob/master/app/google-services.json"
    click FireAuthRepo "https://github.com/yung729/spendsavvy/blob/master/app/src/main/java/com/example/spendsavvy/repo/FireAuthRepository.kt"
    click FirestoreRepo "https://github.com/yung729/spendsavvy/blob/master/app/src/main/java/com/example/spendsavvy/repo/FirestoreRepository.kt"
    click Navigation "https://github.com/yung729/spendsavvy/tree/master/app/src/main/java/com/example/spendsavvy/navigation"
    click DI "https://github.com/yung729/spendsavvy/blob/master/app/src/main/java/com/example/spendsavvy/components/AppComponent.kt"
    click AndroidTest "https://github.com/yung729/spendsavvy/tree/master/app/src/androidTest"
    click UnitTest "https://github.com/yung729/spendsavvy/tree/master/app/src/test"
```
