# sadh114/p2p-editor architecture

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

- Interactive diagram: https://gitdiagram.com/sadh114/p2p-editor
- Repository: https://github.com/sadh114/p2p-editor

## Overview

SyncQuest is a peer-to-peer collaborative rich-text editor with a React client and a small signaling server used for peer discovery, not document storage. Users enter a room, edit shared text, and see peer presence; browser peers exchange document updates directly, while IndexedDB supports local refresh recovery. A separate awareness-based synchronization layer adds vector-clock logging, coordinator election, and a replicated hash-chain audit log. The graph follows the sampled App orchestration and hook implementations; README statements support the signaling boundary and unsampled product capabilities.

Main entry points: [`frontend/src/App.jsx`](https://github.com/sadh114/p2p-editor/blob/main/frontend/src/App.jsx) (Room app), [`frontend/src/hooks/useYjsRoom.js`](https://github.com/sadh114/p2p-editor/blob/main/frontend/src/hooks/useYjsRoom.js) (Room session), [`frontend/src/components/Editor.jsx`](https://github.com/sadh114/p2p-editor/blob/main/frontend/src/components/Editor.jsx) (Rich-text editor), [`frontend/src/hooks/useVectorClockLog.js`](https://github.com/sadh114/p2p-editor/blob/main/frontend/src/hooks/useVectorClockLog.js) (Vector clock log)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Room client"]
  node_app["Room app<br/>[App.jsx]"]
  node_identity["Peer identity<br/>[randomIdentity.js]"]
  node_editor["Rich-text editor<br/>[Editor.jsx]"]
end

subgraph group_sync["Collaboration sync"]
  node_roomhook["Room session<br/>[useYjsRoom.js]"]
  node_signaling["Peer signaling<br/>[server.js]"]
end

subgraph group_coord["Coordination features"]
  node_vectorhook["Vector clock log"]
  node_vector["Clock operations<br/>[vectorClock.js]"]
  node_election["Coordinator election"]
  node_audit["Audit log<br/>[useAuditLog.js]"]
  node_hash["Hash-chain logic<br/>[hashChain.js]"]
end

subgraph group_ui["Room interface"]
  node_presence["Presence panel<br/>[PresencePanel.jsx]"]
  node_status["Connection status"]
  node_roombar["Room sharing<br/>[RoomBar.jsx]"]
  node_quest["Quest progress<br/>[QuestProgress.jsx]"]
  node_toasts["Join notifications<br/>[useToasts.js]"]
  node_toastui["Toast display<br/>[Toasts.jsx]"]
  node_debug["Debug panel<br/>[DebugPanel.jsx]"]
  node_badge["Coordinator badge"]
  node_auditui["Audit log panel<br/>[AuditLogPanel.jsx]"]
end

node_user(("Collaborator"))
node_peer(("Other browsers"))
node_indexeddb[("Browser IndexedDB")]

node_user -->|"opens room"| node_app
node_app -->|"creates identity"| node_identity
node_app -->|"starts session"| node_roomhook
node_app -->|"renders editor"| node_editor
node_roomhook -->|"discovers peers"| node_signaling
node_roomhook -->|"syncs directly"| node_peer
node_roomhook -->|"persists locally"| node_indexeddb
node_editor -->|"edits shared document"| node_roomhook
node_app -->|"renders peers"| node_presence
node_app -->|"renders status"| node_status
node_app -->|"renders room link"| node_roombar
node_app -->|"renders progress"| node_quest
node_app -->|"tracks notifications"| node_toasts
node_toasts -->|"supplies messages"| node_toastui
node_app -->|"tracks clocks"| node_vectorhook
node_vectorhook -->|"uses clock operations"| node_vector
node_app -->|"shows diagnostics"| node_debug
node_app -->|"runs election"| node_election
node_app -->|"shows coordinator"| node_badge
node_app -->|"tracks audit chain"| node_audit
node_audit -->|"creates and verifies"| node_hash
node_app -->|"shows audit status"| node_auditui
node_auditui -->|"formats hashes"| node_hash

click node_app "https://github.com/sadh114/p2p-editor/blob/main/frontend/src/App.jsx"
click node_identity "https://github.com/sadh114/p2p-editor/blob/main/frontend/src/utils/randomIdentity.js"
click node_roomhook "https://github.com/sadh114/p2p-editor/blob/main/frontend/src/hooks/useYjsRoom.js"
click node_editor "https://github.com/sadh114/p2p-editor/blob/main/frontend/src/components/Editor.jsx"
click node_signaling "https://github.com/sadh114/p2p-editor/blob/main/signaling-server/server.js"
click node_presence "https://github.com/sadh114/p2p-editor/blob/main/frontend/src/components/PresencePanel.jsx"
click node_status "https://github.com/sadh114/p2p-editor/blob/main/frontend/src/components/ConnectionStatus.jsx"
click node_roombar "https://github.com/sadh114/p2p-editor/blob/main/frontend/src/components/RoomBar.jsx"
click node_quest "https://github.com/sadh114/p2p-editor/blob/main/frontend/src/components/QuestProgress.jsx"
click node_toasts "https://github.com/sadh114/p2p-editor/blob/main/frontend/src/hooks/useToasts.js"
click node_toastui "https://github.com/sadh114/p2p-editor/blob/main/frontend/src/components/Toasts.jsx"
click node_vectorhook "https://github.com/sadh114/p2p-editor/blob/main/frontend/src/hooks/useVectorClockLog.js"
click node_vector "https://github.com/sadh114/p2p-editor/blob/main/frontend/src/sync/vectorClock.js"
click node_debug "https://github.com/sadh114/p2p-editor/blob/main/frontend/src/components/DebugPanel.jsx"
click node_election "https://github.com/sadh114/p2p-editor/blob/main/frontend/src/hooks/useCoordinatorElection.js"
click node_badge "https://github.com/sadh114/p2p-editor/blob/main/frontend/src/components/CoordinatorBadge.jsx"
click node_audit "https://github.com/sadh114/p2p-editor/blob/main/frontend/src/hooks/useAuditLog.js"
click node_hash "https://github.com/sadh114/p2p-editor/blob/main/frontend/src/sync/hashChain.js"
click node_auditui "https://github.com/sadh114/p2p-editor/blob/main/frontend/src/components/AuditLogPanel.jsx"

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_identity,node_editor,node_peer toneBlue
class node_roomhook,node_signaling,node_indexeddb toneAmber
class node_vectorhook,node_vector,node_election,node_audit,node_hash toneMint
class node_presence,node_status,node_roombar,node_quest,node_toasts,node_toastui,node_debug,node_badge,node_auditui toneRose
class node_user toneIndigo
```

## Components

### Room client

- [Room app](https://github.com/sadh114/p2p-editor/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Peer identity](https://github.com/sadh114/p2p-editor/blob/main/frontend/src/utils/randomIdentity.js): `frontend/src/utils/randomIdentity.js`
- [Rich-text editor](https://github.com/sadh114/p2p-editor/blob/main/frontend/src/components/Editor.jsx): `frontend/src/components/Editor.jsx`

### Collaboration sync

- [Room session](https://github.com/sadh114/p2p-editor/blob/main/frontend/src/hooks/useYjsRoom.js): `frontend/src/hooks/useYjsRoom.js`
- [Peer signaling](https://github.com/sadh114/p2p-editor/blob/main/signaling-server/server.js): `signaling-server/server.js`

### Coordination features

- [Vector clock log](https://github.com/sadh114/p2p-editor/blob/main/frontend/src/hooks/useVectorClockLog.js): `frontend/src/hooks/useVectorClockLog.js`
- [Clock operations](https://github.com/sadh114/p2p-editor/blob/main/frontend/src/sync/vectorClock.js): `frontend/src/sync/vectorClock.js`
- [Coordinator election](https://github.com/sadh114/p2p-editor/blob/main/frontend/src/hooks/useCoordinatorElection.js): `frontend/src/hooks/useCoordinatorElection.js`
- [Audit log](https://github.com/sadh114/p2p-editor/blob/main/frontend/src/hooks/useAuditLog.js): `frontend/src/hooks/useAuditLog.js`
- [Hash-chain logic](https://github.com/sadh114/p2p-editor/blob/main/frontend/src/sync/hashChain.js): `frontend/src/sync/hashChain.js`

### Room interface

- [Presence panel](https://github.com/sadh114/p2p-editor/blob/main/frontend/src/components/PresencePanel.jsx): `frontend/src/components/PresencePanel.jsx`
- [Connection status](https://github.com/sadh114/p2p-editor/blob/main/frontend/src/components/ConnectionStatus.jsx): `frontend/src/components/ConnectionStatus.jsx`
- [Room sharing](https://github.com/sadh114/p2p-editor/blob/main/frontend/src/components/RoomBar.jsx): `frontend/src/components/RoomBar.jsx`
- [Quest progress](https://github.com/sadh114/p2p-editor/blob/main/frontend/src/components/QuestProgress.jsx): `frontend/src/components/QuestProgress.jsx`
- [Join notifications](https://github.com/sadh114/p2p-editor/blob/main/frontend/src/hooks/useToasts.js): `frontend/src/hooks/useToasts.js`
- [Toast display](https://github.com/sadh114/p2p-editor/blob/main/frontend/src/components/Toasts.jsx): `frontend/src/components/Toasts.jsx`
- [Debug panel](https://github.com/sadh114/p2p-editor/blob/main/frontend/src/components/DebugPanel.jsx): `frontend/src/components/DebugPanel.jsx`
- [Coordinator badge](https://github.com/sadh114/p2p-editor/blob/main/frontend/src/components/CoordinatorBadge.jsx): `frontend/src/components/CoordinatorBadge.jsx`
- [Audit log panel](https://github.com/sadh114/p2p-editor/blob/main/frontend/src/components/AuditLogPanel.jsx): `frontend/src/components/AuditLogPanel.jsx`

### Other components

- **Collaborator**
- **Other browsers**
- **Browser IndexedDB**

## Connections

- Collaborator → Room app: opens room (evidence: `README.md`)
- Room app → Peer identity: creates identity (evidence: `frontend/src/App.jsx`)
- Room app → Room session: starts session (evidence: `frontend/src/App.jsx`)
- Room app → Rich-text editor: renders editor (evidence: `frontend/src/App.jsx`)
- Room session → Peer signaling: discovers peers (evidence: `README.md`)
- Room session → Other browsers: syncs directly (evidence: `README.md`)
- Room session → Browser IndexedDB: persists locally (evidence: `frontend/src/hooks/useYjsRoom.js`)
- Rich-text editor → Room session: edits shared document (evidence: `frontend/src/components/Editor.jsx`)
- Room app → Presence panel: renders peers (evidence: `frontend/src/App.jsx`)
- Room app → Connection status: renders status (evidence: `frontend/src/App.jsx`)
- Room app → Room sharing: renders room link (evidence: `frontend/src/App.jsx`)
- Room app → Quest progress: renders progress (evidence: `frontend/src/App.jsx`)
- Room app → Join notifications: tracks notifications (evidence: `frontend/src/App.jsx`)
- Join notifications → Toast display: supplies messages (evidence: `frontend/src/App.jsx`)
- Room app → Vector clock log: tracks clocks (evidence: `frontend/src/App.jsx`)
- Vector clock log → Clock operations: uses clock operations (evidence: `frontend/src/hooks/useVectorClockLog.js`)
- Room app → Debug panel: shows diagnostics (evidence: `frontend/src/App.jsx`)
- Room app → Coordinator election: runs election (evidence: `frontend/src/App.jsx`)
- Room app → Coordinator badge: shows coordinator (evidence: `frontend/src/App.jsx`)
- Room app → Audit log: tracks audit chain (evidence: `frontend/src/App.jsx`)
- Audit log → Hash-chain logic: creates and verifies (evidence: `frontend/src/hooks/useAuditLog.js`)
- Room app → Audit log panel: shows audit status (evidence: `frontend/src/App.jsx`)
- Audit log panel → Hash-chain logic: formats hashes (evidence: `frontend/src/components/AuditLogPanel.jsx`)
