# fliegendewurst/triliumdroid architecture

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

- Interactive diagram: https://gitdiagram.com/fliegendewurst/triliumdroid
- Repository: https://github.com/fliegendewurst/triliumdroid

## Overview

##### Main Components Identification
The system should be represented with these primary components:

a) Client-Side Components:
- UI Layer (Activities and Fragments)
- Data Management Layer
- Sync Service Layer
- Storage Layer

b) External Components:
- Trilium Notes Server
- Android System Services
- External Apps (for sharing)

##### Detailed Component Breakdown

A. UI Layer (Top Level):
- WelcomeActivity
- MainActivity
- SetupActivity
- AboutActivity
- Fragments hierarchy:
- NoteTreeFragment
- NoteEditFragment
- NoteMapFragment
- NoteRelatedFragment

B. Data Management Layer (Middle Level):
- Model Classes:
- Note
- Attribute
- Branch
- Relation
- Cache Management
- Data Synchronization

C. Backend Communication Layer:
- FrontendBackendApi
- ConnectionUtil
- Sync Protocol Handlers

D. Storage Layer (Bottom Level):
- SQLite Database (schema.sql)
- File Provider
- Cache Storage

##### Relationships and Data Flow

- User interaction flow
- Data synchronization flow
- Storage operations flow

##### Specific Implementation Details

- The sync protocol support for versions 0.90.12 and 0.63.7
- Tree structure and navigation
- Attribute inheritance system
- Local/global note mapping
- Basic scripting support

##### Technical Specifications

- Kotlin as primary language
- Android 8.0+ support
- External dependencies (AztecEditor, etc.)
- Database schema version

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef ui fill:#3498db,stroke:#2980b9,color:white
    classDef data fill:#2ecc71,stroke:#27ae60,color:white
    classDef comm fill:#f1c40f,stroke:#f39c12,color:black
    classDef storage fill:#9b59b6,stroke:#8e44ad,color:white
    classDef external fill:#95a5a6,stroke:#7f8c8d,color:white

    %% External Systems
    TriliumServer["Trilium Notes Server"]:::external
    AndroidSystem["Android System Services"]:::external
    ExternalApps["External Apps"]:::external

    %% UI Layer
    subgraph UILayer["UI Layer"]
        %% Activities
        WelcomeActivity["Welcome Activity"]:::ui
        MainActivity["Main Activity"]:::ui
        SetupActivity["Setup Activity"]:::ui
        AboutActivity["About Activity"]:::ui

        %% Fragments
        NoteTreeFragment["Note Tree Fragment"]:::ui
        NoteEditFragment["Note Edit Fragment"]:::ui
        NoteMapFragment["Note Map Fragment"]:::ui
        NoteRelatedFragment["Note Related Fragment"]:::ui

        %% Dialogs
        CreateNoteDialog["Create Note Dialog"]:::ui
        ModifyLabelsDialog["Modify Labels Dialog"]:::ui
        ModifyRelationsDialog["Modify Relations Dialog"]:::ui
    end

    %% Data Management Layer
    subgraph DataLayer["Data Management Layer"]
        %% Models
        Note["Note Model"]:::data
        Attribute["Attribute Model"]:::data
        Branch["Branch Model"]:::data
        Label["Label Model"]:::data
        Relation["Relation Model"]:::data
        Cache["Cache Management"]:::data
    end

    %% Backend Communication Layer
    subgraph CommLayer["Backend Communication Layer"]
        FrontendBackendApi["Frontend Backend API"]:::comm
        ConnectionUtil["Connection Utility"]:::comm
        SyncProtocol["Sync Protocol Handler"]:::comm
    end

    %% Storage Layer
    subgraph StorageLayer["Storage Layer"]
        SQLiteDB["SQLite Database"]:::storage
        FileProvider["File Provider"]:::storage
        CacheStorage["Cache Storage"]:::storage
    end

    %% Relationships
    TriliumServer <--> FrontendBackendApi
    FrontendBackendApi <--> ConnectionUtil
    ConnectionUtil <--> MainActivity
    MainActivity --> NoteTreeFragment
    MainActivity --> NoteEditFragment
    MainActivity --> NoteMapFragment
    MainActivity --> NoteRelatedFragment
    
    NoteTreeFragment --> CreateNoteDialog
    NoteRelatedFragment --> ModifyLabelsDialog
    NoteRelatedFragment --> ModifyRelationsDialog
    
    DataLayer <--> CommLayer
    CommLayer <--> StorageLayer
    UILayer <--> DataLayer

    AndroidSystem <--> FileProvider
    ExternalApps <--> MainActivity

    %% Click Events
    click WelcomeActivity "https://github.com/FliegendeWurst/TriliumDroid/blob/master/app/src/main/kotlin/eu/fliegendewurst/triliumdroid/activity/WelcomeActivity.kt"
    click MainActivity "https://github.com/FliegendeWurst/TriliumDroid/blob/master/app/src/main/kotlin/eu/fliegendewurst/triliumdroid/activity/main/MainActivity.kt"
    click SetupActivity "https://github.com/FliegendeWurst/TriliumDroid/blob/master/app/src/main/kotlin/eu/fliegendewurst/triliumdroid/SetupActivity.kt"
    click AboutActivity "https://github.com/FliegendeWurst/TriliumDroid/blob/master/app/src/main/kotlin/eu/fliegendewurst/triliumdroid/AboutActivity.kt"
    click NoteTreeFragment "https://github.com/FliegendeWurst/TriliumDroid/blob/master/app/src/main/kotlin/eu/fliegendewurst/triliumdroid/fragment/NoteTreeFragment.kt"
    click NoteEditFragment "https://github.com/FliegendeWurst/TriliumDroid/blob/master/app/src/main/kotlin/eu/fliegendewurst/triliumdroid/NoteEditFragment.kt"
    click NoteMapFragment "https://github.com/FliegendeWurst/TriliumDroid/blob/master/app/src/main/kotlin/eu/fliegendewurst/triliumdroid/fragment/NoteMapFragment.kt"
    click NoteRelatedFragment "https://github.com/FliegendeWurst/TriliumDroid/blob/master/app/src/main/kotlin/eu/fliegendewurst/triliumdroid/fragment/NoteRelatedFragment.kt"
    click Note "https://github.com/FliegendeWurst/TriliumDroid/blob/master/app/src/main/kotlin/eu/fliegendewurst/triliumdroid/data/Note.kt"
    click Attribute "https://github.com/FliegendeWurst/TriliumDroid/blob/master/app/src/main/kotlin/eu/fliegendewurst/triliumdroid/data/Attribute.kt"
    click Branch "https://github.com/FliegendeWurst/TriliumDroid/blob/master/app/src/main/kotlin/eu/fliegendewurst/triliumdroid/data/Branch.kt"
    click Label "https://github.com/FliegendeWurst/TriliumDroid/blob/master/app/src/main/kotlin/eu/fliegendewurst/triliumdroid/data/Label.kt"
    click Relation "https://github.com/FliegendeWurst/TriliumDroid/blob/master/app/src/main/kotlin/eu/fliegendewurst/triliumdroid/data/Relation.kt"
    click Cache "https://github.com/FliegendeWurst/TriliumDroid/blob/master/app/src/main/kotlin/eu/fliegendewurst/triliumdroid/Cache.kt"
    click FrontendBackendApi "https://github.com/FliegendeWurst/TriliumDroid/blob/master/app/src/main/kotlin/eu/fliegendewurst/triliumdroid/FrontendBackendApi.kt"
    click ConnectionUtil "https://github.com/FliegendeWurst/TriliumDroid/blob/master/app/src/main/kotlin/eu/fliegendewurst/triliumdroid/ConnectionUtil.kt"
    click SQLiteDB "https://github.com/FliegendeWurst/TriliumDroid/blob/master/app/src/main/res/raw/schema.sql"
    click FileProvider "https://github.com/FliegendeWurst/TriliumDroid/blob/master/app/src/main/kotlin/eu/fliegendewurst/triliumdroid/TriliumFileProvider.kt"
    click CreateNoteDialog "https://github.com/FliegendeWurst/TriliumDroid/blob/master/app/src/main/kotlin/eu/fliegendewurst/triliumdroid/dialog/CreateNewNoteDialog.kt"
    click ModifyLabelsDialog "https://github.com/FliegendeWurst/TriliumDroid/blob/master/app/src/main/kotlin/eu/fliegendewurst/triliumdroid/dialog/ModifyLabelsDialog.kt"
    click ModifyRelationsDialog "https://github.com/FliegendeWurst/TriliumDroid/blob/master/app/src/main/kotlin/eu/fliegendewurst/triliumdroid/dialog/ModifyRelationsDialog.kt"
```
