# stevemoraco/bitchat-in-browser architecture

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

- Interactive diagram: https://gitdiagram.com/stevemoraco/bitchat-in-browser
- Repository: https://github.com/stevemoraco/bitchat-in-browser

## Overview

BitChat In Browser is a private, offline-first messaging PWA interoperable with native BitChat through Nostr. Users create or import an identity, enter location-based channels or private DMs, and exchange encrypted messages; the app also supports peer management, offline storage and sync, notifications, emergency wipe, and nearby app sharing. The README documents the product workflow and capabilities; sampled source confirms app routing, command-to-store updates, and storage backend selection. Other internal links are limited to README or SOURCE INDEX evidence, so unsampled implementation details are not inferred.

Main entry points: [`src/components/chat/ChatView.tsx`](https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/components/chat/ChatView.tsx) (Chat interface), [`src/services/storage/storage-manager.ts`](https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/services/storage/storage-manager.ts) (Storage manager), [`src/services/nostr/client.ts`](https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/services/nostr/client.ts) (Nostr protocol), [`src/App.tsx`](https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/App.tsx) (App shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["App and navigation"]
  node_app["App shell<br/>[App.tsx]"]
  node_router["Route guards<br/>[guards.tsx]"]
  node_onboarding["Identity onboarding<br/>[OnboardingFlow.tsx]"]
  node_channels["Channel pages<br/>[ChannelsPage.tsx]"]
end

subgraph group_messaging["Messaging experience"]
  node_channel_info["Channel details<br/>[ChannelInfo.tsx]"]
  node_location_create["Location channel setup"]
  node_chat["Chat interface<br/>[ChatView.tsx]"]
  node_message_input["Message composition<br/>[MessageInput.tsx]"]
  node_image_picker["Image selection<br/>[ImagePicker.tsx]"]
  node_payments["Payment messages<br/>[PaymentChip.tsx]"]
  node_formatting["Message formatting<br/>[renderer.ts]"]
end

subgraph group_protocol["Identity and networking"]
  node_identity["Identity and crypto<br/>[encryption.ts]"]
  node_nostr["Nostr protocol<br/>[client.ts]"]
  node_relay_list["Relay selection<br/>[relay-list.ts]"]
  node_webrtc["WebRTC connections<br/>[peer-connection.ts]"]
  node_sharing["Nearby app sharing<br/>[hotspot-bridge.ts]"]
end

subgraph group_platform["Offline and device services"]
  node_sync["Offline sync queue<br/>[offline-queue.ts]"]
  node_service_worker["Service worker<br/>[sw.ts]"]
  node_emergency["Emergency wipe<br/>[wipe.ts]"]
  node_storage_manager["Storage manager<br/>[storage-manager.ts]"]
  node_opfs[("OPFS adapter<br/>[opfs-storage.ts]")]
  node_indexeddb[("IndexedDB adapter")]
  node_performance["Performance utilities<br/>[performance.ts]"]
end

subgraph group_state["Application state"]
  node_messages_store["Message state<br/>[messages-store.ts]"]
  node_channels_store["Channel state<br/>[channels-store.ts]"]
  node_mesh_store["Mesh state<br/>[mesh-store.ts]"]
  node_settings_store["Settings state<br/>[settings-store.ts]"]
end

node_user(("User"))
node_native_apps(("Native BitChat users"))

node_user -->|"opens app"| node_app
node_app -->|"routes through"| node_router
node_router -->|"redirects to"| node_onboarding
node_user -->|"creates or imports"| node_onboarding
node_user -->|"joins channels"| node_channels
node_channels -->|"shows details"| node_channel_info
node_channels -->|"opens setup"| node_location_create
node_user -->|"opens conversation"| node_chat
node_chat -->|"composes messages"| node_message_input
node_message_input -.->|"selects images"| node_image_picker
node_chat -.->|"shows payment"| node_payments
node_chat -.->|"renders text"| node_formatting
node_user -->|"uses identity"| node_identity
node_identity -->|"encrypts DMs"| node_nostr
node_nostr -.->|"selects relays"| node_relay_list
node_nostr -->|"interoperates with"| node_native_apps
node_user -->|"shares app nearby"| node_sharing
node_chat -->|"queues offline messages"| node_sync
node_sync -->|"syncs when online"| node_nostr
node_app -->|"registers worker"| node_service_worker
node_user -->|"triggers wipe"| node_emergency
node_storage_manager -.->|"selects backend"| node_opfs
node_storage_manager -.->|"selects fallback"| node_indexeddb
node_messages_store -.->|"persists messages"| node_storage_manager
node_channels_store -.->|"persists channels"| node_storage_manager
node_performance -.->|"measures operations"| node_storage_manager

click node_app "https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/App.tsx"
click node_router "https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/router/guards.tsx"
click node_onboarding "https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/components/onboarding/OnboardingFlow.tsx"
click node_channels "https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/pages/ChannelsPage.tsx"
click node_channel_info "https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/components/channels/ChannelInfo.tsx"
click node_location_create "https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/components/channels/LocationChannelCreate.tsx"
click node_chat "https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/components/chat/ChatView.tsx"
click node_message_input "https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/components/chat/MessageInput.tsx"
click node_image_picker "https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/components/chat/ImagePicker.tsx"
click node_payments "https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/components/chat/PaymentChip.tsx"
click node_formatting "https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/services/formatting/renderer.ts"
click node_identity "https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/services/crypto/encryption.ts"
click node_nostr "https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/services/nostr/client.ts"
click node_relay_list "https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/services/nostr/relay-list.ts"
click node_webrtc "https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/services/webrtc/peer-connection.ts"
click node_sharing "https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/services/sharing/hotspot-bridge.ts"
click node_sync "https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/services/sync/offline-queue.ts"
click node_service_worker "https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/workers/sw.ts"
click node_emergency "https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/features/emergency/wipe.ts"
click node_storage_manager "https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/services/storage/storage-manager.ts"
click node_opfs "https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/services/storage/opfs-storage.ts"
click node_indexeddb "https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/services/storage/indexeddb-storage.ts"
click node_messages_store "https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/stores/messages-store.ts"
click node_channels_store "https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/stores/channels-store.ts"
click node_mesh_store "https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/stores/mesh-store.ts"
click node_settings_store "https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/stores/settings-store.ts"
click node_performance "https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/utils/performance.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_app,node_router,node_onboarding,node_channels,node_user,node_native_apps toneBlue
class node_channel_info,node_location_create,node_chat,node_message_input,node_image_picker,node_payments,node_formatting toneAmber
class node_identity,node_nostr,node_relay_list,node_webrtc,node_sharing toneMint
class node_sync,node_service_worker,node_emergency,node_storage_manager,node_opfs,node_indexeddb,node_performance toneRose
class node_messages_store,node_channels_store,node_mesh_store,node_settings_store toneIndigo
```

## Components

### App and navigation

- [App shell](https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/App.tsx): `src/App.tsx`
- [Route guards](https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/router/guards.tsx): `src/router/guards.tsx`
- [Identity onboarding](https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/components/onboarding/OnboardingFlow.tsx): `src/components/onboarding/OnboardingFlow.tsx`
- [Channel pages](https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/pages/ChannelsPage.tsx): `src/pages/ChannelsPage.tsx`

### Messaging experience

- [Channel details](https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/components/channels/ChannelInfo.tsx): `src/components/channels/ChannelInfo.tsx`
- [Location channel setup](https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/components/channels/LocationChannelCreate.tsx): `src/components/channels/LocationChannelCreate.tsx`
- [Chat interface](https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/components/chat/ChatView.tsx): `src/components/chat/ChatView.tsx`
- [Message composition](https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/components/chat/MessageInput.tsx): `src/components/chat/MessageInput.tsx`
- [Image selection](https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/components/chat/ImagePicker.tsx): `src/components/chat/ImagePicker.tsx`
- [Payment messages](https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/components/chat/PaymentChip.tsx): `src/components/chat/PaymentChip.tsx`
- [Message formatting](https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/services/formatting/renderer.ts): `src/services/formatting/renderer.ts`

### Identity and networking

- [Identity and crypto](https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/services/crypto/encryption.ts): `src/services/crypto/encryption.ts`
- [Nostr protocol](https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/services/nostr/client.ts): `src/services/nostr/client.ts`
- [Relay selection](https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/services/nostr/relay-list.ts): `src/services/nostr/relay-list.ts`
- [WebRTC connections](https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/services/webrtc/peer-connection.ts): `src/services/webrtc/peer-connection.ts`
- [Nearby app sharing](https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/services/sharing/hotspot-bridge.ts): `src/services/sharing/hotspot-bridge.ts`

### Offline and device services

- [Offline sync queue](https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/services/sync/offline-queue.ts): `src/services/sync/offline-queue.ts`
- [Service worker](https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/workers/sw.ts): `src/workers/sw.ts`
- [Emergency wipe](https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/features/emergency/wipe.ts): `src/features/emergency/wipe.ts`
- [Storage manager](https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/services/storage/storage-manager.ts): `src/services/storage/storage-manager.ts`
- [OPFS adapter](https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/services/storage/opfs-storage.ts): `src/services/storage/opfs-storage.ts`
- [IndexedDB adapter](https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/services/storage/indexeddb-storage.ts): `src/services/storage/indexeddb-storage.ts`
- [Performance utilities](https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/utils/performance.ts): `src/utils/performance.ts`

### Application state

- [Message state](https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/stores/messages-store.ts): `src/stores/messages-store.ts`
- [Channel state](https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/stores/channels-store.ts): `src/stores/channels-store.ts`
- [Mesh state](https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/stores/mesh-store.ts): `src/stores/mesh-store.ts`
- [Settings state](https://github.com/stevemoraco/bitchat-in-browser/blob/main/src/stores/settings-store.ts): `src/stores/settings-store.ts`

### Other components

- **User**
- **Native BitChat users**

## Connections

- User → App shell: opens app (evidence: `README.md`)
- App shell → Route guards: routes through (evidence: `src/App.tsx`)
- Route guards → Identity onboarding: redirects to
- User → Identity onboarding: creates or imports (evidence: `README.md`)
- User → Channel pages: joins channels (evidence: `README.md`)
- Channel pages → Channel details: shows details (evidence: `src/pages/ChannelsPage.tsx`)
- Channel pages → Location channel setup: opens setup (evidence: `src/pages/ChannelsPage.tsx`)
- User → Chat interface: opens conversation (evidence: `README.md`)
- Chat interface → Message composition: composes messages (evidence: `src/components/chat/index.ts`)
- Message composition → Image selection: selects images
- Chat interface → Payment messages: shows payment
- Chat interface → Message formatting: renders text
- User → Identity and crypto: uses identity (evidence: `README.md`)
- Identity and crypto → Nostr protocol: encrypts DMs (evidence: `README.md`)
- Nostr protocol → Relay selection: selects relays
- Nostr protocol → Native BitChat users: interoperates with (evidence: `README.md`)
- User → Nearby app sharing: shares app nearby (evidence: `README.md`)
- Chat interface → Offline sync queue: queues offline messages (evidence: `README.md`)
- Offline sync queue → Nostr protocol: syncs when online (evidence: `README.md`)
- App shell → Service worker: registers worker
- User → Emergency wipe: triggers wipe (evidence: `README.md`)
- Storage manager → OPFS adapter: selects backend (evidence: `src/services/storage/storage-manager.ts`)
- Storage manager → IndexedDB adapter: selects fallback (evidence: `src/services/storage/storage-manager.ts`)
- Message state → Storage manager: persists messages
- Channel state → Storage manager: persists channels
- Performance utilities → Storage manager: measures operations
