# h4xor7/shri architecture

> Architecture diagram of the GitHub repository h4xor7/shri, 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/h4xor7/shri
- Repository: https://github.com/h4xor7/shri

## Overview

##### Project Type and Purpose
- This is an Android mobile application built primarily in Kotlin. Its purpose is to help users manage and track expenses, featuring a home screen displaying a pie chart for expense summaries, an entry screen for adding expenses, and a list screen for reviewing and filtering past entries.
- The README emphasizes features, the use of Android Architecture Components, Room for database persistence, coroutines/Flow for asynchronous handling, and a navigation component, which point to an MVVM (Model-View-ViewModel) architecture.

##### File Structure
- Top-Level: The project uses standard Android project directories with an /app folder that contains the main Android source sets and resources.
- Source Code Layering: Within app/src/main/java/com/pandey/shri, you have clear sub-packages:
- data – including local database configuration with Room (db, dao, models, converters) and repositories.
- ui – containing activities, fragments, adapters, and viewmodels.
- utils – housing helper classes and constants.
- Testing Directories: Both unit tests and Android instrumentation tests are present.
- Resource Files: There are XML layouts, drawable assets, navigation graph (nav_graph.xml), and various UI resource files that define the visual aspects.

a. Main Components:
- UI Layer: Activity (MainActivity) and Fragments (HomeFragment, DetailFragment, NewEntryFragment). These elements constitute the user interface and are tied together using Android Jetpack Navigation.
- ViewModel Layer: Classes like HomeViewModel, DetailDateViewModel, and NewEntryViewModel which manage UI-related data and handle data-binding.
- Repository Layer: The ExpenseDetailRepository in the data/repository package which acts as an abstraction over data operations.
- Data Layer: Room Database components including ExpenseRoomDatabase, ExpenseDao, Converters, and model classes (CategoryModel, Entry, Expensehelp, PieModel) that represent domain entities.
- Utility Components: Various helper utilities (e.g., HomePrefrences, Constant, Utils) performing ancillary functions.

b. Relationships and Interactions:
- UI components (Fragments/Activity) interact with ViewModels to receive data updates and trigger user actions.
- ViewModels call on the Repository layer to fetch, process, or update data.
- The Repository communicates with the Room database (using ExpenseDao) to perform CRUD operations, with model objects representing the data.
- The Navigation component ties the various UI screens together, orchestrating the flow based on user interactions.
- Asynchronous operations are managed using Coroutines and Flow which could be highlighted to show data streaming and lifecycle awareness.

c. Architectural Patterns & Design Principles:
- MVVM Pattern: Clearly depicted by separating views (UI), ViewModels, and the data/repository layers.
- Clean Architecture Basis: While not strictly multi-layered, components are organized to separate concerns (UI, data handling, business logic).
- Use of Android Architecture Components: ViewModel for state management, Room for persistence, and Navigation for routing.
- Asynchronous Data Handling: Flow and Coroutines are critical for non-blocking data operations.

d. Relevant Technologies & Frameworks:
- Kotlin as the programming language.
- Android Architecture Components (ViewModel, Navigation, Room).
- Kotlin Coroutines and Flow for managing asynchronous operations.
- Android Gradle build system (with build.gradle scripts) for project configuration.
- Testing frameworks (unit and instrumentation tests) for quality assurance.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "UI Layer"
        MainActivity["MainActivity (Activity)"]:::ui
        HomeFragment["HomeFragment"]:::ui
        DetailFragment["DetailFragment"]:::ui
        NewEntryFragment["NewEntryFragment"]:::ui
        NavComponent["Navigation (Jetpack)"]:::note
    end

    %% ViewModel Layer
    subgraph "ViewModel Layer"
        HomeVM["HomeViewModel"]:::vm
        DetailDateVM["DetailDateViewModel"]:::vm
        NewEntryVM["NewEntryViewModel"]:::vm
        DetailFactory["DetailViewmodelFactory"]:::vm
    end

    %% Repository Layer
    subgraph "Repository Layer"
        ExpenseRepo["ExpenseDetailRepository"]:::repo
    end

    %% Data Layer
    subgraph "Data Layer"
        DB["ExpenseRoomDatabase"]:::db
        Converters["Converters"]:::db
        ExpenseDao["ExpenseDao"]:::dao
        subgraph "Models"
            CategoryModel["CategoryModel"]:::model
            Entry["Entry"]:::model
            Expensehelp["Expensehelp"]:::model
            PieModel["PieModel"]:::model
        end
    end

    %% Utility Components
    subgraph "Utility Components"
        Constant["Constant"]:::util
        HomePreferences["HomePrefrences"]:::util
        Utils["Utils"]:::util
    end

    %% Relationships: UI -> ViewModel
    MainActivity -->|"triggers"| HomeVM
    HomeFragment -->|"updates"| HomeVM
    DetailFragment -->|"requests"| DetailDateVM
    NewEntryFragment -->|"submits"| NewEntryVM
    MainActivity -->|"navigates"| NavComponent
    NavComponent -->|"routes to"| HomeFragment
    HomeFragment -->|"routes to"| DetailFragment
    HomeFragment -->|"routes to"| NewEntryFragment

    %% Relationships: ViewModel -> Repository
    HomeVM -->|"fetches"| ExpenseRepo
    DetailDateVM -->|"fetches"| ExpenseRepo
    NewEntryVM -->|"adds"| ExpenseRepo
    DetailFactory -->|"creates"| HomeVM

    %% Relationships: Repository -> Data Layer
    ExpenseRepo -->|"performsCRUD"| ExpenseDao
    ExpenseRepo -->|"uses"| DB
    ExpenseDao -->|"manages"| CategoryModel
    ExpenseDao -->|"manages"| Entry
    ExpenseDao -->|"manages"| Expensehelp
    ExpenseDao -->|"manages"| PieModel
    DB -->|"includes"| Converters

    %% Asynchronous Operations using Coroutines/Flow (dashed arrows)
    HomeVM -.->|"FlowCoroutines"| ExpenseRepo
    DetailDateVM -.->|"FlowCoroutines"| ExpenseRepo
    NewEntryVM -.->|"FlowCoroutines"| ExpenseRepo

    %% Utility interactions (used by ViewModels)
    HomeVM -->|"reads"| Constant
    HomeVM -->|"accesses"| HomePreferences
    HomeVM -->|"utilizes"| Utils

    %% Click Events for Component Mapping
    click MainActivity "https://github.com/h4xor7/shri/tree/master/app/src/main/java/com/pandey/shri/ui/main/view"
    click HomeFragment "https://github.com/h4xor7/shri/tree/master/app/src/main/java/com/pandey/shri/ui/main/view"
    click DetailFragment "https://github.com/h4xor7/shri/tree/master/app/src/main/java/com/pandey/shri/ui/main/view"
    click NewEntryFragment "https://github.com/h4xor7/shri/tree/master/app/src/main/java/com/pandey/shri/ui/main/view"
    
    click HomeVM "https://github.com/h4xor7/shri/tree/master/app/src/main/java/com/pandey/shri/ui/main/viewmodel"
    click DetailDateVM "https://github.com/h4xor7/shri/tree/master/app/src/main/java/com/pandey/shri/ui/main/viewmodel"
    click NewEntryVM "https://github.com/h4xor7/shri/tree/master/app/src/main/java/com/pandey/shri/ui/main/viewmodel"
    click DetailFactory "https://github.com/h4xor7/shri/tree/master/app/src/main/java/com/pandey/shri/ui/main/viewmodel"
    
    click ExpenseRepo "https://github.com/h4xor7/shri/blob/master/app/src/main/java/com/pandey/shri/data/repository/ExpenseDetailRepository.kt"
    
    click DB "https://github.com/h4xor7/shri/tree/master/app/src/main/java/com/pandey/shri/data/local/db"
    click Converters "https://github.com/h4xor7/shri/tree/master/app/src/main/java/com/pandey/shri/data/local/db"
    click ExpenseDao "https://github.com/h4xor7/shri/blob/master/app/src/main/java/com/pandey/shri/data/local/db/dao/ExpenseDao.kt"
    
    click CategoryModel "https://github.com/h4xor7/shri/tree/master/app/src/main/java/com/pandey/shri/data/model"
    click Entry "https://github.com/h4xor7/shri/tree/master/app/src/main/java/com/pandey/shri/data/model"
    click Expensehelp "https://github.com/h4xor7/shri/tree/master/app/src/main/java/com/pandey/shri/data/model"
    click PieModel "https://github.com/h4xor7/shri/tree/master/app/src/main/java/com/pandey/shri/data/model"
    
    click Constant "https://github.com/h4xor7/shri/tree/master/app/src/main/java/com/pandey/shri/utils"
    click HomePreferences "https://github.com/h4xor7/shri/tree/master/app/src/main/java/com/pandey/shri/utils"
    click Utils "https://github.com/h4xor7/shri/tree/master/app/src/main/java/com/pandey/shri/utils"

    %% Styles
    classDef ui fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef vm fill:#87CEEB,stroke:#333,stroke-width:2px;
    classDef repo fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef db fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef dao fill:#FFA07A,stroke:#333,stroke-width:2px;
    classDef model fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef util fill:#FFDEAD,stroke:#333,stroke-width:2px;
    classDef note fill:#D3D3D3,stroke:#808080,stroke-dasharray:5, 5,stroke-width:2px;
```
