# streetwriters/notesnook architecture

> Architecture diagram of the GitHub repository streetwriters/notesnook, 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/streetwriters/notesnook
- Repository: https://github.com/streetwriters/notesnook

## Overview

##### High-Level Architecture Components

a. Client Applications (Frontend Layer):
- Web Client (React)
- Desktop Client (Electron)
- Mobile Client (React Native)
- Web Clipper Extension

b. Core Services Layer:
- Database Management
- Encryption Services
- Sync Engine
- Management
- Collections Management

c. Shared Components Layer:
- Editor (@notesnook/editor)
- Cryptography (@notesnook/crypto)
- Theme Engine (@notesnook/theme)
- Logging System (@notesnook/logger)

##### Data Flow & Integration Points

a. Client-Core Communication:
- Data encryption/decryption flow
- Synchronization
- User authentication
- Storage operations

b. Storage & Encryption:
- IndexedDB (via @notesnook/streamable-fs)
- Local encryption layer
- Remote sync storage

##### Key Architectural Features

a. Security Components:
- Encryption mechanisms:
- XChaCha20-Poly1305 encryption
- Argon2 key derivation
- Zero-knowledge architecture

b. Cross-Platform Integration:
- Shared components:
- Common core logic
- Unified editor experience
- Consistent theming

##### Important Subsystems

a. Editor System:
- Rich text editing
- Markdown support
- Attachments handling
- Real-time collaboration

b. Sync Engine:
- Components for:
- Change detection
- Conflict resolution
- Delta synchronization
- Multi-device sync

##### External Integrations

- Connections for:
- Web Clipper integration
- Import/Export systems
- Backup systems
- Third-party integrations

##### Implementation Details

Specific technologies:
- React/React Native for UI
- Electron for desktop
- IndexedDB for storage
- WebAssembly for encryption
- TypeScript/JavaScript

##### Security boundaries and data flow

Remember to:
- Use consistent styling
- Related components
- Clear boundaries between systems
- Security zones
- Document all major interfaces

This system design should provide a clear understanding of how Notesnook's various components interact while maintaining its core promise of privacy and security.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Clients
        WC["Web Client"]:::client
        DC["Desktop Client"]:::client
        MC["Mobile Client"]:::client
        WCE["Web Clipper Extension"]:::client
    end

    subgraph CoreServices
        DM["Database Management"]:::core
        ES["Encryption Services"]:::security
        SE["Sync Engine"]:::core
        NM["Note Management"]:::core
        CM["Collections Management"]:::core
    end

    subgraph SharedComponents
        ED["Editor"]:::shared
        CR["Cryptography"]:::security
        TE["Theme Engine"]:::shared
        LS["Logging System"]:::shared
    end

    subgraph Storage
        IDB["IndexedDB"]:::storage
        RS["Remote Sync Storage"]:::storage
    end

    subgraph SecurityLayer
        XC["XChaCha20-Poly1305"]:::security
        AR["Argon2"]:::security
        ZK["Zero-knowledge Architecture"]:::security
    end

    subgraph EditorSystem
        RTE["Rich Text Editing"]:::editor
        MD["Markdown Support"]:::editor
        AH["Attachments Handling"]:::editor
        RC["Real-time Collaboration"]:::editor
    end

    subgraph SyncEngine
        CD["Change Detection"]:::sync
        CR2["Conflict Resolution"]:::sync
        DS["Delta Synchronization"]:::sync
        MDS["Multi-device Sync"]:::sync
    end

    %% Connections
    Clients --> CoreServices
    CoreServices <--> SharedComponents
    CoreServices <--> Storage
    SecurityLayer --> CoreServices
    EditorSystem --> ED
    SyncEngine --> SE

    %% Styling
    classDef client fill:#90EE90
    classDef core fill:#87CEEB
    classDef shared fill:#DDA0DD
    classDef security fill:#FFD700
    classDef storage fill:#A9A9A9
    classDef editor fill:#98FB98
    classDef sync fill:#87CEFA

    %% Click Events
    click WC "https://github.com/streetwriters/notesnook/tree/master/apps/web/"
    click DC "https://github.com/streetwriters/notesnook/tree/master/apps/desktop/"
    click MC "https://github.com/streetwriters/notesnook/tree/master/apps/mobile/"
    click WCE "https://github.com/streetwriters/notesnook/tree/master/extensions/web-clipper/"
    click DM "https://github.com/streetwriters/notesnook/tree/master/packages/core/src/database/"
    click ES "https://github.com/streetwriters/notesnook/tree/master/packages/crypto/"
    click SE "https://github.com/streetwriters/notesnook/tree/master/packages/core/src/api/sync/"
    click NM "https://github.com/streetwriters/notesnook/blob/master/packages/core/src/collections/notes.ts"
    click CM "https://github.com/streetwriters/notesnook/tree/master/packages/core/src/collections/"
    click ED "https://github.com/streetwriters/notesnook/tree/master/packages/editor/"
    click CR "https://github.com/streetwriters/notesnook/tree/master/packages/crypto/"
    click TE "https://github.com/streetwriters/notesnook/tree/master/packages/theme/"
    click LS "https://github.com/streetwriters/notesnook/tree/master/packages/logger/"
    click RTE "https://github.com/streetwriters/notesnook/tree/master/packages/editor/src/extensions/"
    click CD "https://github.com/streetwriters/notesnook/tree/master/packages/core/src/api/sync/"
    click IDB "https://github.com/streetwriters/notesnook/tree/master/packages/streamable-fs/"
    click XC "https://github.com/streetwriters/notesnook/blob/master/packages/crypto/src/encryption.ts"
    click AR "https://github.com/streetwriters/notesnook/blob/master/packages/crypto/src/keyutils.ts"
    click ZK "https://github.com/streetwriters/notesnook/blob/master/packages/crypto/src/password.ts"
```
