# hattorius/cipherdrop architecture

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

- Interactive diagram: https://gitdiagram.com/hattorius/cipherdrop
- Repository: https://github.com/hattorius/cipherdrop

## Overview

##### Main Components

a. Client-Side (Frontend)
- File Upload Interface
- Client-Side Encryption Layer
- File Download Interface

b. Backend Server (Rust)
- HTTP Server Layer
- Route Handlers
- File Processing System
- Encryption Layer

c. Storage Systems
- PostgreSQL Database
- S3 Storage (Multiple Buckets)

d. External Services
- Tor Network Integration (for .onion access)

##### Key Relationships to Highlight

a. Double Encryption Flow:
- Client-side encryption
- Server-side encryption
- Private key/nonce retention on client

b. Storage Flow:
- File upload path
- Database metadata storage
- S3 storage distribution

##### Specific Implementation Details

**[Client Browser] --> [Frontend (Static Files)]**
- index.html
- CSS/JS files
- Client-side encryption

**[Frontend] <--> [Backend Server (Rust)]**
- Routes (/upload, /download, etc.)
- File processing
- Secondary encryption

**[Backend Server] <--> [PostgreSQL Database]**
- File metadata
- S3 bucket configurations

**[Backend Server] <--> [S3 Storage]**
- Multiple buckets
- Encrypted file storage

##### Important Architectural Aspects to Emphasize

a. Security Flow:
- Client-side encryption (first layer)
- Server-side encryption (second layer)
- Key management (client-side only)

b. Data Flow:
- File upload path
- File download path
- Metadata management

c. Storage Architecture:
- Database schema (files, s3_buckets, file_to_bucket tables)
- S3 bucket distribution

##### Additional Notes

- A section showing the Docker containerization
- Separation between development and production environments
- Diesel ORM integration with PostgreSQL
- Migration system

## Diagram (Mermaid)

```mermaid
%%{init: {
  'theme': 'base',
  'themeVariables': {
    'primaryColor': '#2b2b2b',
    'primaryTextColor': '#fff',
    'primaryBorderColor': '#7C0000',
    'lineColor': '#F8B229',
    'secondaryColor': '#006100',
    'tertiaryColor': '#fff'
  }
}}%%

flowchart TB
    classDef frontend fill:#4287f5,stroke:#333,stroke-width:2px
    classDef backend fill:#2ecc71,stroke:#333,stroke-width:2px
    classDef database fill:#f1c40f,stroke:#333,stroke-width:2px
    classDef storage fill:#e67e22,stroke:#333,stroke-width:2px
    classDef security fill:#e74c3c,stroke:#333,stroke-width:2px
    classDef container fill:#8e44ad,stroke:#333,stroke-width:2px

    subgraph Client["Client Layer"]
        Browser["Web Browser"]
        UploadUI["File Upload Interface"]:::frontend
        DownloadUI["File Download Interface"]:::frontend
        ClientEncrypt["Client-Side Encryption"]:::security
    end

    subgraph Server["Server Layer"]
        direction TB
        HTTPServer["HTTP Server (Rust)"]:::backend
        RouteHandlers["Route Handlers"]:::backend
        ServerEncrypt["Server-Side Encryption"]:::security
        FileProcess["File Processing System"]:::backend
        S3Integration["S3 Integration"]:::backend
        BackgroundJobs["Background Jobs"]:::backend
    end

    subgraph Storage["Storage Layer"]
        direction TB
        DB[(PostgreSQL Database)]:::database
        S3["S3 Storage Buckets"]:::storage
    end

    subgraph Docker["Docker Environment"]
        direction TB
        ProdContainer["Production Container"]:::container
        DevContainer["Development Container"]:::container
    end

    Browser --> UploadUI
    Browser --> DownloadUI
    UploadUI --> ClientEncrypt
    ClientEncrypt --> HTTPServer
    DownloadUI --> HTTPServer
    
    HTTPServer --> RouteHandlers
    RouteHandlers --> ServerEncrypt
    RouteHandlers --> FileProcess
    FileProcess --> S3Integration
    S3Integration --> S3
    RouteHandlers --> DB
    BackgroundJobs --> S3
    BackgroundJobs --> DB

    %% Click events for component mapping
    click UploadUI "https://github.com/hattorius/cipherdrop/blob/main/frontend/index.html"
    click DownloadUI "https://github.com/hattorius/cipherdrop/blob/main/frontend/templates/file.html"
    click RouteHandlers "https://github.com/hattorius/cipherdrop/tree/main/backend/src/routes/"
    click ServerEncrypt "https://github.com/hattorius/cipherdrop/blob/main/backend/src/crypt.rs"
    click FileProcess "https://github.com/hattorius/cipherdrop/blob/main/backend/src/files.rs"
    click S3Integration "https://github.com/hattorius/cipherdrop/blob/main/backend/src/s3.rs"
    click DB "https://github.com/hattorius/cipherdrop/tree/main/backend/src/database/"
    click BackgroundJobs "https://github.com/hattorius/cipherdrop/blob/main/backend/src/jobs.rs"
    click ProdContainer "https://github.com/hattorius/cipherdrop/blob/main/compose.yml"
    click DevContainer "https://github.com/hattorius/cipherdrop/blob/main/compose-dev.yml"

    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        Backend["Backend Component"]:::backend
        DatabaseComp["Database Component"]:::database
        StorageComp["Storage Component"]:::storage
        SecurityComp["Security Component"]:::security
        ContainerComp["Container Component"]:::container
    end
```
