# dinesh2811/mynotes architecture

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

- Interactive diagram: https://gitdiagram.com/dinesh2811/mynotes
- Repository: https://github.com/dinesh2811/mynotes

## Overview

##### Main Architectural Layers
- User Interface (UI) Layer: This includes all the Android activities (MainActivity, AddNote, EditNote) along with various layouts, XML drawable resources, and UI components (NavigationDrawer, ToolbarMain, FancySnackbar, etc.).
- Presentation and Business Logic Layer: This is mainly represented by the ViewModel (NotesViewModel) and related helper classes in the “app” package, making use of LiveData and Coroutines for state management and asynchronous operations.
- Data Persistence Layer: The Room Database components (NotesDatabase, NotesDao, Note model, LocalDateTimeConverter) handle local data storage. This layer also underpins the backup/restore functionality mentioned in the README.
- External Services/Utilities: Components for AES 256-bit encryption, backup services, and integrations with external libraries (e.g., Gson for JSON handling, ZXing for QR code features) should be represented here.

##### Deciding on Component Details and Interactions
- Presentation Layer: Show the ViewModel (NotesViewModel) and any associated components (like LiveData and Coroutine support) that handle user events and coordinate with the data layer.
- Data Layer: Illustrate the Room Database with its DAO (NotesDao) and data models (Note, converters). Emphasize the data flow from Room to the ViewModel.
- Backup/Encryption Module: Given the emphasis on AES 256-bit encryption for backups, include a separate component or module (possibly part of the app package as a helper or utility class) dedicated to encryption, backup, and restore processes.
- Third-Party Libraries: Although these may not have dedicated modules in the file tree, include them as external dependencies (e.g., Gson for JSON, ZXing for QR code scanning) that interact with the overall system at relevant points.

##### Architectural Patterns and Design Principles
- MVVM Pattern: Since the project leverages ViewModel and LiveData, denote the separation between view (activities and layouts), view model (NotesViewModel), and model (Room Database, encryption components).
- Decoupling and Asynchronous Data Handling: Highlight the use of Coroutines that ensure the UI stays responsive while handling data operations (especially during database queries or backup encryption tasks).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "UI Layer"
        MA["MainActivity"]:::ui
        AN["AddNote Activity"]:::ui
        EN["EditNote Activity"]:::ui
        LR["Layout Resources"]:::ui
    end

    %% Presentation and Business Logic Layer
    subgraph "Presentation Layer"
        NVM["NotesViewModel"]:::business
        ND["NavigationDrawer"]:::business
        TM["ToolbarMain"]:::business
        FS["FancySnackbar"]:::business
        FL["FancySnackbarLayout"]:::business
    end

    %% Data Persistence Layer
    subgraph "Data Persistence Layer"
        RDB["Room Database"]:::data
        NM["Note Model"]:::data
        NDao["NotesDao"]:::data
        LDT["LocalDateTimeConverter"]:::data
    end

    %% Backup/Encryption Module
    subgraph "Backup/Encryption Module"
        BD["Backup Dialog"]:::backup
        BI["Backup Icon"]:::backup
        BR["Backup Rules"]:::backup
    end

    %% External Libraries
    subgraph "External Libraries"
        G["Gson"]:::external
        ZX["ZXing"]:::external
    end

    %% Connections from UI to Presentation
    MA -->|"triggers"| NVM
    AN -->|"triggers"| NVM
    EN -->|"triggers"| NVM

    %% UI component integrations
    MA -->|"uses"| ND
    MA -->|"uses"| TM
    MA -->|"shows"| FS

    %% Presentation to Data interactions
    NVM -->|"CRUD Operations"| RDB
    RDB -->|"LiveData Updates"| NVM

    %% Data layer internal structure
    RDB -->|"includes"| NDao
    RDB -->|"includes"| NM
    RDB -->|"uses"| LDT

    %% Data to Backup/Encryption flow
    RDB -->|"supplies backup data"| BD

    %% Backup Module internal flow
    BD -->|"integrates"| BI
    BD -->|"applies"| BR

    %% Backup Module and External Libraries
    BD -->|"serializes"| G
    BD -->|"generatesQR"| ZX

    %% Class definitions for color coding
    classDef ui fill:#FFEEAD,stroke:#EFB700,stroke-width:2px;
    classDef business fill:#C6E2FF,stroke:#1E90FF,stroke-width:2px;
    classDef data fill:#DBFFC2,stroke:#32CD32,stroke-width:2px;
    classDef backup fill:#FFD1DC,stroke:#FF69B4,stroke-width:2px;
    classDef external fill:#F0F8FF,stroke:#4682B4,stroke-width:2px;

    %% Click Events for UI Layer
    click MA "https://github.com/dinesh2811/mynotes/blob/A15/app/src/main/java/com/dinesh/mynotes/MainActivity.kt"
    click AN "https://github.com/dinesh2811/mynotes/blob/A15/app/src/main/java/com/dinesh/mynotes/activity/AddNote.kt"
    click EN "https://github.com/dinesh2811/mynotes/blob/A15/app/src/main/java/com/dinesh/mynotes/activity/EditNote.kt"
    click LR "https://github.com/dinesh2811/mynotes/tree/A15/app/src/main/res/layout"

    %% Click Events for Presentation Layer
    click NVM "https://github.com/dinesh2811/mynotes/blob/A15/app/src/main/java/com/dinesh/mynotes/room/NotesViewModel.kt"
    click ND "https://github.com/dinesh2811/mynotes/blob/A15/app/src/main/java/com/dinesh/mynotes/app/NavigationDrawer.kt"
    click TM "https://github.com/dinesh2811/mynotes/blob/A15/app/src/main/java/com/dinesh/mynotes/app/ToolbarMain.kt"
    click FS "https://github.com/dinesh2811/mynotes/blob/A15/app/src/main/java/com/dinesh/mynotes/app/FancySnackbar.kt"
    click FL "https://github.com/dinesh2811/mynotes/blob/A15/app/src/main/java/com/dinesh/mynotes/app/FancySnackbarLayout.kt"

    %% Click Events for Data Persistence Layer
    click NM "https://github.com/dinesh2811/mynotes/blob/A15/app/src/main/java/com/dinesh/mynotes/room/Note.kt"
    click RDB "https://github.com/dinesh2811/mynotes/blob/A15/app/src/main/java/com/dinesh/mynotes/room/NotesDatabase.kt"
    click NDao "https://github.com/dinesh2811/mynotes/blob/A15/app/src/main/java/com/dinesh/mynotes/room/NotesDao.kt"
    click LDT "https://github.com/dinesh2811/mynotes/blob/A15/app/src/main/java/com/dinesh/mynotes/room/LocalDateTimeConverter.kt"

    %% Click Events for Backup/Encryption Module
    click BD "https://github.com/dinesh2811/mynotes/blob/A15/app/src/main/res/layout/dialog_to_enter_decryption_key.xml"
    click BI "https://github.com/dinesh2811/mynotes/blob/A15/app/src/main/res/drawable/baseline_backup_24.xml"
    click BR "https://github.com/dinesh2811/mynotes/blob/A15/app/src/main/res/xml/backup_rules.xml"
```
