# swadesh-c0de/dchat architecture

> Architecture diagram of the GitHub repository swadesh-c0de/dchat, 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/swadesh-c0de/dchat
- Repository: https://github.com/swadesh-c0de/dchat

## Overview

dChat is a wallet-based decentralized communications app. A user connects a wallet, the chat page initializes an XMTP client, and the chat experience supports encrypted conversations, real-time message synchronization, peer-to-peer calls, and encrypted IPFS attachments. The README documents profiles and message revocation as additional capabilities. Some wiring and subsystem implementations were not included in the sampled source, so links to those are limited to documented capabilities and visible codec registration.

Main entry points: [`src/hooks/useWebRTC.ts`](https://github.com/swadesh-c0de/dchat/blob/main/src/hooks/useWebRTC.ts) (WebRTC call state), [`src/lib/xmtp/messages.ts`](https://github.com/swadesh-c0de/dchat/blob/main/src/lib/xmtp/messages.ts) (Message operations), [`src/lib/xmtp/client.ts`](https://github.com/swadesh-c0de/dchat/blob/main/src/lib/xmtp/client.ts) (XMTP client), [`src/components/chat/ChatWindow.tsx`](https://github.com/swadesh-c0de/dchat/blob/main/src/components/chat/ChatWindow.tsx) (Conversation view)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client Experience"]
  node_chatpage["Chat entry<br/>[page.tsx]"]
  node_chatlayout["Chat workspace<br/>[ChatLayout.tsx]"]
  node_chatwindow["Conversation view<br/>[ChatWindow.tsx]"]
  node_sidebar["Conversation list<br/>[ChatSidebar.tsx]"]
  node_messageui["Message composer<br/>[MessageInput.tsx]"]
end

subgraph group_messaging["XMTP Messaging"]
  node_xmtpclient["XMTP client<br/>[client.ts]"]
  node_conversations["Conversation operations<br/>[conversations.ts]"]
  node_messages["Message operations<br/>[messages.ts]"]
  node_sync["Message synchronization<br/>[useMessagesSync.ts]"]
  node_display["Conversation display"]
end

subgraph group_calls["Peer Calls"]
  node_webrtc["WebRTC call state<br/>[useWebRTC.ts]"]
  node_callui["Call controls<br/>[VideoCallModal.tsx]"]
  node_incoming["Incoming call prompt"]
  node_turn["ICE configuration<br/>[route.ts]"]
  node_callcodec["Call codec<br/>[CallCodec.ts]"]
end

subgraph group_attachments["Encrypted Attachments"]
  node_ipfs["Attachment handling<br/>[ipfs.ts]"]
end

subgraph group_identity["Profiles and Revocation"]
  node_profilecodec["Profile codec<br/>[ProfileCodec.ts]"]
  node_deletecodec["Delete codec<br/>[DeleteCodec.ts]"]
end

node_user(("Wallet user"))
node_xmtpsvc[("XMTP network")]
node_pinata[("Pinata IPFS")]

node_user -->|"connects wallet"| node_chatpage
node_chatpage -->|"initializes"| node_xmtpclient
node_chatpage -->|"renders"| node_chatlayout
node_chatlayout -->|"shows conversations"| node_sidebar
node_chatlayout -->|"shows messages"| node_chatwindow
node_chatwindow -->|"syncs messages"| node_sync
node_chatwindow -->|"resolves display"| node_display
node_chatwindow -->|"composes messages"| node_messageui
node_xmtpclient -->|"creates client"| node_xmtpsvc
node_xmtpclient -->|"registers codec"| node_callcodec
node_xmtpclient -->|"registers codec"| node_deletecodec
node_xmtpclient -->|"registers codec"| node_profilecodec
node_sidebar -->|"loads conversations"| node_conversations
node_messageui -->|"sends messages"| node_messages
node_sync -->|"fetches and streams"| node_messages
node_messages -->|"exchanges messages"| node_xmtpsvc
node_display -.->|"uses profile content"| node_profilecodec
node_webrtc -->|"sends call signals"| node_messages
node_webrtc -->|"streams signals"| node_messages
node_webrtc -->|"handles call payloads"| node_callcodec
node_callui -->|"controls call"| node_webrtc
node_incoming -->|"accepts or rejects"| node_webrtc
node_webrtc -.->|"gets ICE config"| node_turn
node_ipfs -.->|"stores encrypted files"| node_pinata
node_messages -.->|"shares attachments"| node_ipfs
node_sync -.->|"processes revocations"| node_deletecodec
node_profilecodec -.->|"broadcasts profiles"| node_xmtpsvc
node_deletecodec -.->|"broadcasts deletions"| node_xmtpsvc

click node_chatpage "https://github.com/swadesh-c0de/dchat/blob/main/src/app/chat/page.tsx"
click node_chatlayout "https://github.com/swadesh-c0de/dchat/blob/main/src/components/chat/ChatLayout.tsx"
click node_chatwindow "https://github.com/swadesh-c0de/dchat/blob/main/src/components/chat/ChatWindow.tsx"
click node_sidebar "https://github.com/swadesh-c0de/dchat/blob/main/src/components/chat/ChatSidebar.tsx"
click node_messageui "https://github.com/swadesh-c0de/dchat/blob/main/src/components/chat/MessageInput.tsx"
click node_xmtpclient "https://github.com/swadesh-c0de/dchat/blob/main/src/lib/xmtp/client.ts"
click node_conversations "https://github.com/swadesh-c0de/dchat/blob/main/src/lib/xmtp/conversations.ts"
click node_messages "https://github.com/swadesh-c0de/dchat/blob/main/src/lib/xmtp/messages.ts"
click node_sync "https://github.com/swadesh-c0de/dchat/blob/main/src/hooks/useMessagesSync.ts"
click node_display "https://github.com/swadesh-c0de/dchat/blob/main/src/hooks/useConversationDisplay.ts"
click node_webrtc "https://github.com/swadesh-c0de/dchat/blob/main/src/hooks/useWebRTC.ts"
click node_callui "https://github.com/swadesh-c0de/dchat/blob/main/src/components/chat/VideoCallModal.tsx"
click node_incoming "https://github.com/swadesh-c0de/dchat/blob/main/src/components/chat/IncomingCallModal.tsx"
click node_turn "https://github.com/swadesh-c0de/dchat/blob/main/src/app/api/turn/route.ts"
click node_ipfs "https://github.com/swadesh-c0de/dchat/blob/main/src/lib/ipfs.ts"
click node_profilecodec "https://github.com/swadesh-c0de/dchat/blob/main/src/lib/xmtp/codecs/ProfileCodec.ts"
click node_deletecodec "https://github.com/swadesh-c0de/dchat/blob/main/src/lib/xmtp/codecs/DeleteCodec.ts"
click node_callcodec "https://github.com/swadesh-c0de/dchat/blob/main/src/lib/xmtp/codecs/CallCodec.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_chatpage,node_chatlayout,node_chatwindow,node_sidebar,node_messageui,node_user toneBlue
class node_xmtpclient,node_conversations,node_messages,node_sync,node_display,node_xmtpsvc,node_pinata toneAmber
class node_webrtc,node_callui,node_incoming,node_turn,node_callcodec toneMint
class node_ipfs toneRose
class node_profilecodec,node_deletecodec toneIndigo
```

## Components

### Client Experience

- [Chat entry](https://github.com/swadesh-c0de/dchat/blob/main/src/app/chat/page.tsx): `src/app/chat/page.tsx`
- [Chat workspace](https://github.com/swadesh-c0de/dchat/blob/main/src/components/chat/ChatLayout.tsx): `src/components/chat/ChatLayout.tsx`
- [Conversation view](https://github.com/swadesh-c0de/dchat/blob/main/src/components/chat/ChatWindow.tsx): `src/components/chat/ChatWindow.tsx`
- [Conversation list](https://github.com/swadesh-c0de/dchat/blob/main/src/components/chat/ChatSidebar.tsx): `src/components/chat/ChatSidebar.tsx`
- [Message composer](https://github.com/swadesh-c0de/dchat/blob/main/src/components/chat/MessageInput.tsx): `src/components/chat/MessageInput.tsx`

### XMTP Messaging

- [XMTP client](https://github.com/swadesh-c0de/dchat/blob/main/src/lib/xmtp/client.ts): `src/lib/xmtp/client.ts`
- [Conversation operations](https://github.com/swadesh-c0de/dchat/blob/main/src/lib/xmtp/conversations.ts): `src/lib/xmtp/conversations.ts`
- [Message operations](https://github.com/swadesh-c0de/dchat/blob/main/src/lib/xmtp/messages.ts): `src/lib/xmtp/messages.ts`
- [Message synchronization](https://github.com/swadesh-c0de/dchat/blob/main/src/hooks/useMessagesSync.ts): `src/hooks/useMessagesSync.ts`
- [Conversation display](https://github.com/swadesh-c0de/dchat/blob/main/src/hooks/useConversationDisplay.ts): `src/hooks/useConversationDisplay.ts`

### Peer Calls

- [WebRTC call state](https://github.com/swadesh-c0de/dchat/blob/main/src/hooks/useWebRTC.ts): `src/hooks/useWebRTC.ts`
- [Call controls](https://github.com/swadesh-c0de/dchat/blob/main/src/components/chat/VideoCallModal.tsx): `src/components/chat/VideoCallModal.tsx`
- [Incoming call prompt](https://github.com/swadesh-c0de/dchat/blob/main/src/components/chat/IncomingCallModal.tsx): `src/components/chat/IncomingCallModal.tsx`
- [ICE configuration](https://github.com/swadesh-c0de/dchat/blob/main/src/app/api/turn/route.ts): `src/app/api/turn/route.ts`
- [Call codec](https://github.com/swadesh-c0de/dchat/blob/main/src/lib/xmtp/codecs/CallCodec.ts): `src/lib/xmtp/codecs/CallCodec.ts`

### Encrypted Attachments

- [Attachment handling](https://github.com/swadesh-c0de/dchat/blob/main/src/lib/ipfs.ts): `src/lib/ipfs.ts`

### Profiles and Revocation

- [Profile codec](https://github.com/swadesh-c0de/dchat/blob/main/src/lib/xmtp/codecs/ProfileCodec.ts): `src/lib/xmtp/codecs/ProfileCodec.ts`
- [Delete codec](https://github.com/swadesh-c0de/dchat/blob/main/src/lib/xmtp/codecs/DeleteCodec.ts): `src/lib/xmtp/codecs/DeleteCodec.ts`

### Other components

- **Wallet user**
- **XMTP network**
- **Pinata IPFS**

## Connections

- Wallet user → Chat entry: connects wallet
- Chat entry → XMTP client: initializes
- Chat entry → Chat workspace: renders
- Chat workspace → Conversation list: shows conversations
- Chat workspace → Conversation view: shows messages
- Conversation view → Message synchronization: syncs messages
- Conversation view → Conversation display: resolves display
- Conversation view → Message composer: composes messages
- XMTP client → XMTP network: creates client
- XMTP client → Call codec: registers codec
- XMTP client → Delete codec: registers codec
- XMTP client → Profile codec: registers codec
- Conversation list → Conversation operations: loads conversations
- Message composer → Message operations: sends messages
- Message synchronization → Message operations: fetches and streams
- Message operations → XMTP network: exchanges messages
- Conversation display → Profile codec: uses profile content
- WebRTC call state → Message operations: sends call signals
- WebRTC call state → Message operations: streams signals
- WebRTC call state → Call codec: handles call payloads
- Call controls → WebRTC call state: controls call
- Incoming call prompt → WebRTC call state: accepts or rejects
- WebRTC call state → ICE configuration: gets ICE config
- Attachment handling → Pinata IPFS: stores encrypted files
- Message operations → Attachment handling: shares attachments
- Message synchronization → Delete codec: processes revocations
- Profile codec → XMTP network: broadcasts profiles
- Delete codec → XMTP network: broadcasts deletions
