# dallen4/deadrop architecture

> Architecture diagram of the GitHub repository dallen4/deadrop, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dallen4/deadrop
- Repository: https://github.com/dallen4/deadrop

## Overview

##### Project Type and Purpose
- The project is a full-stack, end-to-end encrypted secret sharing platform.
- Its core functionality is to allow users (“droppers” and “grabbers”) to securely exchange secrets (plain text, JSON, and files) using modern cryptographic methods (AES-GCM, ECDH, and SHA-256) over peer-to-peer WebRTC connections.
- The system provides both a web app (a Progressive Web App) and a CLI interface for interacting with the platform.

##### Main Components & Their Roles
- Web Client (PWA):
- Found under the “web” directory, this part handles the user interface.
- Contains React components (atoms, molecules, organisms) and pages to interact with the API endpoints.
- Uses Next.js (notice the pages directory and next.config.mjs) to render server-side content along with client-side functionality.
- CLI Client:
- Located in the “cli” directory, it provides a command-line interface for users to drop and grab secrets.
- Implements actions (e.g., drop, grab, login, logout) along with database utilities (migrations and schema) and shared encryption logic.
- Worker (Serverless Backend/API):
- The “worker” directory contains code for a backend service likely running on Cloudflare Workers (as indicated by wrangler.toml and usage of durable objects).
- It provides core API routers (auth, drop, peers, vault) and middleware, handling key security operations (such as relaying peer IDs, sessions, and storing nonces).
- Shared Library:
- The “shared” directory is used across modules (CLI, web, worker) to segregate and centralize common functionality like crypto utilities, configuration, data structures, and test suites.
- Infrastructure & CI/CD:
- GitHub workflows in “.github/workflows” automate deployment, testing, and publishing for various parts (web, CLI, etc.).
- Configuration files (.nvmrc, .prettierrc, tsconfig.json, vercel.json) indicate the project’s tooling and build setup.
- Redis Backend:

##### Relationships and Interactions
- Users interact with the system via either the Web Client (PWA) or the CLI.
- Both clients share core business logic and cryptography by using the “shared” module.
- For secret exchanges, the Web Client or CLI initiates a “drop” action that communicates (using HTTPS requests or API calls) with the Worker API.
- The Worker handles authentication and routing (using routers such as auth.ts, drop.ts, peers.ts, vault.ts) and integrates with Redis to manage session metadata.
- Internal modules (like durable objects in Cloudflare Workers from worker/src/lib/durable_objects) help manage stateful sessions and handle real-time data.

##### Architectural Patterns & Design Principles
- Separation of Concerns: Each entry point (web, CLI, worker) serves a focused purpose but leverages common code from the “shared” module.
- Modular Design: The clearly defined directories (API routes, actions, core libraries) help illustrate the modular nature of the system.
- Service-Oriented/Microservices: Even though all parts form a cohesive whole, the backend worker can be seen as a microservice handling API requests, while frontends are decoupled.
- Secure by Design: Emphasize the end-to-end encryption (using Web Crypto API) that separates prompting, key exchange, and payload transfer from any server-side logging.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction
    U["User"]:::external

    %% Client Layer
    subgraph "Client Layer"
        WP["Web Client (PWA)"]:::client
        CLI["CLI Client"]:::client
        P2P["P2P Channel (WebRTC)"]:::client
    end

    %% Shared Module used by all layers
    SHARED["Shared Library"]:::shared

    %% Backend Layer
    subgraph "Backend Layer"
        WORKER["Worker (Serverless Backend/API)"]:::backend
        subgraph "Worker Components"
            ROUTERS["API Routers"]:::backend
            DURABLE["Durable Objects"]:::backend
        end
    end

    %% External Infrastructure
    subgraph "Infrastructure"
        REDIS["Redis Instance"]:::infrastructure
        CICD["CI/CD & Config"]:::cicd
    end

    %% Connections - User interactions
    U -->|"interacts"| WP
    U -->|"interacts"| CLI

    %% Connections - Client to Backend via API calls
    WP -->|"HTTP drop/grab"| WORKER
    CLI -->|"HTTP drop/grab"| WORKER

    %% Connections - Shared Library usage
    WP ---|"uses"| SHARED
    CLI ---|"uses"| SHARED
    WORKER ---|"uses"| SHARED

    %% Connections - Worker internal components
    WORKER -->|"routes requests"| ROUTERS
    WORKER -->|"state management"| DURABLE

    %% Connections - Worker integration with External store
    WORKER -->|"stores metadata"| REDIS

    %% Peer-to-peer communication
    WP ---|"exchanges keys via"| P2P
    P2P ---|"exchanges keys via"| WP

    %% CI/CD influences the entire project
    CICD ---|"automates deployment"| WP
    CICD ---|"automates deployment"| CLI
    CICD ---|"automates deployment"| WORKER

    %% Click Events
    click WP "https://github.com/dallen4/deadrop/tree/main/web"
    click CLI "https://github.com/dallen4/deadrop/tree/main/cli"
    click WORKER "https://github.com/dallen4/deadrop/tree/main/worker"
    click ROUTERS "https://github.com/dallen4/deadrop/tree/main/worker/src/routers"
    click DURABLE "https://github.com/dallen4/deadrop/tree/main/worker/src/lib/durable_objects"
    click SHARED "https://github.com/dallen4/deadrop/tree/main/shared"
    click CICD "https://github.com/dallen4/deadrop/tree/main/.github/workflows"

    %% Styles
    classDef client fill:#AED6F1,stroke:#000,stroke-width:2px;
    classDef backend fill:#F9E79F,stroke:#000,stroke-width:2px;
    classDef shared fill:#D5F5E3,stroke:#000,stroke-width:2px;
    classDef infrastructure fill:#F5CBA7,stroke:#000,stroke-width:2px;
    classDef external fill:#F1948A,stroke:#000,stroke-width:2px;
    classDef cicd fill:#E8DAEF,stroke:#000,stroke-width:2px;
```
