# ronituohino/p2p-chat architecture

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

- Interactive diagram: https://gitdiagram.com/ronituohino/p2p-chat
- Repository: https://github.com/ronituohino/p2p-chat

## Overview

p2p-chat is a peer-to-peer group-chat application. A user adds a Node Discovery Service (NDS), browses or creates a network, joins through its leader, and sends messages that peers broadcast and synchronize using logical clocks. Leaders are elected among peers; heartbeats support failure detection, while the NDS tracks group leaders. The graph preserves the documented runtime capabilities and sampled client, UI, and NDS flow. Several service modules are represented from the source index and README; their internal call paths were not sampled, so those connections are omitted unless documented.

Main entry points: [`client/service/server.py`](https://github.com/ronituohino/p2p-chat/blob/main/client/service/server.py) (Peer RPC service), [`client/ui/ui.py`](https://github.com/ronituohino/p2p-chat/blob/main/client/ui/ui.py) (Chat application), [`main.py`](https://github.com/ronituohino/p2p-chat/blob/main/main.py) (Networking adapter), [`client/ui/Networks/main.py`](https://github.com/ronituohino/p2p-chat/blob/main/client/ui/Networks/main.py) (Network browser)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Chat interface"]
  node_app["Chat application<br/>[ui.py]"]
  node_networks["Network browser<br/>[main.py]"]
  node_addsource["Add discovery source"]
  node_creategroup["Create group form<br/>[create_group.py]"]
  node_chat["Chat panel<br/>[main.py]"]
end

subgraph group_client["Peer client"]
  node_entry["Client entry<br/>[main.py]"]
  node_networking["Networking adapter<br/>[main.py]"]
  node_peer["Peer RPC service<br/>[server.py]"]
  node_election["Leader election<br/>[leader_election.py]"]
  node_heartbeat["Heartbeat monitor<br/>[heartbeat.py]"]
  node_overseer["Peer overseer<br/>[overseer.py]"]
  node_messaging["Message broadcasting<br/>[messaging.py]"]
  node_sync["Logical-clock sync<br/>[synchronization.py]"]
  node_state["Peer state<br/>[state.py]"]
  node_crawler["Discovery crawler<br/>[crawler.py]"]
end

subgraph group_discovery["Network discovery"]
  node_nds["Node Discovery Service<br/>[nds.py]"]
end

subgraph group_models["Protocol data"]
  node_groupmodel["Group and message models<br/>[client.py]"]
  node_ndsmodel["Discovery group models<br/>[nds.py]"]
  node_response["Generic response model<br/>[generic.py]"]
end

node_user(("User"))

node_user -->|"uses"| node_app
node_entry -->|"starts"| node_app
node_entry -->|"creates"| node_networking
node_app -->|"composes"| node_networks
node_app -->|"composes"| node_chat
node_app -->|"opens"| node_addsource
node_app -->|"opens"| node_creategroup
node_app -->|"starts"| node_peer
node_chat -->|"sends messages"| node_networking
node_networks -->|"joins groups"| node_networking
node_addsource -->|"adds source"| node_networking
node_creategroup -->|"creates group"| node_networking
node_networking -->|"invokes services"| node_peer
node_peer -->|"contacts NDS"| node_nds
node_peer -->|"dispatches election"| node_election
node_peer -->|"handles heartbeats"| node_heartbeat
node_peer -->|"broadcasts messages"| node_messaging
node_peer -->|"synchronizes messages"| node_sync
node_peer -->|"uses state"| node_state
node_peer -->|"starts crawler"| node_crawler
node_election -->|"starts monitoring"| node_overseer
node_election -->|"synchronizes peers"| node_sync
node_nds -->|"uses models"| node_ndsmodel
node_nds -->|"uses response"| node_response
node_peer -->|"uses models"| node_groupmodel
node_peer -->|"uses discovery models"| node_ndsmodel
node_networks -->|"displays groups"| node_groupmodel
node_networks -->|"browses groups"| node_ndsmodel
node_sync -->|"uses message models"| node_groupmodel
node_election -->|"uses response model"| node_groupmodel

click node_entry "https://github.com/ronituohino/p2p-chat/blob/main/main.py"
click node_app "https://github.com/ronituohino/p2p-chat/blob/main/client/ui/ui.py"
click node_networks "https://github.com/ronituohino/p2p-chat/blob/main/client/ui/Networks/main.py"
click node_addsource "https://github.com/ronituohino/p2p-chat/blob/main/client/ui/Networks/add_discovery_source.py"
click node_creategroup "https://github.com/ronituohino/p2p-chat/blob/main/client/ui/Networks/create_group.py"
click node_chat "https://github.com/ronituohino/p2p-chat/blob/main/client/ui/Chat/main.py"
click node_networking "https://github.com/ronituohino/p2p-chat/blob/main/main.py"
click node_peer "https://github.com/ronituohino/p2p-chat/blob/main/client/service/server.py"
click node_election "https://github.com/ronituohino/p2p-chat/blob/main/client/service/leader_election.py"
click node_heartbeat "https://github.com/ronituohino/p2p-chat/blob/main/client/service/heartbeat.py"
click node_overseer "https://github.com/ronituohino/p2p-chat/blob/main/client/service/overseer.py"
click node_messaging "https://github.com/ronituohino/p2p-chat/blob/main/client/service/messaging.py"
click node_sync "https://github.com/ronituohino/p2p-chat/blob/main/client/service/synchronization.py"
click node_state "https://github.com/ronituohino/p2p-chat/blob/main/client/service/state.py"
click node_crawler "https://github.com/ronituohino/p2p-chat/blob/main/client/service/crawler.py"
click node_nds "https://github.com/ronituohino/p2p-chat/blob/main/client/nds/nds.py"
click node_groupmodel "https://github.com/ronituohino/p2p-chat/blob/main/client/structs/client.py"
click node_ndsmodel "https://github.com/ronituohino/p2p-chat/blob/main/client/structs/nds.py"
click node_response "https://github.com/ronituohino/p2p-chat/blob/main/client/structs/generic.py"

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_app,node_networks,node_addsource,node_creategroup,node_chat,node_user toneBlue
class node_entry,node_networking,node_peer,node_election,node_heartbeat,node_overseer,node_messaging,node_sync,node_state,node_crawler toneAmber
class node_nds toneMint
class node_groupmodel,node_ndsmodel,node_response toneRose
```

## Components

### Chat interface

- [Chat application](https://github.com/ronituohino/p2p-chat/blob/main/client/ui/ui.py): `client/ui/ui.py`
- [Network browser](https://github.com/ronituohino/p2p-chat/blob/main/client/ui/Networks/main.py): `client/ui/Networks/main.py`
- [Add discovery source](https://github.com/ronituohino/p2p-chat/blob/main/client/ui/Networks/add_discovery_source.py): `client/ui/Networks/add_discovery_source.py`
- [Create group form](https://github.com/ronituohino/p2p-chat/blob/main/client/ui/Networks/create_group.py): `client/ui/Networks/create_group.py`
- [Chat panel](https://github.com/ronituohino/p2p-chat/blob/main/client/ui/Chat/main.py): `client/ui/Chat/main.py`

### Peer client

- [Client entry](https://github.com/ronituohino/p2p-chat/blob/main/main.py): `main.py`
- [Networking adapter](https://github.com/ronituohino/p2p-chat/blob/main/main.py): `main.py`
- [Peer RPC service](https://github.com/ronituohino/p2p-chat/blob/main/client/service/server.py): `client/service/server.py`
- [Leader election](https://github.com/ronituohino/p2p-chat/blob/main/client/service/leader_election.py): `client/service/leader_election.py`
- [Heartbeat monitor](https://github.com/ronituohino/p2p-chat/blob/main/client/service/heartbeat.py): `client/service/heartbeat.py`
- [Peer overseer](https://github.com/ronituohino/p2p-chat/blob/main/client/service/overseer.py): `client/service/overseer.py`
- [Message broadcasting](https://github.com/ronituohino/p2p-chat/blob/main/client/service/messaging.py): `client/service/messaging.py`
- [Logical-clock sync](https://github.com/ronituohino/p2p-chat/blob/main/client/service/synchronization.py): `client/service/synchronization.py`
- [Peer state](https://github.com/ronituohino/p2p-chat/blob/main/client/service/state.py): `client/service/state.py`
- [Discovery crawler](https://github.com/ronituohino/p2p-chat/blob/main/client/service/crawler.py): `client/service/crawler.py`

### Network discovery

- [Node Discovery Service](https://github.com/ronituohino/p2p-chat/blob/main/client/nds/nds.py): `client/nds/nds.py`

### Protocol data

- [Group and message models](https://github.com/ronituohino/p2p-chat/blob/main/client/structs/client.py): `client/structs/client.py`
- [Discovery group models](https://github.com/ronituohino/p2p-chat/blob/main/client/structs/nds.py): `client/structs/nds.py`
- [Generic response model](https://github.com/ronituohino/p2p-chat/blob/main/client/structs/generic.py): `client/structs/generic.py`

### Other components

- **User**

## Connections

- User → Chat application: uses (evidence: `README.md`)
- Client entry → Chat application: starts (evidence: `main.py`)
- Client entry → Networking adapter: creates (evidence: `main.py`)
- Chat application → Network browser: composes (evidence: `client/ui/ui.py`)
- Chat application → Chat panel: composes (evidence: `client/ui/ui.py`)
- Chat application → Add discovery source: opens (evidence: `client/ui/ui.py`)
- Chat application → Create group form: opens (evidence: `client/ui/ui.py`)
- Chat application → Peer RPC service: starts (evidence: `client/ui/ui.py`)
- Chat panel → Networking adapter: sends messages (evidence: `client/ui/Chat/main.py`)
- Network browser → Networking adapter: joins groups (evidence: `client/ui/Networks/main.py`)
- Add discovery source → Networking adapter: adds source (evidence: `README.md`)
- Create group form → Networking adapter: creates group (evidence: `README.md`)
- Networking adapter → Peer RPC service: invokes services (evidence: `main.py`)
- Peer RPC service → Node Discovery Service: contacts NDS (evidence: `client/service/server.py`)
- Peer RPC service → Leader election: dispatches election (evidence: `client/service/server.py`)
- Peer RPC service → Heartbeat monitor: handles heartbeats (evidence: `client/service/server.py`)
- Peer RPC service → Message broadcasting: broadcasts messages (evidence: `client/service/server.py`)
- Peer RPC service → Logical-clock sync: synchronizes messages (evidence: `client/service/server.py`)
- Peer RPC service → Peer state: uses state (evidence: `client/service/server.py`)
- Peer RPC service → Discovery crawler: starts crawler (evidence: `client/service/server.py`)
- Leader election → Peer overseer: starts monitoring (evidence: `client/service/leader_election.py`)
- Leader election → Logical-clock sync: synchronizes peers (evidence: `client/service/leader_election.py`)
- Node Discovery Service → Discovery group models: uses models (evidence: `client/nds/nds.py`)
- Node Discovery Service → Generic response model: uses response (evidence: `client/nds/nds.py`)
- Peer RPC service → Group and message models: uses models (evidence: `client/service/server.py`)
- Peer RPC service → Discovery group models: uses discovery models (evidence: `client/service/server.py`)
- Network browser → Group and message models: displays groups (evidence: `client/ui/Networks/main.py`)
- Network browser → Discovery group models: browses groups (evidence: `client/ui/Networks/main.py`)
- Logical-clock sync → Group and message models: uses message models (evidence: `client/service/synchronization.py`)
- Leader election → Group and message models: uses response model (evidence: `client/service/leader_election.py`)
