# nikbulavin/cashsense architecture

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

- Interactive diagram: https://gitdiagram.com/nikbulavin/cashsense
- Repository: https://github.com/nikbulavin/cashsense

## Overview

##### Main Components
- Mobile Application Layer: Represented by the “mobile” module that contains the entry point (CsApplication, MainActivity) and UI integration.
- Feature Modules: Each distinct feature (e.g., Category, Home, Settings, Subscription, Transaction, Transfer, Wallet) is encapsulated as a separate module (found in the “feature” directory). Each feature module has its own UI screens, view models, dialogs, and navigation definitions.
- Core Modules:
- Core Domain: Contains business logic and use cases in “core/domain”.
- Core Data: Contains repository patterns, data models, and data sources (“core/data”).
- Core Database: Manages SQLite/Room schemas, DAO definitions, migration logic (“core/database”).
- Core Datastore and Proto: Manages local preferences and proto definitions (“core/datastore-proto”, “core/datastore”).
- Core Model: Defines the common data structures used across the app (“core/model”).
- Core Network: Handles API communication via Retrofit and network data sources (“core/network”).
- Core Notifications & Shortcuts: Manages notifications and Android shortcuts (“core/notifications”, “core/shortcuts”).
- Build and Configuration Modules: “build-logic” holds Gradle convention plugins that standardize build configurations across modules.
- Work Module: Contains background processing components such as workers and initializers (“work”).

##### Relationships and Data Flow
- The Mobile layer is the “shell” of the application that ties together feature modules through navigation (CsNavHost, TopLevelDestination) and provides the overall application context.
- Each Feature module interacts with core modules:
- They use core/domain use cases to trigger business logic.
- They communicate with core/data and core/database for local data persistence.
- They leverage core/network for remote API interaction.
- They integrate UI components defined in core/designsystem and core/ui.
- The Build and Configuration layer supports the entire project by providing standardized Gradle plugins and build conventions.
- Background services, such as those in the Work module, run tasks (e.g., deleting outdated rates) that may also trigger updates in the core layers.

##### Architectural Patterns and Design Principles
- A Modular (feature-based) architecture: Each functionality is split into its own module, which improves maintainability and reusability.
- Clean Architecture Principles:
- Presentation (UI in mobile and feature modules)
- Domain (business logic in core/domain)
- Data (repositories and data sources in core/data, core/database, core/network)
- Separation of Build Logic: The “build-logic” module centralizes Gradle conventions for consistency.
- Use of Dependency Injection (DI): Although not explicitly shown in every file, the presence of “di” (dependency injection) packages in network, datastore, database, etc., indicate that DI is a central design principle.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Mobile Layer
    subgraph "Mobile Layer"
        MA["Cash Sense - Mobile App"]:::mobileLayer
    end

    %% Feature Modules
    subgraph "Feature Modules"
        FC["Feature: Category"]:::featureLayer
        FH["Feature: Home"]:::featureLayer
        FS["Feature: Settings"]:::featureLayer
        FSub["Feature: Subscription"]:::featureLayer
        FT["Feature: Transaction"]:::featureLayer
        FTr["Feature: Transfer"]:::featureLayer
        FW["Feature: Wallet"]:::featureLayer
        Fagg["Features Aggregator"]:::featureLayer
    end

    %% Core Modules
    subgraph "Core Modules"
        CD["Core: Domain"]:::coreDomain
        CData["Core: Data"]:::coreData
        CDB["Core: Database"]:::corePersistence
        CDstore["Core: Datastore"]:::coreData
        CProto["Core: Proto"]:::coreData
        CM["Core: Model"]:::coreData
        CN["Core: Network"]:::coreData
        CDU["Core: Design System"]:::coreUI
        CU["Core: UI"]:::coreUI
        CNt["Core: Notifications"]:::coreUI
        CS["Core: Shortcuts"]:::coreUI
    end

    %% Build & Work Modules
    subgraph "Build & Work Modules"
        BL["Build Logic"]:::buildModule
        WM["Work Module"]:::workModule
    end

    %% Connections from Mobile to Feature Modules
    MA -->|"contains"| FC
    MA -->|"contains"| FH
    MA -->|"contains"| FS
    MA -->|"contains"| FSub
    MA -->|"contains"| FT
    MA -->|"contains"| FTr
    MA -->|"contains"| FW

    %% Connections from Feature Modules to Aggregator
    FC -->|"triggers"| Fagg
    FH -->|"triggers"| Fagg
    FS -->|"triggers"| Fagg
    FSub -->|"triggers"| Fagg
    FT -->|"triggers"| Fagg
    FTr -->|"triggers"| Fagg
    FW -->|"triggers"| Fagg

    %% Connections from Features Aggregator to Core Modules
    Fagg -->|"use"| CD
    Fagg -->|"access"| CData
    Fagg -->|"store"| CDB
    Fagg -->|"sync"| CDstore
    Fagg -->|"proto"| CProto
    Fagg -->|"model"| CM
    Fagg -->|"api"| CN
    Fagg -->|"theme"| CDU
    Fagg -->|"ui"| CU
    Fagg -->|"notify"| CNt
    Fagg -->|"shortcut"| CS

    %% Work Module dependency
    WM -->|"update"| CData

    %% Build Logic dependencies
    BL -->|"builds"| MA
    BL -->|"builds"| Fagg
    BL -->|"configures"| WM

    %% Click Events
    click MA "https://github.com/nikbulavin/cashsense/tree/main/mobile/src/main/kotlin/ru/resodostudios/cashsense"
    click FC "https://github.com/nikbulavin/cashsense/tree/main/feature/category"
    click FH "https://github.com/nikbulavin/cashsense/tree/main/feature/home"
    click FS "https://github.com/nikbulavin/cashsense/tree/main/feature/settings"
    click FSub "https://github.com/nikbulavin/cashsense/tree/main/feature/subscription"
    click FT "https://github.com/nikbulavin/cashsense/tree/main/feature/transaction"
    click FTr "https://github.com/nikbulavin/cashsense/tree/main/feature/transfer"
    click FW "https://github.com/nikbulavin/cashsense/tree/main/feature/wallet"
    click CD "https://github.com/nikbulavin/cashsense/tree/main/core/domain"
    click CData "https://github.com/nikbulavin/cashsense/tree/main/core/data"
    click CDB "https://github.com/nikbulavin/cashsense/tree/main/core/database"
    click CDstore "https://github.com/nikbulavin/cashsense/tree/main/core/datastore"
    click CProto "https://github.com/nikbulavin/cashsense/tree/main/core/datastore-proto"
    click CM "https://github.com/nikbulavin/cashsense/tree/main/core/model"
    click CN "https://github.com/nikbulavin/cashsense/tree/main/core/network"
    click CDU "https://github.com/nikbulavin/cashsense/tree/main/core/designsystem"
    click CU "https://github.com/nikbulavin/cashsense/tree/main/core/ui"
    click CNt "https://github.com/nikbulavin/cashsense/tree/main/core/notifications"
    click CS "https://github.com/nikbulavin/cashsense/tree/main/core/shortcuts"
    click BL "https://github.com/nikbulavin/cashsense/tree/main/build-logic"
    click WM "https://github.com/nikbulavin/cashsense/tree/main/work"

    %% Styles
    classDef mobileLayer fill:#a2d5f2,stroke:#333,stroke-width:2px;
    classDef featureLayer fill:#fef3bd,stroke:#333,stroke-width:2px;
    classDef coreDomain fill:#d5f5e3,stroke:#333,stroke-width:2px;
    classDef coreData fill:#f9e79f,stroke:#333,stroke-width:2px;
    classDef corePersistence fill:#fadbd8,stroke:#333,stroke-width:2px;
    classDef coreUI fill:#d6eaf8,stroke:#333,stroke-width:2px;
    classDef buildModule fill:#e8daef,stroke:#333,stroke-width:2px;
    classDef workModule fill:#f5b7b1,stroke:#333,stroke-width:2px;
```
