# eziomercer/web-rtc-chat architecture

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

- Interactive diagram: https://gitdiagram.com/eziomercer/web-rtc-chat
- Repository: https://github.com/eziomercer/web-rtc-chat

## Overview

web-rtc-chat is a browser-based, end-to-end encrypted peer-to-peer messenger. Its main workflow is local identity setup, contact introduction and verification, relay-assisted connection negotiation, then direct WebRTC messaging, calls, and file transfer; chats are saved encrypted on-device. The README documents the product stages and capabilities, while source excerpts and the index support the app/store wiring and selected internal dependencies. Several feature implementations were not sampled, so their links are shown only where documented, not as inferred call chains.

Main entry points: [`src/store/chat/chatSlice.ts`](https://github.com/eziomercer/web-rtc-chat/blob/master/src/store/chat/chatSlice.ts) (Chat state), [`src/store/store.ts`](https://github.com/eziomercer/web-rtc-chat/blob/master/src/store/store.ts) (App state store), [`src/core/webrtc/config.ts`](https://github.com/eziomercer/web-rtc-chat/blob/master/src/core/webrtc/config.ts) (WebRTC transport), [`src/App.tsx`](https://github.com/eziomercer/web-rtc-chat/blob/master/src/App.tsx) (App lifecycle)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["App and state"]
  node_entry["Browser entry<br/>[main.tsx]"]
  node_appflow["App lifecycle<br/>[App.tsx]"]
  node_store["App state store<br/>[store.ts]"]
  node_messenger["Messenger UI<br/>[Messenger.tsx]"]
end

subgraph group_identity["Identity and contact"]
  node_identityflow["Identity setup<br/>[setupIdentity.ts]"]
  node_identitykeys["Identity and keys"]
  node_contacts["Contacts and invites<br/>[contactsSlice.ts]"]
end

subgraph group_connection["Connection and calls"]
  node_signaling["Relay signaling"]
  node_sessionflow["Session management<br/>[sessionsSlice.ts]"]
  node_webrtc["WebRTC transport<br/>[config.ts]"]
  node_callflow["Audio and video calls<br/>[startCall.ts]"]
  node_manual["Manual connection<br/>[manualSlice.ts]"]
end

subgraph group_messaging["Messaging and sharing"]
  node_chatstate["Chat state<br/>[chatSlice.ts]"]
  node_chatui["Chat interface<br/>[ChatPane.tsx]"]
  node_recording["Voice and video notes<br/>[useRecording.ts]"]
  node_location["Location sharing"]
end

subgraph group_localdata["Local data and backup"]
  node_history[("Encrypted chat history")]
  node_storage[("Browser storage<br/>[kv.ts]")]
  node_backup["Password-locked backup<br/>[RecordType.ts]"]
end

node_person(("User"))

node_person -->|"opens app"| node_entry
node_entry -->|"renders"| node_appflow
node_appflow -->|"dispatches init"| node_store
node_appflow -->|"renders ready state"| node_messenger
node_person -->|"sets up identity"| node_identityflow
node_identityflow -->|"creates keys"| node_identitykeys
node_person -->|"adds contact"| node_contacts
node_contacts -->|"exchanges rendezvous notes"| node_signaling
node_signaling -->|"enables negotiation"| node_sessionflow
node_sessionflow -->|"establishes peer link"| node_webrtc
node_person -->|"uses manual mode"| node_manual
node_messenger -->|"manages conversations"| node_chatstate
node_chatstate -->|"sends messages and files"| node_webrtc
node_webrtc -->|"delivers peer data"| node_chatstate
node_person -->|"starts call"| node_callflow
node_callflow -->|"uses media tracks"| node_webrtc
node_person -->|"records note"| node_recording
node_recording -->|"dispatches note"| node_chatstate
node_person -->|"shares location"| node_location
node_chatstate -->|"persists encrypted chats"| node_history
node_history -->|"writes local data"| node_storage
node_person -->|"exports or restores"| node_backup
node_backup -->|"moves chat data"| node_history
node_store -->|"registers reducer"| node_chatstate
node_store -->|"registers reducer"| node_sessionflow
node_store -->|"registers reducer"| node_manual

click node_entry "https://github.com/eziomercer/web-rtc-chat/blob/master/src/main.tsx"
click node_appflow "https://github.com/eziomercer/web-rtc-chat/blob/master/src/App.tsx"
click node_store "https://github.com/eziomercer/web-rtc-chat/blob/master/src/store/store.ts"
click node_messenger "https://github.com/eziomercer/web-rtc-chat/blob/master/src/features/app/Messenger/Messenger.tsx"
click node_identityflow "https://github.com/eziomercer/web-rtc-chat/blob/master/src/store/thunks/app/setupIdentity.ts"
click node_identitykeys "https://github.com/eziomercer/web-rtc-chat/tree/master/src/core/identity"
click node_contacts "https://github.com/eziomercer/web-rtc-chat/blob/master/src/store/contacts/contactsSlice.ts"
click node_signaling "https://github.com/eziomercer/web-rtc-chat/tree/master/src/core/nostr"
click node_sessionflow "https://github.com/eziomercer/web-rtc-chat/blob/master/src/store/sessions/sessionsSlice.ts"
click node_webrtc "https://github.com/eziomercer/web-rtc-chat/blob/master/src/core/webrtc/config.ts"
click node_callflow "https://github.com/eziomercer/web-rtc-chat/blob/master/src/store/thunks/call/startCall.ts"
click node_manual "https://github.com/eziomercer/web-rtc-chat/blob/master/src/store/manual/manualSlice.ts"
click node_chatstate "https://github.com/eziomercer/web-rtc-chat/blob/master/src/store/chat/chatSlice.ts"
click node_chatui "https://github.com/eziomercer/web-rtc-chat/blob/master/src/features/chat/ChatPane/ChatPane.tsx"
click node_recording "https://github.com/eziomercer/web-rtc-chat/blob/master/src/features/recording/useRecording.ts"
click node_location "https://github.com/eziomercer/web-rtc-chat/tree/master/src/store/thunks/location"
click node_history "https://github.com/eziomercer/web-rtc-chat/tree/master/src/core/history"
click node_storage "https://github.com/eziomercer/web-rtc-chat/blob/master/src/core/storage/kv.ts"
click node_backup "https://github.com/eziomercer/web-rtc-chat/blob/master/src/core/backup/RecordType.ts"

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_entry,node_appflow,node_store,node_messenger,node_person toneBlue
class node_identityflow,node_identitykeys,node_contacts toneAmber
class node_signaling,node_sessionflow,node_webrtc,node_callflow,node_manual toneMint
class node_chatstate,node_chatui,node_recording,node_location toneRose
class node_history,node_storage,node_backup toneIndigo
```

## Components

### App and state

- [Browser entry](https://github.com/eziomercer/web-rtc-chat/blob/master/src/main.tsx): `src/main.tsx`
- [App lifecycle](https://github.com/eziomercer/web-rtc-chat/blob/master/src/App.tsx): `src/App.tsx`
- [App state store](https://github.com/eziomercer/web-rtc-chat/blob/master/src/store/store.ts): `src/store/store.ts`
- [Messenger UI](https://github.com/eziomercer/web-rtc-chat/blob/master/src/features/app/Messenger/Messenger.tsx): `src/features/app/Messenger/Messenger.tsx`

### Identity and contact

- [Identity setup](https://github.com/eziomercer/web-rtc-chat/blob/master/src/store/thunks/app/setupIdentity.ts): `src/store/thunks/app/setupIdentity.ts`
- [Identity and keys](https://github.com/eziomercer/web-rtc-chat/tree/master/src/core/identity): `src/core/identity`
- [Contacts and invites](https://github.com/eziomercer/web-rtc-chat/blob/master/src/store/contacts/contactsSlice.ts): `src/store/contacts/contactsSlice.ts`

### Connection and calls

- [Relay signaling](https://github.com/eziomercer/web-rtc-chat/tree/master/src/core/nostr): `src/core/nostr`
- [Session management](https://github.com/eziomercer/web-rtc-chat/blob/master/src/store/sessions/sessionsSlice.ts): `src/store/sessions/sessionsSlice.ts`
- [WebRTC transport](https://github.com/eziomercer/web-rtc-chat/blob/master/src/core/webrtc/config.ts): `src/core/webrtc/config.ts`
- [Audio and video calls](https://github.com/eziomercer/web-rtc-chat/blob/master/src/store/thunks/call/startCall.ts): `src/store/thunks/call/startCall.ts`
- [Manual connection](https://github.com/eziomercer/web-rtc-chat/blob/master/src/store/manual/manualSlice.ts): `src/store/manual/manualSlice.ts`

### Messaging and sharing

- [Chat state](https://github.com/eziomercer/web-rtc-chat/blob/master/src/store/chat/chatSlice.ts): `src/store/chat/chatSlice.ts`
- [Chat interface](https://github.com/eziomercer/web-rtc-chat/blob/master/src/features/chat/ChatPane/ChatPane.tsx): `src/features/chat/ChatPane/ChatPane.tsx`
- [Voice and video notes](https://github.com/eziomercer/web-rtc-chat/blob/master/src/features/recording/useRecording.ts): `src/features/recording/useRecording.ts`
- [Location sharing](https://github.com/eziomercer/web-rtc-chat/tree/master/src/store/thunks/location): `src/store/thunks/location`

### Local data and backup

- [Encrypted chat history](https://github.com/eziomercer/web-rtc-chat/tree/master/src/core/history): `src/core/history`
- [Browser storage](https://github.com/eziomercer/web-rtc-chat/blob/master/src/core/storage/kv.ts): `src/core/storage/kv.ts`
- [Password-locked backup](https://github.com/eziomercer/web-rtc-chat/blob/master/src/core/backup/RecordType.ts): `src/core/backup/RecordType.ts`

### Other components

- **User**

## Connections

- User → Browser entry: opens app
- Browser entry → App lifecycle: renders (evidence: `src/main.tsx`)
- App lifecycle → App state store: dispatches init (evidence: `src/App.tsx`)
- App lifecycle → Messenger UI: renders ready state (evidence: `src/App.tsx`)
- User → Identity setup: sets up identity
- Identity setup → Identity and keys: creates keys
- User → Contacts and invites: adds contact
- Contacts and invites → Relay signaling: exchanges rendezvous notes
- Relay signaling → Session management: enables negotiation
- Session management → WebRTC transport: establishes peer link
- User → Manual connection: uses manual mode
- Messenger UI → Chat state: manages conversations
- Chat state → WebRTC transport: sends messages and files (evidence: `src/store/chat/chatSlice.ts`)
- WebRTC transport → Chat state: delivers peer data (evidence: `src/store/chat/chatSlice.ts`)
- User → Audio and video calls: starts call
- Audio and video calls → WebRTC transport: uses media tracks
- User → Voice and video notes: records note (evidence: `src/features/recording/useRecording.ts`)
- Voice and video notes → Chat state: dispatches note (evidence: `src/features/recording/useRecording.ts`)
- User → Location sharing: shares location
- Chat state → Encrypted chat history: persists encrypted chats
- Encrypted chat history → Browser storage: writes local data
- User → Password-locked backup: exports or restores
- Password-locked backup → Encrypted chat history: moves chat data
- App state store → Chat state: registers reducer (evidence: `src/store/store.ts`)
- App state store → Session management: registers reducer (evidence: `src/store/store.ts`)
- App state store → Manual connection: registers reducer (evidence: `src/store/store.ts`)
