# 05sanjaykumar/peer-drop architecture

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

- Interactive diagram: https://gitdiagram.com/05sanjaykumar/peer-drop
- Repository: https://github.com/05sanjaykumar/peer-drop

## Overview

##### Project Type and Purpose
- From the file tree and README, PeerDrop is a full-stack, real-time P2P file-sharing and chat application.
- The frontend is a SvelteKit app running in a container; the backend is a Go-based WebSocket signaling server.
- Purpose: negotiate WebRTC peer connections, exchange encrypted chat and file data over RTCDataChannels, all end-to-end encrypted.

##### File Structure
- Top-level:
- client/ – SvelteKit UI and WebRTC logic
- server/ – Go signaling server (client.go, handler.go, main.go)
- docker-compose.yml – orchestrates both containers
- client/src/lib – encryption utilities (AES-GCM, PBKDF2), WebRTC and WebSocket wrappers
- client/src/hooks/useWebRTC.ts – encapsulates connection-lifecycle logic
- server/handler.go – WebSocket handshake & message routing for offer/answer/ICE
- Dockerfiles at client/ and server/ define container environments
- No external database; ephemeral state lives in memory or on the peers.

##### README for Additional Insights
- Architecture notes:
- WebSocket signaling over ws://localhost:8080/ws
- WebRTC data exchange peer-to-peer after handshake
- AES-GCM encryption and optional ECC identity on top of RTCDataChannel
- DevOps: built and run via docker-compose up –build
- Roadmap indicates drag-and-drop UI, identity fingerprinting, TURN support (future).

##### Detail
- Library’s role (e.g., useWebRTC hook wraps RTCPeerConnection, lib/webrtc.ts abstracts signaling).
- Where encryption sits: at the RTCDataChannel layer (AES-GCM encryption wrapper).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Orchestration: docker-compose.yml"
        direction TB
        ComposeFile["docker-compose.yml"]:::orchestration
        subgraph "Frontend Container"
            direction TB
            subgraph "Client Instances"
                PeerA["Peer A Client"]:::frontend
                PeerB["Peer B Client"]:::frontend
            end
            UIComponents["UI Components"]:::frontend
            PageRoutes["Page Routes"]:::frontend
            Hook["useWebRTC Hook"]:::frontend
            LibWebRTC["WebRTC Abstraction"]:::frontend
            WSWrapper["WebSocket Wrapper"]:::frontend
            CryptoUtils["Encryption Utilities"]:::crypto
            FDocker["Dockerfile"]:::orchestration
        end
        subgraph "Backend Container"
            direction TB
            SignalServer["Go Signaling Server"]:::backend
            MainGo["main.go"]:::backend
            HandlerGo["handler.go"]:::backend
            ClientGo["client.go"]:::backend
            BDocker["Dockerfile"]:::orchestration
        end
        STUN["STUN/TURN Servers"]:::service
    end

    PeerA -->|"ws://localhost:8080/ws"| SignalServer
    PeerB -->|"ws://localhost:8080/ws"| SignalServer
    PeerA -->|"ICE via STUN/TURN"| STUN
    PeerB -->|"ICE via STUN/TURN"| STUN
    PeerA ---|"DTLS-secured DataChannel"| PeerB

    classDef frontend fill:#D0E8FF,stroke:#1E73BE,color:#0D3B66;
    classDef backend fill:#DFFFE0,stroke:#3A9D23,color:#1B4D3E;
    classDef crypto fill:#F3E1FF,stroke:#A042A0,color:#581845;
    classDef service fill:#FFF4D1,stroke:#E29800,color:#A65F00;
    classDef orchestration fill:#E8E8E8,stroke:#A0A0A0,color:#333333;

    click PeerA "https://github.com/05sanjaykumar/peer-drop/tree/main/client/"
    click PeerB "https://github.com/05sanjaykumar/peer-drop/tree/main/client/"
    click UIComponents "https://github.com/05sanjaykumar/peer-drop/tree/main/client/src/components/"
    click PageRoutes "https://github.com/05sanjaykumar/peer-drop/tree/main/client/src/pages/"
    click Hook "https://github.com/05sanjaykumar/peer-drop/blob/main/client/src/hooks/useWebRTC.ts"
    click LibWebRTC "https://github.com/05sanjaykumar/peer-drop/blob/main/client/src/lib/webrtc.ts"
    click WSWrapper "https://github.com/05sanjaykumar/peer-drop/blob/main/client/src/lib/ws.ts"
    click CryptoUtils "https://github.com/05sanjaykumar/peer-drop/blob/main/client/src/lib/utils.ts"
    click FDocker "https://github.com/05sanjaykumar/peer-drop/tree/main/client/Dockerfile"
    click SignalServer "https://github.com/05sanjaykumar/peer-drop/tree/main/server/"
    click MainGo "https://github.com/05sanjaykumar/peer-drop/blob/main/server/main.go"
    click HandlerGo "https://github.com/05sanjaykumar/peer-drop/blob/main/server/handler.go"
    click ClientGo "https://github.com/05sanjaykumar/peer-drop/blob/main/server/client.go"
    click BDocker "https://github.com/05sanjaykumar/peer-drop/tree/main/server/Dockerfile"
    click ComposeFile "https://github.com/05sanjaykumar/peer-drop/blob/main/docker-compose.yml"
```
