# computing-den/unforget architecture

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

- Interactive diagram: https://gitdiagram.com/computing-den/unforget
- Repository: https://github.com/computing-den/unforget

## Overview

##### Main Components

a. Client-Side (Browser):
- Progressive Web App Container
- React Frontend Application
- Service Worker Layer
- Local Storage (IndexedDB)
- Encryption/Decryption Module
- Sync Manager

b. Server-Side:
- API Server
- User Authentication System
- Encrypted Notes Storage
- Sync Management System

##### Key Architectural Patterns to Highlight

a. PWA Architecture:
- How the service worker (src/client/serviceWorker.ts) enables offline functionality
- Client-to-service-worker communication (src/client/clientToServiceWorkerApi.ts)

b. Security Layer:
- Demonstrate the end-to-end encryption flow
- Password hashing and key derivation processes
- Encryption boundary between client and server

c. Data Flow:
- Local storage operations
- Sync mechanism with delta and queue sync options
- Encryption/decryption process

##### Specific Implementation Details

**[Frontend Layer]**
- React Components (src/client/*.tsx)
- App Store (src/client/appStore.tsx)
- Router (src/client/router.tsx)
**↕️ (API Calls)**
**[Client Core Layer]**
- API Client (src/client/api.ts)
- Crypto Module (src/client/crypto.ts)
- Sync Manager (src/client/sync.ts)
**↕️ (Local Storage)**
**[Storage Layer]**
- IndexedDB (src/client/storage.ts)
- Service Worker Cache
**↕️ (HTTPS)**
**[Server Layer]**
- Authentication API
- Note Sync API
- Encrypted Storage

##### Important Flows to Illustrate

a. Creation/Update Flow:
**User Input → Encryption → Local Storage → Sync Queue → Server Storage**

b. Sync Flow:
**Delta Sync Request → Queue Sync (if needed) → Merge Resolution → Local Update**

c. Authentication Flow:
**Login/Signup → Password Hashing → Token Generation → Encryption Key Derivation**

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Browser
        PWA["PWA Container"]:::frontend
        click PWA "https://github.com/computing-den/unforget/blob/master/public/manifest.json"
        
        subgraph "Frontend Components"
            React["React Application"]:::frontend
            click React "https://github.com/computing-den/unforget/blob/master/src/client/App.tsx"
            AuthUI["Authentication UI"]:::frontend
            click AuthUI "https://github.com/computing-den/unforget/blob/master/src/client/LoginPage.tsx"
            NotesUI["Notes Management"]:::frontend
            click NotesUI "https://github.com/computing-den/unforget/blob/master/src/client/NotesPage.tsx"
            ImpExp["Import/Export UI"]:::frontend
            click ImpExp "https://github.com/computing-den/unforget/blob/master/src/client/ImportPage.tsx"
            AppState["App State"]:::frontend
            click AppState "https://github.com/computing-den/unforget/blob/master/src/client/appStore.tsx"
            Router["Router"]:::frontend
            click Router "https://github.com/computing-den/unforget/blob/master/src/client/router.tsx"
        end

        subgraph "Core Services"
            SW["Service Worker"]:::service
            click SW "https://github.com/computing-den/unforget/blob/master/src/client/serviceWorker.ts"
            SWComm["SW Communication"]:::service
            click SWComm "https://github.com/computing-den/unforget/blob/master/src/client/clientToServiceWorkerApi.ts"
            APIClient["API Client"]:::service
            click APIClient "https://github.com/computing-den/unforget/blob/master/src/client/api.ts"
            CryptoMod["Crypto Module"]:::security
            click CryptoMod "https://github.com/computing-den/unforget/blob/master/src/client/crypto.ts"
            SyncMgr["Sync Manager"]:::service
            click SyncMgr "https://github.com/computing-den/unforget/blob/master/src/client/sync.ts"
        end

        subgraph "Local Storage"
            IDB["IndexedDB"]:::storage
            click IDB "https://github.com/computing-den/unforget/blob/master/src/client/storage.ts"
            SWCache["SW Cache"]:::storage
        end
    end

    subgraph Server
        subgraph "Server Components"
            APIServer["API Server"]:::backend
            click APIServer "https://github.com/computing-den/unforget/blob/master/src/server/index.ts"
            AuthSystem["Authentication System"]:::backend
            DB["Database"]:::storage
            click DB "https://github.com/computing-den/unforget/blob/master/src/server/db.ts"
        end
    end

    subgraph "Common"
        Types["Types & Utilities"]:::common
        click Types "https://github.com/computing-den/unforget/blob/master/src/common/types.ts"
    end

    %% Relationships
    React --> AuthUI
    React --> NotesUI
    React --> ImpExp
    React --> AppState
    React --> Router
    
    AuthUI --> APIClient
    NotesUI --> APIClient
    ImpExp --> APIClient
    
    APIClient --> CryptoMod
    APIClient --> SyncMgr
    SyncMgr --> IDB
    
    SW --> SWComm
    SW --> SWCache
    
    APIClient --> APIServer
    APIServer --> AuthSystem
    APIServer --> DB
    
    %% Styles
    classDef frontend fill:#a7c7e7
    classDef service fill:#95b8d1
    classDef security fill:#ff9999
    classDef storage fill:#b8e6b8
    classDef backend fill:#ffb366
    classDef common fill:#e6e6e6

    %% Legend
    subgraph Legend
        F["Frontend Component"]:::frontend
        S["Service"]:::service
        Sec["Security Component"]:::security
        St["Storage"]:::storage
        B["Backend Component"]:::backend
        C["Common Utilities"]:::common
    end
```
