# vuxenn1/decentralized-p2p-chat-system architecture

> Architecture diagram of the GitHub repository vuxenn1/decentralized-p2p-chat-system, 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/vuxenn1/decentralized-p2p-chat-system
- Repository: https://github.com/vuxenn1/decentralized-p2p-chat-system

## Overview

This is a decentralized Go chat application with both a desktop CLI and a browser interface. Users discover or address peers, request and approve connections, then exchange encrypted messages; trusted peers and encrypted conversation histories persist locally. The graph reflects the documented identity, discovery, approval, messaging, and storage capabilities. Some runtime wiring is inferred only from the README because the Go entry-point and web excerpts are partial.

Main entry points: [`main.go`](https://github.com/vuxenn1/decentralized-p2p-chat-system/blob/main/main.go) (Stream manager), [`web.go`](https://github.com/vuxenn1/decentralized-p2p-chat-system/blob/main/web.go) (WebSocket API), [`discovery/dht.go`](https://github.com/vuxenn1/decentralized-p2p-chat-system/blob/main/discovery/dht.go) (DHT discovery), [`web/app.js`](https://github.com/vuxenn1/decentralized-p2p-chat-system/blob/main/web/app.js) (Browser UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User interfaces"]
  node_cli["Desktop CLI<br/>[main.go]"]
  node_browser["Browser UI<br/>[app.js]"]
  node_web_api["WebSocket API<br/>[web.go]"]
end

subgraph group_peer_runtime["Peer runtime"]
  node_stream_manager["Stream manager<br/>[main.go]"]
  node_dht["DHT discovery<br/>[dht.go]"]
  node_discovery_config["Discovery config<br/>[config.go]"]
  node_approval["Connection approval<br/>[main.go]"]
end

subgraph group_security["Identity and security"]
  node_e2ee["Session encryption<br/>[e2ee.go]"]
  node_identity["Persistent identity<br/>[main.go]"]
end

subgraph group_persistence["Local persistence"]
  node_history[("Encrypted history<br/>[history.go]")]
  node_trusted_peers[("Trusted peers<br/>[peers.go]")]
end

node_user(("Chat user"))
node_peer_network(("Peer network"))
node_bootstrap_peers(("Bootstrap peers"))

node_user -->|"uses commands"| node_cli
node_user -->|"uses chat UI"| node_browser
node_browser -->|"sends WebSocket events"| node_web_api
node_web_api -->|"dispatches commands"| node_stream_manager
node_cli -->|"controls sessions"| node_stream_manager
node_stream_manager -->|"loads identity"| node_identity
node_identity -->|"provides key"| node_stream_manager
node_stream_manager -->|"requests approval"| node_approval
node_user -->|"accepts or rejects"| node_approval
node_stream_manager -->|"starts discovery"| node_dht
node_web_api -->|"requests discovery"| node_dht
node_dht -->|"reads bootstrap list"| node_discovery_config
node_dht -->|"bootstraps"| node_bootstrap_peers
node_dht -->|"finds peers"| node_peer_network
node_stream_manager -->|"connects and exchanges streams"| node_peer_network
node_stream_manager -->|"encrypts and decrypts"| node_e2ee
node_web_api -->|"encrypts outgoing messages"| node_e2ee
node_stream_manager -->|"loads and saves messages"| node_history
node_web_api -->|"clears history"| node_history
node_web_api -->|"manages saved peers"| node_trusted_peers
node_web_api -->|"broadcasts state"| node_browser

click node_cli "https://github.com/vuxenn1/decentralized-p2p-chat-system/blob/main/main.go"
click node_browser "https://github.com/vuxenn1/decentralized-p2p-chat-system/blob/main/web/app.js"
click node_web_api "https://github.com/vuxenn1/decentralized-p2p-chat-system/blob/main/web.go"
click node_stream_manager "https://github.com/vuxenn1/decentralized-p2p-chat-system/blob/main/main.go"
click node_dht "https://github.com/vuxenn1/decentralized-p2p-chat-system/blob/main/discovery/dht.go"
click node_discovery_config "https://github.com/vuxenn1/decentralized-p2p-chat-system/blob/main/discovery/config.go"
click node_e2ee "https://github.com/vuxenn1/decentralized-p2p-chat-system/blob/main/security/e2ee.go"
click node_identity "https://github.com/vuxenn1/decentralized-p2p-chat-system/blob/main/main.go"
click node_approval "https://github.com/vuxenn1/decentralized-p2p-chat-system/blob/main/main.go"
click node_history "https://github.com/vuxenn1/decentralized-p2p-chat-system/blob/main/storage/history.go"
click node_trusted_peers "https://github.com/vuxenn1/decentralized-p2p-chat-system/blob/main/storage/peers.go"

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_cli,node_browser,node_web_api,node_user toneBlue
class node_stream_manager,node_dht,node_discovery_config,node_approval toneAmber
class node_e2ee,node_identity toneMint
class node_history,node_trusted_peers toneRose
class node_peer_network,node_bootstrap_peers toneIndigo
```

## Components

### User interfaces

- [Desktop CLI](https://github.com/vuxenn1/decentralized-p2p-chat-system/blob/main/main.go): `main.go`
- [Browser UI](https://github.com/vuxenn1/decentralized-p2p-chat-system/blob/main/web/app.js): `web/app.js`
- [WebSocket API](https://github.com/vuxenn1/decentralized-p2p-chat-system/blob/main/web.go): `web.go`

### Peer runtime

- [Stream manager](https://github.com/vuxenn1/decentralized-p2p-chat-system/blob/main/main.go): `main.go`
- [DHT discovery](https://github.com/vuxenn1/decentralized-p2p-chat-system/blob/main/discovery/dht.go): `discovery/dht.go`
- [Discovery config](https://github.com/vuxenn1/decentralized-p2p-chat-system/blob/main/discovery/config.go): `discovery/config.go`
- [Connection approval](https://github.com/vuxenn1/decentralized-p2p-chat-system/blob/main/main.go): `main.go`

### Identity and security

- [Session encryption](https://github.com/vuxenn1/decentralized-p2p-chat-system/blob/main/security/e2ee.go): `security/e2ee.go`
- [Persistent identity](https://github.com/vuxenn1/decentralized-p2p-chat-system/blob/main/main.go): `main.go`

### Local persistence

- [Encrypted history](https://github.com/vuxenn1/decentralized-p2p-chat-system/blob/main/storage/history.go): `storage/history.go`
- [Trusted peers](https://github.com/vuxenn1/decentralized-p2p-chat-system/blob/main/storage/peers.go): `storage/peers.go`

### Other components

- **Chat user**
- **Peer network**
- **Bootstrap peers**

## Connections

- Chat user → Desktop CLI: uses commands
- Chat user → Browser UI: uses chat UI
- Browser UI → WebSocket API: sends WebSocket events
- WebSocket API → Stream manager: dispatches commands
- Desktop CLI → Stream manager: controls sessions
- Stream manager → Persistent identity: loads identity
- Persistent identity → Stream manager: provides key
- Stream manager → Connection approval: requests approval
- Chat user → Connection approval: accepts or rejects
- Stream manager → DHT discovery: starts discovery
- WebSocket API → DHT discovery: requests discovery
- DHT discovery → Discovery config: reads bootstrap list
- DHT discovery → Bootstrap peers: bootstraps
- DHT discovery → Peer network: finds peers
- Stream manager → Peer network: connects and exchanges streams
- Stream manager → Session encryption: encrypts and decrypts
- WebSocket API → Session encryption: encrypts outgoing messages
- Stream manager → Encrypted history: loads and saves messages
- WebSocket API → Encrypted history: clears history
- WebSocket API → Trusted peers: manages saved peers
- WebSocket API → Browser UI: broadcasts state
