# mhss1/mybrain architecture

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

- Interactive diagram: https://gitdiagram.com/mhss1/mybrain
- Repository: https://github.com/mhss1/mybrain

## Overview

##### Main Architecture Overview

a) Core Layers (vertically):
- Presentation Layer (UI/Compose)
- Domain Layer (Use Cases)
- Data Layer (Repository Implementations)
- Database Layer (Room)

b) Feature Modules (horizontally):
- Tasks
- Notes
- Calendar
- Diary
- Bookmarks
- AI Assistant
- Settings
- Widget

##### Module Dependencies
- Feature modules → Core modules
- All modules → Core:UI
- All modules → Core:Database
- All modules → Core:DI (Koin)

##### Data Flow Components

a) Local Storage:
- Room Database
- DataStore Preferences
- File System (for backups)

b) External Integrations:
- Calendar Content Provider
- AI APIs (OpenAI, Gemini)
- Alarm Manager
- Biometric Authentication

##### Specific Implementation Details

For each feature module, show:
- Repository
- Use Cases
- ViewModels
- UI Components

Example for Tasks Module:
**Tasks Module**
- Presentation
- TasksViewModel
- TasksScreen
- Components
- Domain
- TaskRepository (Interface)
- Use Cases
- Data
- TaskRepositoryImpl

##### Cross-Cutting Concerns

Shared functionality:
- DI Container (Koin)
- Navigation
- Theme/Styling
- Permissions
- Notifications

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Application Layer"
        App["Main Application"]:::app
        MainActivity["Main Activity"]:::app
        NavGraph["Navigation Graph"]:::app
    end

    subgraph "Core Modules"
        Database["Database Layer"]:::core
        UI["UI/Theme Layer"]:::core
        DI["Dependency Injection"]:::core
        Prefs["Preferences"]:::core
        Notif["Notifications"]:::core
        WidgetCore["Widget Core"]:::core
    end

    subgraph "Feature Modules"
        direction TB
        subgraph "AI Assistant"
            AIData["Data Layer<br>- API Client<br>- Response Cache<br>- Message History"]:::data
            AIDomain["Domain Layer<br>- Message Processing<br>- Context Management<br>- Stream Handling"]:::domain
            AIPresentation["Presentation Layer<br>- Chat Interface<br>- Message Display<br>- Input Handling<br>- Stream Updates"]:::presentation
        end

        subgraph "Tasks"
            TasksData["Data Layer"]:::data
            TasksDomain["Domain Layer"]:::domain
            TasksPresentation["Presentation Layer"]:::presentation
        end

        subgraph "Notes"
            NotesData["Data Layer"]:::data
            NotesDomain["Domain Layer"]:::domain
            NotesPresentation["Presentation Layer"]:::presentation
        end

        subgraph "Calendar"
            CalendarData["Data Layer"]:::data
            CalendarDomain["Domain Layer"]:::domain
            CalendarPresentation["Presentation Layer"]:::presentation
        end

        subgraph "Diary"
            DiaryData["Data Layer"]:::data
            DiaryDomain["Domain Layer"]:::domain
            DiaryPresentation["Presentation Layer"]:::presentation
        end

        subgraph "Bookmarks"
            BookmarksData["Data Layer"]:::data
            BookmarksDomain["Domain Layer"]:::domain
            BookmarksPresentation["Presentation Layer"]:::presentation
        end

        subgraph "Settings"
            SettingsData["Data Layer"]:::data
            SettingsDomain["Domain Layer"]:::domain
            SettingsPresentation["Presentation Layer"]:::presentation
        end
    end

    subgraph "Widget Implementation"
        CalendarWidget["Calendar Widget"]:::widget
        TasksWidget["Tasks Widget"]:::widget
    end

    subgraph "External Services"
        CalendarProvider["Calendar Content Provider"]:::external
        AIAPIs["AI APIs (OpenAI, Gemini)"]:::external
        AlarmManager["Alarm Manager"]:::external
        BiometricAuth["Biometric Authentication"]:::external
    end

    %% Core Dependencies
    App --> MainActivity
    MainActivity --> NavGraph
    App --> DI

    %% Feature Module Dependencies
    TasksPresentation --> TasksDomain --> TasksData
    NotesPresentation --> NotesDomain --> NotesData
    CalendarPresentation --> CalendarDomain --> CalendarData
    DiaryPresentation --> DiaryDomain --> DiaryData
    BookmarksPresentation --> BookmarksDomain --> BookmarksData
    AIPresentation --> AIDomain --> AIData
    SettingsPresentation --> SettingsDomain --> SettingsData

    %% Core Module Dependencies
    TasksData & NotesData & CalendarData & DiaryData & BookmarksData & AIData & SettingsData --> Database
    TasksPresentation & NotesPresentation & CalendarPresentation & DiaryPresentation & BookmarksPresentation & AIPresentation & SettingsPresentation --> UI

    %% Widget Dependencies
    CalendarWidget & TasksWidget --> WidgetCore
    
    %% External Service Dependencies
    CalendarData --> CalendarProvider
    AIData --> AIAPIs
    TasksData --> AlarmManager
    App --> BiometricAuth

    %% Click Events
    click App "https://github.com/mhss1/MyBrain/blob/master/app/src/main/java/com/mhss/app/mybrain/MyBrainApplication.kt"
    click MainActivity "https://github.com/mhss1/MyBrain/blob/master/app/src/main/java/com/mhss/app/mybrain/presentation/main/MainActivity.kt"
    click NavGraph "https://github.com/mhss1/MyBrain/blob/master/app/src/main/java/com/mhss/app/mybrain/presentation/main/components/NavigationGraph.kt"
    click Database "https://github.com/mhss1/MyBrain/tree/master/core/database/"
    click UI "https://github.com/mhss1/MyBrain/tree/master/core/ui/"
    click DI "https://github.com/mhss1/MyBrain/tree/master/core/di/"
    click Prefs "https://github.com/mhss1/MyBrain/tree/master/core/preferences/"
    click Notif "https://github.com/mhss1/MyBrain/tree/master/core/notification/"
    click WidgetCore "https://github.com/mhss1/MyBrain/tree/master/core/widget/"
    click TasksData "https://github.com/mhss1/MyBrain/tree/master/tasks/data/"
    click TasksDomain "https://github.com/mhss1/MyBrain/tree/master/tasks/domain/"
    click TasksPresentation "https://github.com/mhss1/MyBrain/tree/master/tasks/presentation/"
    click NotesData "https://github.com/mhss1/MyBrain/tree/master/notes/data/"
    click NotesDomain "https://github.com/mhss1/MyBrain/tree/master/notes/domain/"
    click NotesPresentation "https://github.com/mhss1/MyBrain/tree/master/notes/presentation/"
    click CalendarData "https://github.com/mhss1/MyBrain/tree/master/calendar/data/"
    click CalendarDomain "https://github.com/mhss1/MyBrain/tree/master/calendar/domain/"
    click CalendarPresentation "https://github.com/mhss1/MyBrain/tree/master/calendar/presentation/"
    click DiaryData "https://github.com/mhss1/MyBrain/tree/master/diary/data/"
    click DiaryDomain "https://github.com/mhss1/MyBrain/tree/master/diary/domain/"
    click DiaryPresentation "https://github.com/mhss1/MyBrain/tree/master/diary/presentation/"
    click BookmarksData "https://github.com/mhss1/MyBrain/tree/master/bookmarks/data/"
    click BookmarksDomain "https://github.com/mhss1/MyBrain/tree/master/bookmarks/domain/"
    click BookmarksPresentation "https://github.com/mhss1/MyBrain/tree/master/bookmarks/presentation/"
    click AIData "https://github.com/mhss1/MyBrain/tree/master/ai/data/"
    click AIDomain "https://github.com/mhss1/MyBrain/tree/master/ai/domain/"
    click AIPresentation "https://github.com/mhss1/MyBrain/tree/master/ai/presentation/"
    click SettingsData "https://github.com/mhss1/MyBrain/tree/master/settings/data/"
    click SettingsDomain "https://github.com/mhss1/MyBrain/tree/master/settings/domain/"
    click SettingsPresentation "https://github.com/mhss1/MyBrain/tree/master/settings/presentation/"
    click CalendarWidget "https://github.com/mhss1/MyBrain/tree/master/widget/src/main/java/com/mhss/app/widget/calendar/"
    click TasksWidget "https://github.com/mhss1/MyBrain/tree/master/widget/src/main/java/com/mhss/app/widget/tasks/"

    %% Styling
    classDef app fill:#f9f,stroke:#333
    classDef core fill:#9cf,stroke:#333
    classDef data fill:#fcf,stroke:#333
    classDef domain fill:#cfc,stroke:#333
    classDef presentation fill:#ffc,stroke:#333
    classDef widget fill:#ff9,stroke:#333
    classDef external fill:#f90,stroke:#333

    %% Legend
    subgraph Legend
        L1["Application Components"]:::app
        L2["Core Modules"]:::core
        L3["Data Layer"]:::data
        L4["Domain Layer"]:::domain
        L5["Presentation Layer"]:::presentation
        L6["Widget Components"]:::widget
        L7["External Services"]:::external
    end
```
