# skiletcool/myunit_java architecture

> Architecture diagram of the GitHub repository skiletcool/myunit_java, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/skiletcool/myunit_java
- Repository: https://github.com/skiletcool/myunit_java

## Overview

1. **What this repo is**
   - A single Android application called **MyUnit**, built in **Java**.
   - It is a personal organizer that combines **auth**, **notes**, **finance tracking**, **health logging**, and an **AI chat assistant** in one app.

2. **Top-level app shape**
   - The app is centered around **`MainActivity`** as the host.
   - Most user-facing behavior is split into feature fragments under `ui/*`, with navigation resources in `res/navigation`.
   - This is a classic **fragment + ViewModel** Android app rather than a multi-module backend/frontend system.

3. **Presentation layer**
   - Each feature has its own UI package:
     - `ui/auth` for login/register
     - `ui/notes` for note list/detail
     - `ui/finance` for income/expense tracking
     - `ui/health` for health/activity logs
     - `ui/ai` for the Gemini chat assistant
     - `ui/home` and `ui/settings` for app shell and preferences
   - The UI layer is driven by **Fragments**, **Adapters** for lists, and **ViewModels** for state and actions.

4. **Navigation and screen composition**
   - `nav_graph.xml` and `nav_graph_home.xml` define the screen flow.
   - `activity_main.xml` and the fragment layouts indicate that the app uses a **single-activity, multi-fragment** structure.
   - Bottom navigation and feature menus suggest the app is organized around switching between major modules rather than deep nested screens.

5. **Feature boundaries**
   - The repo is cleanly split into independent business areas:
     - **Auth**: user login/registration and session handling
     - **Notes**: CRUD-style note management plus note detail
     - **Finance**: transactions, balances, analytics-style views
     - **Health**: health log entry and viewing
     - **AI**: chat interface plus AI context integration
   - These features appear to share common persistence patterns but remain separate at the UI and repository levels.

6. **Local data layer**
   - Persistent app data is stored locally with **Room** on top of SQLite.
   - The database layer is anchored by `AppDatabase`, with DAOs for:
     - `UserDao`
     - `NoteDao`
     - `FinanceRecordDao`
     - `HealthRecordDao`
     - `ChatMessageDao`
   - Entities mirror those domains: `User`, `Note`, `FinanceRecord`, `HealthRecord`, and `ChatMessage`.

7. **Repository layer**
   - Each domain has a repository under `data/repository`:
     - `UserRepository`
     - `NoteRepository`
     - `FinanceRepository`
     - `HealthRepository`
     - `ChatRepository`
   - Repositories are the main boundary between UI/ViewModels and data sources.
   - They likely mediate between Room storage and, for AI, remote network calls plus context assembly.

8. **Remote AI integration**
   - The only visible remote integration is the Gemini assistant stack in `data/remote`:
     - `GeminiApiService`
     - `GeminiRequest`
     - `GeminiResponse`
     - `RetrofitClient`
   - This indicates the app calls **Gemini via Retrofit** rather than through a generic backend API.
   - The AI feature therefore has a direct outbound network dependency from the app to Google’s generative service.

9. **AI context flow**
   - `AIContextManager` is a key architectural piece because it bridges user-owned local data and AI prompts.
   - The README says the assistant uses context from notes and goals to personalize responses.
   - Architecturally, this means the AI flow is not just chat history; it likely aggregates local data from repositories into prompt context before sending the request.

10. **State and concurrency**
   - The README calls out **ExecutorService** and **ListenableFutures**, which suggests asynchronous work is off the main thread for database and network operations.
   - ViewModels likely expose UI state while repositories perform background I/O.
   - This keeps the app responsive during Room access and Gemini calls.

11. **Authentication and session handling**
   - Auth is localized in the app, with `LoginFragment`, `RegisterFragment`, `AuthViewModel`, and `UserViewModel`.
   - `SessionManager` indicates the app maintains login/session state locally.
   - The README mentions **BCrypt** password hashing, so credentials are not stored in plain text; the secure user record is part of the local persistence model.

12. **Cross-cutting utilities and locale support**
   - `LocaleHelper` suggests app-wide language or locale switching.
   - `values-uk` resources show Ukrainian localization support.
   - These are supporting, cross-cutting concerns rather than standalone business modules.

13. **Infrastructure and boundaries to show in a diagram**
   - The key boundary is between:
     - **UI/ViewModel layer** in `ui/*`
     - **Repository layer** in `data/repository`
     - **Local persistence** in Room (`AppDatabase`, DAOs, entities)
     - **Remote AI service** in `data/remote`
   - There is no obvious separate backend service in the repo; the app is primarily **client-side with local storage plus external Gemini API calls**.

14. **Overall architecture summary**
   - MyUnit is a **single Android client app** with a modular feature layout.
   - It uses **MVVM** with **Room-backed repositories** for local data and a **Gemini-powered AI subsystem** that can incorporate local context.
   - The architecture is optimized for an offline-first personal organizer, with cloud usage limited to AI generation rather than general app storage or authentication services.

Main entry points: [`app/src/main/java/com/example/myunit/data/repository`](https://github.com/skiletcool/myunit_java/tree/master/app/src/main/java/com/example/myunit/data/repository) (Repositories), [`app/src/main/res/navigation/nav_graph.xml`](https://github.com/skiletcool/myunit_java/blob/master/app/src/main/res/navigation/nav_graph.xml) (Nav graph), [`app/src/main/java/com/example/myunit/MainActivity.java`](https://github.com/skiletcool/myunit_java/blob/master/app/src/main/java/com/example/myunit/MainActivity.java) (MainActivity), [`app/src/main/java/com/example/myunit/ui/ai/AIViewModel.java`](https://github.com/skiletcool/myunit_java/blob/master/app/src/main/java/com/example/myunit/ui/ai/AIViewModel.java) (AI VM)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_ui["UI layer"]
  node_main_activity["MainActivity<br/>activity host<br/>[MainActivity.java]"]
  node_home_fragment["Home<br/>fragment<br/>[HomeFragment.java]"]
  node_auth_feature["Auth<br/>feature ui"]
  node_notes_feature["Notes<br/>feature ui"]
  node_finance_feature["Finance<br/>feature ui"]
  node_health_feature["Health<br/>feature ui"]
  node_ai_feature["AI chat<br/>feature ui"]
  node_settings_fragment["Settings<br/>fragment"]
  node_auth_vm["Auth VM<br/>viewmodel<br/>[AuthViewModel.java]"]
  node_notes_vm["Notes VM<br/>viewmodel<br/>[NoteViewModel.java]"]
  node_finance_vm["Finance VM<br/>viewmodel"]
  node_health_vm["Health VM<br/>viewmodel"]
  node_ai_vm["AI VM<br/>viewmodel<br/>[AIViewModel.java]"]
end

subgraph group_group_data["Data layer"]
  node_repositories["Repositories<br/>domain boundary"]
  node_app_database[("AppDatabase<br/>room database<br/>[AppDatabase.java]")]
  node_gemini_api["Gemini API<br/>remote service"]
  node_ai_context["AI context<br/>prompt builder"]
end

subgraph group_group_utils["Cross-cutting"]
  node_session_manager["Session manager<br/>session helper"]
  node_locale_helper["Locale helper<br/>[LocaleHelper.java]"]
end

subgraph group_group_nav["Navigation"]
  node_nav_graph["Nav graph<br/>navigation<br/>[nav_graph.xml]"]
  node_nav_graph_home["Home graph<br/>navigation<br/>[nav_graph_home.xml]"]
end

node_main_activity -->|"hosts"| node_nav_graph
node_main_activity -->|"embeds"| node_nav_graph_home
node_nav_graph -->|"routes to"| node_auth_feature
node_nav_graph -->|"routes to"| node_notes_feature
node_nav_graph -->|"routes to"| node_finance_feature
node_nav_graph -->|"routes to"| node_health_feature
node_nav_graph -->|"routes to"| node_ai_feature
node_nav_graph -->|"routes to"| node_settings_fragment
node_nav_graph_home -->|"contains"| node_home_fragment
node_auth_feature -->|"uses"| node_auth_vm
node_notes_feature -->|"uses"| node_notes_vm
node_finance_feature -->|"uses"| node_finance_vm
node_health_feature -->|"uses"| node_health_vm
node_ai_feature -->|"uses"| node_ai_vm
node_auth_vm -->|"calls"| node_repositories
node_notes_vm -->|"calls"| node_repositories
node_finance_vm -->|"calls"| node_repositories
node_health_vm -->|"calls"| node_repositories
node_ai_vm -->|"builds with"| node_ai_context
node_ai_vm -->|"calls"| node_repositories
node_repositories -->|"reads/writes"| node_app_database
node_repositories -->|"calls"| node_gemini_api
node_repositories -->|"uses"| node_session_manager
node_main_activity -->|"applies"| node_locale_helper

click node_main_activity "https://github.com/skiletcool/myunit_java/blob/master/app/src/main/java/com/example/myunit/MainActivity.java"
click node_nav_graph "https://github.com/skiletcool/myunit_java/blob/master/app/src/main/res/navigation/nav_graph.xml"
click node_nav_graph_home "https://github.com/skiletcool/myunit_java/blob/master/app/src/main/res/navigation/nav_graph_home.xml"
click node_home_fragment "https://github.com/skiletcool/myunit_java/blob/master/app/src/main/java/com/example/myunit/ui/home/HomeFragment.java"
click node_auth_feature "https://github.com/skiletcool/myunit_java/tree/master/app/src/main/java/com/example/myunit/ui/auth"
click node_notes_feature "https://github.com/skiletcool/myunit_java/tree/master/app/src/main/java/com/example/myunit/ui/notes"
click node_finance_feature "https://github.com/skiletcool/myunit_java/tree/master/app/src/main/java/com/example/myunit/ui/finance"
click node_health_feature "https://github.com/skiletcool/myunit_java/tree/master/app/src/main/java/com/example/myunit/ui/health"
click node_ai_feature "https://github.com/skiletcool/myunit_java/tree/master/app/src/main/java/com/example/myunit/ui/ai"
click node_settings_fragment "https://github.com/skiletcool/myunit_java/blob/master/app/src/main/java/com/example/myunit/ui/settings/SettingsFragment.java"
click node_auth_vm "https://github.com/skiletcool/myunit_java/blob/master/app/src/main/java/com/example/myunit/ui/auth/AuthViewModel.java"
click node_notes_vm "https://github.com/skiletcool/myunit_java/blob/master/app/src/main/java/com/example/myunit/ui/notes/NoteViewModel.java"
click node_finance_vm "https://github.com/skiletcool/myunit_java/blob/master/app/src/main/java/com/example/myunit/ui/finance/FinanceViewModel.java"
click node_health_vm "https://github.com/skiletcool/myunit_java/blob/master/app/src/main/java/com/example/myunit/ui/health/HealthViewModel.java"
click node_ai_vm "https://github.com/skiletcool/myunit_java/blob/master/app/src/main/java/com/example/myunit/ui/ai/AIViewModel.java"
click node_repositories "https://github.com/skiletcool/myunit_java/tree/master/app/src/main/java/com/example/myunit/data/repository"
click node_app_database "https://github.com/skiletcool/myunit_java/blob/master/app/src/main/java/com/example/myunit/data/local/AppDatabase.java"
click node_gemini_api "https://github.com/skiletcool/myunit_java/blob/master/app/src/main/java/com/example/myunit/data/remote/GeminiApiService.java"
click node_ai_context "https://github.com/skiletcool/myunit_java/blob/master/app/src/main/java/com/example/myunit/data/repository/AIContextManager.java"
click node_session_manager "https://github.com/skiletcool/myunit_java/blob/master/app/src/main/java/com/example/myunit/utils/SessionManager.java"
click node_locale_helper "https://github.com/skiletcool/myunit_java/blob/master/app/src/main/java/com/example/myunit/utils/LocaleHelper.java"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main_activity,node_home_fragment,node_auth_feature,node_notes_feature,node_finance_feature,node_health_feature,node_ai_feature,node_settings_fragment,node_auth_vm,node_notes_vm,node_finance_vm,node_health_vm,node_ai_vm toneBlue
class node_repositories,node_app_database,node_gemini_api,node_ai_context toneAmber
class node_session_manager,node_locale_helper toneMint
class node_nav_graph,node_nav_graph_home toneRose
```

## Components

### UI layer

Single-activity, multi-fragment presentation layer.

- [MainActivity](https://github.com/skiletcool/myunit_java/blob/master/app/src/main/java/com/example/myunit/MainActivity.java): activity host · Single activity that hosts the app shell and fragment navigation. · `app/src/main/java/com/example/myunit/MainActivity.java`
- [Home](https://github.com/skiletcool/myunit_java/blob/master/app/src/main/java/com/example/myunit/ui/home/HomeFragment.java): fragment · Main landing shell for the organizer app. · `app/src/main/java/com/example/myunit/ui/home/HomeFragment.java`
- [Auth](https://github.com/skiletcool/myunit_java/tree/master/app/src/main/java/com/example/myunit/ui/auth): feature ui · Login and registration screens plus auth state handling. · `app/src/main/java/com/example/myunit/ui/auth`
- [Notes](https://github.com/skiletcool/myunit_java/tree/master/app/src/main/java/com/example/myunit/ui/notes): feature ui · Note browsing, editing, and detail screens. · `app/src/main/java/com/example/myunit/ui/notes`
- [Finance](https://github.com/skiletcool/myunit_java/tree/master/app/src/main/java/com/example/myunit/ui/finance): feature ui · Income, expense, and transaction tracking screens. · `app/src/main/java/com/example/myunit/ui/finance`
- [Health](https://github.com/skiletcool/myunit_java/tree/master/app/src/main/java/com/example/myunit/ui/health): feature ui · Health and activity logging screens. · `app/src/main/java/com/example/myunit/ui/health`
- [AI chat](https://github.com/skiletcool/myunit_java/tree/master/app/src/main/java/com/example/myunit/ui/ai): feature ui · Gemini chat assistant and message list UI. · `app/src/main/java/com/example/myunit/ui/ai`
- [Settings](https://github.com/skiletcool/myunit_java/blob/master/app/src/main/java/com/example/myunit/ui/settings/SettingsFragment.java): fragment · App preferences and configuration screen. · `app/src/main/java/com/example/myunit/ui/settings/SettingsFragment.java`
- [Auth VM](https://github.com/skiletcool/myunit_java/blob/master/app/src/main/java/com/example/myunit/ui/auth/AuthViewModel.java): viewmodel · Coordinates login and registration actions. · `app/src/main/java/com/example/myunit/ui/auth/AuthViewModel.java`
- [Notes VM](https://github.com/skiletcool/myunit_java/blob/master/app/src/main/java/com/example/myunit/ui/notes/NoteViewModel.java): viewmodel · Drives note list and detail state. · `app/src/main/java/com/example/myunit/ui/notes/NoteViewModel.java`
- [Finance VM](https://github.com/skiletcool/myunit_java/blob/master/app/src/main/java/com/example/myunit/ui/finance/FinanceViewModel.java): viewmodel · Manages transaction and balance state. · `app/src/main/java/com/example/myunit/ui/finance/FinanceViewModel.java`
- [Health VM](https://github.com/skiletcool/myunit_java/blob/master/app/src/main/java/com/example/myunit/ui/health/HealthViewModel.java): viewmodel · Manages health log state and actions. · `app/src/main/java/com/example/myunit/ui/health/HealthViewModel.java`
- [AI VM](https://github.com/skiletcool/myunit_java/blob/master/app/src/main/java/com/example/myunit/ui/ai/AIViewModel.java): viewmodel · Builds chat requests and feeds assistant responses. · `app/src/main/java/com/example/myunit/ui/ai/AIViewModel.java`

### Data layer

Repositories, Room storage, and remote AI integration.

- [Repositories](https://github.com/skiletcool/myunit_java/tree/master/app/src/main/java/com/example/myunit/data/repository): domain boundary · Domain repositories mediating between UI and storage or network. · `app/src/main/java/com/example/myunit/data/repository`
- [AppDatabase](https://github.com/skiletcool/myunit_java/blob/master/app/src/main/java/com/example/myunit/data/local/AppDatabase.java): room database · Room database entry point for local persistence. · `app/src/main/java/com/example/myunit/data/local/AppDatabase.java`
- [Gemini API](https://github.com/skiletcool/myunit_java/blob/master/app/src/main/java/com/example/myunit/data/remote/GeminiApiService.java): remote service · Retrofit-based Gemini request/response integration. · `app/src/main/java/com/example/myunit/data/remote/GeminiApiService.java`
- [AI context](https://github.com/skiletcool/myunit_java/blob/master/app/src/main/java/com/example/myunit/data/repository/AIContextManager.java): prompt builder · Assembles local notes and goals into assistant context. · `app/src/main/java/com/example/myunit/data/repository/AIContextManager.java`

### Cross-cutting

Session, locale, and other app-wide helpers.

- [Session manager](https://github.com/skiletcool/myunit_java/blob/master/app/src/main/java/com/example/myunit/utils/SessionManager.java): session helper · Tracks local login/session state. · `app/src/main/java/com/example/myunit/utils/SessionManager.java`
- [Locale helper](https://github.com/skiletcool/myunit_java/blob/master/app/src/main/java/com/example/myunit/utils/LocaleHelper.java): locale helper · Supports app language and locale switching. · `app/src/main/java/com/example/myunit/utils/LocaleHelper.java`

### Navigation

Screen flow and fragment composition resources.

- [Nav graph](https://github.com/skiletcool/myunit_java/blob/master/app/src/main/res/navigation/nav_graph.xml): navigation · Primary navigation graph for the app flow. · `app/src/main/res/navigation/nav_graph.xml`
- [Home graph](https://github.com/skiletcool/myunit_java/blob/master/app/src/main/res/navigation/nav_graph_home.xml): navigation · Home-area navigation graph for the main shell. · `app/src/main/res/navigation/nav_graph_home.xml`

## Connections

- MainActivity → Nav graph: hosts · Main activity hosts the primary navigation flow.
- MainActivity → Home graph: embeds · Activity includes the home shell navigation.
- Nav graph → Auth: routes to · Primary graph routes into auth screens.
- Nav graph → Notes: routes to · Primary graph routes into notes.
- Nav graph → Finance: routes to · Primary graph routes into finance.
- Nav graph → Health: routes to · Primary graph routes into health.
- Nav graph → AI chat: routes to · Primary graph routes into AI chat.
- Nav graph → Settings: routes to · Primary graph routes into settings.
- Home graph → Home: contains · Home graph composes the landing shell.
- Auth → Auth VM: uses · Auth UI is driven by its ViewModel.
- Notes → Notes VM: uses · Notes UI is driven by its ViewModel.
- Finance → Finance VM: uses · Finance UI is driven by its ViewModel.
- Health → Health VM: uses · Health UI is driven by its ViewModel.
- AI chat → AI VM: uses · AI UI is driven by its ViewModel.
- Auth VM → Repositories: calls · Auth logic goes through the repository layer.
- Notes VM → Repositories: calls · Notes logic goes through the repository layer.
- Finance VM → Repositories: calls · Finance logic goes through the repository layer.
- Health VM → Repositories: calls · Health logic goes through the repository layer.
- AI VM → AI context: builds with · Assistant requests are enriched with local context.
- AI VM → Repositories: calls · AI feature persists and retrieves chat data through repositories.
- Repositories → AppDatabase: reads/writes · Domain repositories use Room for local persistence.
- Repositories → Gemini API: calls · AI-related repository work reaches the remote Gemini service.
- Repositories → Session manager: uses · User/session state is handled locally.
- MainActivity → Locale helper: applies · Activity-level locale changes are supported by helper utilities.
