# cryptee/web-client architecture

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

## Overview

##### Main Components

A. Client-Side (Frontend) Layer
- Document Editor Component
- Photo Storage Component
- Authentication Component
- Encryption Layer (OpenPGP.js implementation)
- File Processing Adapters (PDF.js, EPUB Reader, Mammoth)
- Local Storage/IndexedDB (Dexie implementation)

B. API Gateway Layer
- Authentication Endpoints
- Document Management Endpoints
- Photo Management Endpoints
- Payment/Billing Endpoints

- User Management Service
- Storage Service
- Payment Processing Service
- Abuse Prevention System

##### Key Relationships to Highlight

a. Client-Side Security:
- Encryption happening entirely in the browser
- Demonstrate how data never leaves the device unencrypted
- Relationship between the encryption layer and storage

b. Adapter Integration:
- How different file format adapters (PDF.js, EPUB, etc.) connect to the main application
- Document processing pipeline

c. Storage Flow:
- Demonstrate the path from local storage to encrypted cloud storage
- Sync mechanisms between devices

##### Important Architectural Patterns to Emphasize

- Client-Side Encryption: Show how all encryption happens in the browser
- Progressive Web App Structure: Indicate offline capabilities
- Modular Design: Highlight the separation between documents, photos, and authentication
- Multi-Format Support: Show the adapter pattern for different file types

##### Technical Stack Indicators

Technology badges or labels for:
- Frontend: Zepto/jQuery, QuillJS
- Encryption: OpenPGP.js
- Storage: IndexedDB/Dexie
- File Processing: PDF.js, Mammoth, EPUB Reader
- Authentication: Custom implementation

##### Security Boundaries

Clearly mark:
- Trust boundaries between client and server
- Encryption/decryption boundaries
- Data storage boundaries
- Authentication checkpoints

##### Additional Elements

- Version information for critical components
- Points where data is encrypted/decrypted
- Offline capability mechanisms
- Where user preferences and settings are stored

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Client-Side Layer"
        direction TB
        DocEditor["Document Editor"]:::frontend
        PhotoStorage["Photo Storage"]:::frontend
        Auth["Authentication"]:::frontend
        EncLayer["Encryption Layer"]:::security
        LocalStorage["Local Storage / IndexedDB"]:::storage
        
        subgraph "File Processing Adapters"
            direction TB
            PDFAdapter["PDF Adapter"]:::adapter
            EPUBAdapter["EPUB Adapter"]:::adapter
            MammothAdapter["Mammoth Adapter"]:::adapter
        end
        
        DocProcessing["Document Processing"]:::process
        FileUpload["File Upload Handler"]:::process
        Security["Security Manager"]:::security
        EditorUI["Editor UI"]:::frontend
        PhotoMgmt["Photo Management"]:::process
        StorageMgmt["Storage Management"]:::process
    end
    
    subgraph "API Gateway Layer"
        AuthAPI["Authentication API"]:::api
        DocAPI["Document API"]:::api
        PhotoAPI["Photo API"]:::api
        BillingAPI["Billing API"]:::api
    end
    
    subgraph "Backend Services"
        direction TB
        UserMgmt["User Management Service"]:::backend
        StorageService["Storage Service"]:::backend
        PaymentService["Payment Processing"]:::backend
        AbuseSystem["Abuse Prevention"]:::backend
    end
    
    %% Relationships
    DocEditor --> DocProcessing
    DocProcessing --> FileUpload
    PhotoStorage --> PhotoMgmt
    PhotoMgmt --> FileUpload
    FileUpload --> EncLayer
    EncLayer --> StorageMgmt
    StorageMgmt --> LocalStorage
    Auth --> AuthAPI
    
    DocProcessing --> PDFAdapter & EPUBAdapter & MammothAdapter
    
    StorageMgmt -.-> DocAPI
    StorageMgmt -.-> PhotoAPI
    Auth -.-> BillingAPI
    
    AuthAPI --> UserMgmt
    DocAPI --> StorageService
    PhotoAPI --> StorageService
    BillingAPI --> PaymentService
    
    UserMgmt --> AbuseSystem
    StorageService --> AbuseSystem
    
    %% Click Events
    click DocEditor "https://github.com/cryptee/web-client/tree/v3/source/js/docs/"
    click PhotoStorage "https://github.com/cryptee/web-client/tree/v3/source/js/photos/"
    click Auth "https://github.com/cryptee/web-client/blob/v3/source/js/auth.js"
    click EncLayer "https://github.com/cryptee/web-client/tree/v3/source/js/lib/openpgpjs/"
    click LocalStorage "https://github.com/cryptee/web-client/tree/v3/source/js/lib/dexie-4.0.4/"
    click PDFAdapter "https://github.com/cryptee/web-client/tree/v3/source/adapters/pdfjs-2.12.313/"
    click EPUBAdapter "https://github.com/cryptee/web-client/tree/v3/source/adapters/epub-reader/"
    click MammothAdapter "https://github.com/cryptee/web-client/tree/v3/source/adapters/mammoth-1.4.16/"
    click DocProcessing "https://github.com/cryptee/web-client/blob/v3/source/js/docs/adapters.js"
    click Security "https://github.com/cryptee/web-client/blob/v3/source/js/housekeeping.js"
    click EditorUI "https://github.com/cryptee/web-client/tree/v3/source/js/quill-modules/"
    click PhotoMgmt "https://github.com/cryptee/web-client/blob/v3/source/js/photos/abstractions.js"
    click StorageMgmt "https://github.com/cryptee/web-client/blob/v3/source/js/io.js"
    click FileUpload "https://github.com/cryptee/web-client/blob/v3/source/js/uploader.js"
    
    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef api fill:#2ecc71,stroke:#27ae60,color:white
    classDef backend fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef security fill:#f1c40f,stroke:#f39c12,color:black
    classDef storage fill:#e74c3c,stroke:#c0392b,color:white
    classDef process fill:#9b59b6,stroke:#8e44ad,color:white
    classDef adapter fill:#1abc9c,stroke:#16a085,color:white
    
    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        API["API Gateway"]:::api
        Backend["Backend Service"]:::backend
        SecurityComp["Security Component"]:::security
        StorageComp["Storage Component"]:::storage
        ProcessComp["Process Component"]:::process
        AdapterComp["File Adapter"]:::adapter
    end
```
