# codevdtanmay/git-zeronet architecture

> Architecture diagram of the GitHub repository codevdtanmay/git-zeronet, 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/codevdtanmay/git-zeronet
- Repository: https://github.com/codevdtanmay/git-zeronet

## Overview

Zeronet lets people on one local network find devices, request and accept peer connections, then chat and transfer files directly. The lobby’s discovery flow finds a server; Socket.IO maintains the online-device list and relays connection decisions and WebRTC signaling. Once a data channel opens, chat messages and chunked files travel peer-to-peer, with received files reassembled for download. The README documents discovery scanning and file-transfer behavior; those details are represented at the documented module level where implementation excerpts were not provided.

Main entry points: [`frontend/src/context/PeerContext.jsx`](https://github.com/codevdtanmay/git-zeronet/blob/main/frontend/src/context/PeerContext.jsx) (Peer context), [`frontend/src/hooks/useChat.js`](https://github.com/codevdtanmay/git-zeronet/blob/main/frontend/src/hooks/useChat.js) (Chat and transfer), [`backend/sockets/signaling.js`](https://github.com/codevdtanmay/git-zeronet/blob/main/backend/sockets/signaling.js) (Socket signaling), [`frontend/src/context/SocketContext.jsx`](https://github.com/codevdtanmay/git-zeronet/blob/main/frontend/src/context/SocketContext.jsx) (Socket context)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_discovery["LAN discovery"]
  node_lobby["Lobby<br/>[Lobby.jsx]"]
  node_discoveryctx["Discovery context"]
  node_discoveryutil["Server scanning<br/>[discovery.js]"]
  node_deviceui["Device list<br/>[DeviceList.jsx]"]
end

subgraph group_backend["Server services"]
  node_api["Discovery API<br/>[api.js]"]
  node_bonjour["Bonjour advertiser<br/>[bonjour.js]"]
  node_server["HTTP server<br/>[server.js]"]
  node_signaling["Socket signaling<br/>[signaling.js]"]
end

subgraph group_connection["Peer connection"]
  node_socketctx["Socket context<br/>[SocketContext.jsx]"]
  node_peerctx["Peer context<br/>[PeerContext.jsx]"]
  node_connectionui["Connection prompt"]
  node_datachannel["WebRTC data channel"]
end

subgraph group_chat["Chat and files"]
  node_chatpage["Chat page<br/>[Chat.jsx]"]
  node_chatwindow["Chat window<br/>[ChatWindow.jsx]"]
  node_chatlogic["Chat and transfer<br/>[useChat.js]"]
  node_chunks["File chunking<br/>[fileChunks.js]"]
end

node_user(("Device user"))
node_peerdevice(("Other LAN device"))
node_stun["Optional STUN"]

node_user -->|"opens"| node_lobby
node_lobby -->|"starts scan"| node_discoveryctx
node_discoveryctx -->|"scans LAN"| node_discoveryutil
node_discoveryutil -->|"requests info"| node_api
node_lobby -->|"shows devices"| node_deviceui
node_deviceui -->|"requests connection"| node_socketctx
node_server -->|"mounts routes"| node_api
node_server -->|"sets up"| node_signaling
node_server -->|"advertises server"| node_bonjour
node_socketctx -->|"registers and lists"| node_signaling
node_signaling -->|"sends device events"| node_socketctx
node_socketctx -->|"provides socket"| node_peerctx
node_signaling -->|"relays signaling"| node_peerctx
node_peerdevice -->|"requests connection"| node_connectionui
node_connectionui -->|"accepts or rejects"| node_peerctx
node_peerctx -->|"creates connection"| node_datachannel
node_datachannel -->|"connects directly"| node_peerdevice
node_peerctx -.->|"uses for ICE"| node_stun
node_user -->|"opens chat"| node_chatpage
node_chatpage -->|"renders"| node_chatwindow
node_chatwindow -->|"sends and receives"| node_chatlogic
node_chatlogic -->|"sends and handles data"| node_peerctx
node_chatlogic -->|"reads file chunks"| node_chunks
node_chatlogic -->|"transfers messages and files"| node_datachannel

click node_lobby "https://github.com/codevdtanmay/git-zeronet/blob/main/frontend/src/pages/Lobby.jsx"
click node_discoveryctx "https://github.com/codevdtanmay/git-zeronet/blob/main/frontend/src/context/DiscoveryContext.jsx"
click node_discoveryutil "https://github.com/codevdtanmay/git-zeronet/blob/main/frontend/src/utils/discovery.js"
click node_api "https://github.com/codevdtanmay/git-zeronet/blob/main/backend/routes/api.js"
click node_bonjour "https://github.com/codevdtanmay/git-zeronet/blob/main/backend/services/bonjour.js"
click node_server "https://github.com/codevdtanmay/git-zeronet/blob/main/backend/server.js"
click node_signaling "https://github.com/codevdtanmay/git-zeronet/blob/main/backend/sockets/signaling.js"
click node_socketctx "https://github.com/codevdtanmay/git-zeronet/blob/main/frontend/src/context/SocketContext.jsx"
click node_peerctx "https://github.com/codevdtanmay/git-zeronet/blob/main/frontend/src/context/PeerContext.jsx"
click node_connectionui "https://github.com/codevdtanmay/git-zeronet/blob/main/frontend/src/components/ConnectionModal.jsx"
click node_deviceui "https://github.com/codevdtanmay/git-zeronet/blob/main/frontend/src/components/DeviceList.jsx"
click node_chatpage "https://github.com/codevdtanmay/git-zeronet/blob/main/frontend/src/pages/Chat.jsx"
click node_chatwindow "https://github.com/codevdtanmay/git-zeronet/blob/main/frontend/src/components/ChatWindow.jsx"
click node_chatlogic "https://github.com/codevdtanmay/git-zeronet/blob/main/frontend/src/hooks/useChat.js"
click node_chunks "https://github.com/codevdtanmay/git-zeronet/blob/main/frontend/src/utils/fileChunks.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_lobby,node_discoveryctx,node_discoveryutil,node_deviceui,node_user toneBlue
class node_api,node_bonjour,node_server,node_signaling toneAmber
class node_socketctx,node_peerctx,node_connectionui,node_datachannel toneMint
class node_chatpage,node_chatwindow,node_chatlogic,node_chunks toneRose
class node_peerdevice,node_stun toneIndigo
```

## Components

### LAN discovery

- [Lobby](https://github.com/codevdtanmay/git-zeronet/blob/main/frontend/src/pages/Lobby.jsx): `frontend/src/pages/Lobby.jsx`
- [Discovery context](https://github.com/codevdtanmay/git-zeronet/blob/main/frontend/src/context/DiscoveryContext.jsx): `frontend/src/context/DiscoveryContext.jsx`
- [Server scanning](https://github.com/codevdtanmay/git-zeronet/blob/main/frontend/src/utils/discovery.js): `frontend/src/utils/discovery.js`
- [Device list](https://github.com/codevdtanmay/git-zeronet/blob/main/frontend/src/components/DeviceList.jsx): `frontend/src/components/DeviceList.jsx`

### Server services

- [Discovery API](https://github.com/codevdtanmay/git-zeronet/blob/main/backend/routes/api.js): `backend/routes/api.js`
- [Bonjour advertiser](https://github.com/codevdtanmay/git-zeronet/blob/main/backend/services/bonjour.js): `backend/services/bonjour.js`
- [HTTP server](https://github.com/codevdtanmay/git-zeronet/blob/main/backend/server.js): `backend/server.js`
- [Socket signaling](https://github.com/codevdtanmay/git-zeronet/blob/main/backend/sockets/signaling.js): `backend/sockets/signaling.js`

### Peer connection

- [Socket context](https://github.com/codevdtanmay/git-zeronet/blob/main/frontend/src/context/SocketContext.jsx): `frontend/src/context/SocketContext.jsx`
- [Peer context](https://github.com/codevdtanmay/git-zeronet/blob/main/frontend/src/context/PeerContext.jsx): `frontend/src/context/PeerContext.jsx`
- [Connection prompt](https://github.com/codevdtanmay/git-zeronet/blob/main/frontend/src/components/ConnectionModal.jsx): `frontend/src/components/ConnectionModal.jsx`
- **WebRTC data channel**

### Chat and files

- [Chat page](https://github.com/codevdtanmay/git-zeronet/blob/main/frontend/src/pages/Chat.jsx): `frontend/src/pages/Chat.jsx`
- [Chat window](https://github.com/codevdtanmay/git-zeronet/blob/main/frontend/src/components/ChatWindow.jsx): `frontend/src/components/ChatWindow.jsx`
- [Chat and transfer](https://github.com/codevdtanmay/git-zeronet/blob/main/frontend/src/hooks/useChat.js): `frontend/src/hooks/useChat.js`
- [File chunking](https://github.com/codevdtanmay/git-zeronet/blob/main/frontend/src/utils/fileChunks.js): `frontend/src/utils/fileChunks.js`

### Other components

- **Device user**
- **Other LAN device**
- **Optional STUN**

## Connections

- Device user → Lobby: opens
- Lobby → Discovery context: starts scan
- Discovery context → Server scanning: scans LAN
- Server scanning → Discovery API: requests info
- Lobby → Device list: shows devices
- Device list → Socket context: requests connection
- HTTP server → Discovery API: mounts routes
- HTTP server → Socket signaling: sets up
- HTTP server → Bonjour advertiser: advertises server
- Socket context → Socket signaling: registers and lists
- Socket signaling → Socket context: sends device events
- Socket context → Peer context: provides socket
- Socket signaling → Peer context: relays signaling
- Other LAN device → Connection prompt: requests connection
- Connection prompt → Peer context: accepts or rejects
- Peer context → WebRTC data channel: creates connection
- WebRTC data channel → Other LAN device: connects directly
- Peer context → Optional STUN: uses for ICE
- Device user → Chat page: opens chat
- Chat page → Chat window: renders
- Chat window → Chat and transfer: sends and receives
- Chat and transfer → Peer context: sends and handles data
- Chat and transfer → File chunking: reads file chunks
- Chat and transfer → WebRTC data channel: transfers messages and files
