# ishandhull2953/p2p-file-sharing architecture

> Architecture diagram of the GitHub repository ishandhull2953/p2p-file-sharing, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ishandhull2953/p2p-file-sharing
- Repository: https://github.com/ishandhull2953/p2p-file-sharing

## Overview

P2P Mesh lets browser peers select a file and destination, find a route through the live topology, then send chunks directly over WebRTC data channels; intermediate peers relay chunks and the receiver reassembles and verifies the file. The Express/Socket.IO server registers peers, proposes links, exchanges WebRTC signaling, and broadcasts topology, but does not carry file data. The README also documents churn, connectivity and MST views, routing choices, and optional TURN credentials. Architecture links follow the sampled code and README; several UI and transfer details are documented but their complete implementations were not sampled.

Main entry points: [`frontend/js/app.js`](https://github.com/ishandhull2953/p2p-file-sharing/blob/main/frontend/js/app.js) (Browser UI), [`server/server.js`](https://github.com/ishandhull2953/p2p-file-sharing/blob/main/server/server.js) (HTTP and Socket.IO), [`frontend/js/transfer.js`](https://github.com/ishandhull2953/p2p-file-sharing/blob/main/frontend/js/transfer.js) (Transfer manager), [`frontend/js/algorithms.js`](https://github.com/ishandhull2953/p2p-file-sharing/blob/main/frontend/js/algorithms.js) (Routing algorithms)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_server["Signaling server"]
  node_serverapp["HTTP and Socket.IO<br/>[server.js]"]
  node_serverstate[("Topology state<br/>[server.js]")]
end

subgraph group_browser["Peer browser"]
  node_ui["Browser UI<br/>[app.js]"]
  node_socket["Socket client<br/>[app.js]"]
end

subgraph group_routing["Topology and routing"]
  node_graph["Peer graph<br/>[graph.js]"]
  node_algorithms["Routing algorithms<br/>[algorithms.js]"]
end

subgraph group_transfer["WebRTC transfer"]
  node_transfer["Transfer manager<br/>[transfer.js]"]
  node_webrtc["Peer data channels<br/>[transfer.js]"]
end

node_user(("Peer user"))
node_turn["Metered TURN"]
node_peer(("Remote peers"))
node_file["Selected file"]
node_download["Received file"]

node_user -->|"selects and sends"| node_ui
node_file -->|"selects"| node_ui
node_ui -->|"connects and signals"| node_socket
node_socket -->|"Socket.IO events"| node_serverapp
node_serverapp -->|"registers and updates"| node_serverstate
node_serverapp -->|"initializes and broadcasts"| node_socket
node_serverapp -->|"relays signaling"| node_peer
node_serverapp -.->|"fetches credentials"| node_turn
node_serverapp -->|"provides ICE servers"| node_socket
node_ui -->|"syncs topology"| node_graph
node_ui -->|"creates and directs"| node_transfer
node_ui -->|"computes route and MST"| node_algorithms
node_transfer -->|"finds transfer route"| node_algorithms
node_transfer -->|"exchanges signaling and latency"| node_socket
node_transfer -->|"opens peer connections"| node_webrtc
node_webrtc -->|"exchanges chunks directly"| node_peer
node_webrtc -->|"delivers received chunks"| node_transfer
node_transfer -->|"reports progress and completion"| node_ui
node_ui -->|"offers completed file"| node_download

click node_serverapp "https://github.com/ishandhull2953/p2p-file-sharing/blob/main/server/server.js"
click node_serverstate "https://github.com/ishandhull2953/p2p-file-sharing/blob/main/server/server.js"
click node_ui "https://github.com/ishandhull2953/p2p-file-sharing/blob/main/frontend/js/app.js"
click node_socket "https://github.com/ishandhull2953/p2p-file-sharing/blob/main/frontend/js/app.js"
click node_graph "https://github.com/ishandhull2953/p2p-file-sharing/blob/main/frontend/js/graph.js"
click node_algorithms "https://github.com/ishandhull2953/p2p-file-sharing/blob/main/frontend/js/algorithms.js"
click node_transfer "https://github.com/ishandhull2953/p2p-file-sharing/blob/main/frontend/js/transfer.js"
click node_webrtc "https://github.com/ishandhull2953/p2p-file-sharing/blob/main/frontend/js/transfer.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_serverapp,node_serverstate,node_user toneBlue
class node_ui,node_socket toneAmber
class node_graph,node_algorithms toneMint
class node_transfer,node_webrtc toneRose
class node_turn,node_peer,node_file,node_download toneIndigo
```

## Components

### Signaling server

- [HTTP and Socket.IO](https://github.com/ishandhull2953/p2p-file-sharing/blob/main/server/server.js): `server/server.js`
- [Topology state](https://github.com/ishandhull2953/p2p-file-sharing/blob/main/server/server.js): `server/server.js`

### Peer browser

- [Browser UI](https://github.com/ishandhull2953/p2p-file-sharing/blob/main/frontend/js/app.js): `frontend/js/app.js`
- [Socket client](https://github.com/ishandhull2953/p2p-file-sharing/blob/main/frontend/js/app.js): `frontend/js/app.js`

### Topology and routing

- [Peer graph](https://github.com/ishandhull2953/p2p-file-sharing/blob/main/frontend/js/graph.js): `frontend/js/graph.js`
- [Routing algorithms](https://github.com/ishandhull2953/p2p-file-sharing/blob/main/frontend/js/algorithms.js): `frontend/js/algorithms.js`

### WebRTC transfer

- [Transfer manager](https://github.com/ishandhull2953/p2p-file-sharing/blob/main/frontend/js/transfer.js): `frontend/js/transfer.js`
- [Peer data channels](https://github.com/ishandhull2953/p2p-file-sharing/blob/main/frontend/js/transfer.js): `frontend/js/transfer.js`

### Other components

- **Peer user**
- **Metered TURN**
- **Remote peers**
- **Selected file**
- **Received file**

## Connections

- Peer user → Browser UI: selects and sends
- Selected file → Browser UI: selects
- Browser UI → Socket client: connects and signals
- Socket client → HTTP and Socket.IO: Socket.IO events
- HTTP and Socket.IO → Topology state: registers and updates
- HTTP and Socket.IO → Socket client: initializes and broadcasts
- HTTP and Socket.IO → Remote peers: relays signaling
- HTTP and Socket.IO → Metered TURN: fetches credentials
- HTTP and Socket.IO → Socket client: provides ICE servers
- Browser UI → Peer graph: syncs topology
- Browser UI → Transfer manager: creates and directs
- Browser UI → Routing algorithms: computes route and MST
- Transfer manager → Routing algorithms: finds transfer route
- Transfer manager → Socket client: exchanges signaling and latency
- Transfer manager → Peer data channels: opens peer connections
- Peer data channels → Remote peers: exchanges chunks directly
- Peer data channels → Transfer manager: delivers received chunks
- Transfer manager → Browser UI: reports progress and completion
- Browser UI → Received file: offers completed file
