# triliumnext/notes architecture

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

- Interactive diagram: https://gitdiagram.com/triliumnext/notes
- Repository: https://github.com/triliumnext/notes

## Overview

##### Main Components Overview

a) Frontend Layer:
- Desktop Application (Electron-based)
- Web Interface
- Mobile Interface
- Share Interface (for public note sharing)

b) Backend Layer:
- Core Server
- API Services
- Database Layer
- File Storage
- Authentication/Authorization

##### Detailed Component Breakdown

- Client Layer                                         |

- Desktop   |  |    Web     |  |   Mobile    |  |     Share     |                  |
- (Electron)  |  | Interface  |  | Interface   |  |   Interface   |                  |

- Server Layer                                         |

- Note Service  |  | Sync Service  |  | Search Service |  | Authentication Service|   |

- Script Service  |  | ETAPI Service |  | Export Service |  |   Encryption Service |   |

- Data Layer                                           |

- SQLite DB     |  |  Blob Storage    |  |  File System   |                           |
- (Notes/Meta)   |  | (Attachments)    |  | (Resources)    |                           |

##### Key Integration Points

- Bidirectional sync between clients and server
- Authentication flow
- CRUD operations
- Search queries
- File uploads/downloads

##### Special Features to Highlight

- Encryption system
- Versioning system
- Synchronization mechanism
- Plugin/Script system
- Search engine
- Attribute system

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Layer"]
        Desktop["Desktop App (Electron)"]
        Web["Web Interface"]
        Mobile["Mobile Interface"]
        Share["Share Interface"]
    end

    subgraph Server["Server Layer"]
        direction TB
        CoreServer["Core Server"]
        
        subgraph Services["Core Services"]
            direction TB
            NoteService["Note Service"]
            SyncService["Sync Service"]
            SearchService["Search Service"]
            AuthService["Authentication Service"]
            ScriptService["Script Service"]
            ETAPIService["ETAPI Service"]
            ExportService["Export Service"]
            EncryptService["Encryption Service"]
            OptionsService["Options Service"]
            BackupService["Backup Service"]
            ImageService["Image Service"]
            TreeService["Tree Service"]
        end

        subgraph API["API Layer"]
            APIEndpoints["API Endpoints"]
            ETAPIRoutes["ETAPI Routes"]
            SyncRoutes["Sync Routes"]
        end
    end

    subgraph Data["Data Layer"]
        DB[(Database Layer)]
        EntityStorage["Entity Storage"]
        DBSchema["Database Schema"]
        DBMigrations["Database Migrations"]
    end

    subgraph UI["UI Components"]
        Widgets["Widgets"]
        TypeWidgets["Type Widgets"]
        DialogWidgets["Dialog Widgets"]
    end

    %% Connections
    Desktop & Web & Mobile & Share --> APIEndpoints
    APIEndpoints --> Services
    Services --> DB
    Services --> EntityStorage
    CoreServer --> Services
    CoreServer --> API

    %% Click Events
    click Desktop "https://github.com/TriliumNext/Notes/blob/develop/src/public/app/desktop.js"
    click Web "https://github.com/TriliumNext/Notes/blob/develop/src/public/app/layouts/desktop_layout.js"
    click Mobile "https://github.com/TriliumNext/Notes/blob/develop/src/public/app/layouts/mobile_layout.js"
    click Share "https://github.com/TriliumNext/Notes/tree/develop/src/share"
    click CoreServer "https://github.com/TriliumNext/Notes/blob/develop/src/app.ts"
    click NoteService "https://github.com/TriliumNext/Notes/blob/develop/src/services/notes.ts"
    click SyncService "https://github.com/TriliumNext/Notes/blob/develop/src/services/sync.ts"
    click SearchService "https://github.com/TriliumNext/Notes/tree/develop/src/services/search"
    click AuthService "https://github.com/TriliumNext/Notes/blob/develop/src/services/auth.ts"
    click ScriptService "https://github.com/TriliumNext/Notes/blob/develop/src/services/script.ts"
    click ETAPIService "https://github.com/TriliumNext/Notes/blob/develop/src/services/etapi_tokens.ts"
    click ExportService "https://github.com/TriliumNext/Notes/tree/develop/src/services/export"
    click EncryptService "https://github.com/TriliumNext/Notes/tree/develop/src/services/encryption"
    click DB "https://github.com/TriliumNext/Notes/tree/develop/src/becca"
    click EntityStorage "https://github.com/TriliumNext/Notes/tree/develop/src/becca/entities"
    click DBSchema "https://github.com/TriliumNext/Notes/blob/develop/db/schema.sql"
    click DBMigrations "https://github.com/TriliumNext/Notes/tree/develop/db/migrations"
    click APIEndpoints "https://github.com/TriliumNext/Notes/tree/develop/src/routes/api"
    click ETAPIRoutes "https://github.com/TriliumNext/Notes/blob/develop/src/routes/api/etapi_tokens.ts"
    click SyncRoutes "https://github.com/TriliumNext/Notes/blob/develop/src/routes/api/sync.ts"
    click Widgets "https://github.com/TriliumNext/Notes/tree/develop/src/public/app/widgets"
    click TypeWidgets "https://github.com/TriliumNext/Notes/tree/develop/src/public/app/widgets/type_widgets"
    click DialogWidgets "https://github.com/TriliumNext/Notes/tree/develop/src/public/app/widgets/dialogs"
    click OptionsService "https://github.com/TriliumNext/Notes/blob/develop/src/services/options.ts"
    click BackupService "https://github.com/TriliumNext/Notes/blob/develop/src/services/backup.ts"
    click ImageService "https://github.com/TriliumNext/Notes/blob/develop/src/services/image.ts"
    click TreeService "https://github.com/TriliumNext/Notes/blob/develop/src/services/tree.ts"

    %% Styling
    classDef client fill:#a8d1ff
    classDef server fill:#ffb3b3
    classDef data fill:#c2f0c2
    classDef ui fill:#ffe6cc
    classDef service fill:#ffccff

    class Desktop,Web,Mobile,Share client
    class CoreServer,Services,API server
    class DB,EntityStorage,DBSchema,DBMigrations data
    class Widgets,TypeWidgets,DialogWidgets ui
    class NoteService,SyncService,SearchService,AuthService,ScriptService,ETAPIService,ExportService,EncryptService,OptionsService,BackupService,ImageService,TreeService service
```
