# tonghoai/opennotas architecture

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

## Overview

##### Main Components

a. Frontend Layer:
- Vue.js/Nuxt.js Application Structure
- PWA Components
- UI Components (organized by feature)
- Editors (CodeMirror and TipTap)

b. Core Services Layer:
- Storage Management
- Encryption Services
- Synchronization Services
- Authentication Services

c. Adapter Layer:
- LocalForage Adapter
- Turso Adapter
- Database Models

**┌─────────────────────────────────────────────────────────┐**
- Presentation Layer                     │
- ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐│
- Pages     │ │ Components  │ │      UI/UX          ││
- ┘ └─────────────┘ └─────────────────────┘│
- ┤
- Core Services Layer                    │
- ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐│
- Security   │ │    Sync     │ │     Storage         ││
- ┘ └─────────────┘ └─────────────────────┘│
- ┤
- Data Layer                            │
- ┌─────────────┐ ┌─────────────┐                        │
- LocalForage │ │   Turso     │                        │
- ┘ └─────────────┘                        │
- ┘

##### Key Elements to Highlight

a. Presentation Layer:
- Main pages (landing, install, service, sos)
- Components (editor, modal, toolbar)
- PWA-specific elements

b. Core Services Layer:
- Encryption service (AES implementation)
- Sync service with conflict resolution
- Storage management
- Search functionality (FlexSearch)

c. Data Layer:
- Storage adapters (LocalForage, Turso)
- Database models (folders, notes, settings)
- Migration system

##### Data Flow Indicators

- User interaction flow
- Data synchronization flow
- Encryption/decryption process
- Storage operations

##### Additional Details

- Component interaction patterns
- State management flow
- Error handling paths
- Migration processes

Remember to:
- Use consistent symbols and notation
- Version information
- Document all external dependencies

This system design should emphasize OpenNotas's key features: security, synchronization, and cross-platform compatibility, while maintaining clarity about the application's architecture and data flow.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        Pages["Pages"]
        PWA["PWA Components"]
        UI["UI Components"]
        Editors["Editors"]
        
        subgraph EditorComponents
            CodeMirror["CodeMirror"]
            TipTap["TipTap"]
        end
        
        Editors --> CodeMirror
        Editors --> TipTap
    end
    
    subgraph CoreServices
        Storage["Storage Management"]
        Encryption["Encryption Services"]
        Sync["Synchronization Services"]
        Auth["Authentication Services"]
        Search["Search Service"]
        State["State Management"]
        I18n["Internationalization"]
        ErrorHandler["Error Handling"]
    end
    
    subgraph DataLayer
        LocalForage["LocalForage Adapter"]
        Turso["Turso Adapter"]
        Models["Database Models"]
        Migrations["Migrations"]
    end
    
    %% Frontend Relationships
    Pages --> UI
    UI --> Editors
    
    %% Core to Frontend
    Storage --> UI
    Encryption --> UI
    Sync --> UI
    Auth --> UI
    Search --> UI
    
    %% Core to Data
    Storage --> LocalForage
    Storage --> Turso
    Sync --> LocalForage
    Sync --> Turso
    
    %% Data Relationships
    Turso --> Models
    Turso --> Migrations
    
    %% Styles
    classDef frontend fill:#a8d1ff,stroke:#333,stroke-width:1px
    classDef core fill:#90EE90,stroke:#333,stroke-width:1px
    classDef data fill:#FFB6C1,stroke:#333,stroke-width:1px
    classDef security fill:#FFD700,stroke:#333,stroke-width:1px
    
    class Pages,PWA,UI,Editors,CodeMirror,TipTap frontend
    class Storage,Sync,Search,State,I18n,ErrorHandler core
    class Encryption,Auth security
    class LocalForage,Turso,Models,Migrations data
    
    %% Click Events
    click Pages "https://github.com/tonghoai/opennotas/tree/main/pages"
    click CodeMirror "https://github.com/tonghoai/opennotas/tree/main/components/editor/codemirror"
    click TipTap "https://github.com/tonghoai/opennotas/tree/main/components/editor/tiptap"
    click PWA "https://github.com/tonghoai/opennotas/blob/main/public/sw.js"
    click UI "https://github.com/tonghoai/opennotas/tree/main/components"
    click Storage "https://github.com/tonghoai/opennotas/blob/main/repositories/storage.ts"
    click Encryption "https://github.com/tonghoai/opennotas/blob/main/utils/encrypt.ts"
    click Sync "https://github.com/tonghoai/opennotas/blob/main/utils/sync.ts"
    click Auth "https://github.com/tonghoai/opennotas/blob/main/utils/password.ts"
    click LocalForage "https://github.com/tonghoai/opennotas/blob/main/adapter/localforage/index.ts"
    click Turso "https://github.com/tonghoai/opennotas/blob/main/adapter/turso/index.ts"
    click Models "https://github.com/tonghoai/opennotas/tree/main/adapter/turso/models"
    click Migrations "https://github.com/tonghoai/opennotas/tree/main/adapter/turso/migrations"
    click Search "https://github.com/tonghoai/opennotas/blob/main/utils/flexsearch.ts"
    click State "https://github.com/tonghoai/opennotas/blob/main/utils/modal.ts"
    click I18n "https://github.com/tonghoai/opennotas/tree/main/locales"
    click ErrorHandler "https://github.com/tonghoai/opennotas/blob/main/utils/sync-error.ts"
```
