# codexaniket/cipherlink architecture

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

## Overview

CipherLink is a browser-based, peer-to-peer messenger. A user creates a device identity, adds a contact by friend code, and the signaling server introduces the browsers; after WebRTC connects, chat and media travel directly between them. Contacts, keys, and conversation history stay in browser storage, while the server retains limited identity, waiting-request, and push-subscription records. The graph also shows notification delivery and the safety/connection-information layer. Some app and server source was sampled only in excerpts, so uncertain internal wiring is omitted.

Main entry points: [`public/app.js`](https://github.com/codexaniket/cipherlink/blob/main/public/app.js) (App workflow), [`server.js`](https://github.com/codexaniket/cipherlink/blob/main/server.js) (Signaling server), [`public/peer.js`](https://github.com/codexaniket/cipherlink/blob/main/public/peer.js) (WebRTC connection), [`public/sw.js`](https://github.com/codexaniket/cipherlink/blob/main/public/sw.js) (Service worker)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser app"]
  node_page["Chat interface<br/>[index.html]"]
  node_app["App workflow<br/>[app.js]"]
end

subgraph group_identity["Identity and history"]
  node_identity_keys["Device keys<br/>[device-key.js]"]
  node_browser_store[("Browser history<br/>[storage.js]")]
end

subgraph group_realtime["Peer chat"]
  node_peer["WebRTC connection<br/>[peer.js]"]
end

subgraph group_signaling["Signaling service"]
  node_signaling_server["Signaling server<br/>[server.js]"]
  node_server_records[("Server records<br/>[server.js]")]
end

subgraph group_alerts["Notifications"]
  node_notify["Notification controls<br/>[notify.js]"]
  node_worker["Service worker<br/>[sw.js]"]
  node_sounds["UI sounds<br/>[sounds.js]"]
end

node_user(("User"))
node_remote(("Contact browser"))
node_push_service["Push service"]
node_stun["Google STUN"]

node_user -->|"uses"| node_page
node_page -->|"hosts interface"| node_app
node_app -->|"loads identity"| node_identity_keys
node_identity_keys -->|"reads/writes key"| node_browser_store
node_app -->|"reads/writes chats"| node_browser_store
node_app -->|"signs in; exchanges requests"| node_signaling_server
node_signaling_server -->|"dispatches signaling"| node_app
node_signaling_server -->|"stores pending records"| node_server_records
node_app -->|"creates connection"| node_peer
node_peer -->|"sends handshake signals"| node_signaling_server
node_signaling_server -->|"forwards handshake signals"| node_peer
node_peer -->|"exchanges chat and media"| node_remote
node_remote -->|"returns chat and media"| node_peer
node_peer -.->|"discovers route"| node_stun
node_app -->|"controls alerts"| node_notify
node_app -->|"plays tones"| node_sounds
node_notify -->|"registers; shows alerts"| node_worker
node_signaling_server -.->|"sends encrypted push"| node_push_service
node_push_service -.->|"delivers push"| node_worker
node_worker -->|"shows request alert"| node_user

click node_page "https://github.com/codexaniket/cipherlink/blob/main/public/index.html"
click node_app "https://github.com/codexaniket/cipherlink/blob/main/public/app.js"
click node_identity_keys "https://github.com/codexaniket/cipherlink/blob/main/public/device-key.js"
click node_browser_store "https://github.com/codexaniket/cipherlink/blob/main/public/storage.js"
click node_peer "https://github.com/codexaniket/cipherlink/blob/main/public/peer.js"
click node_signaling_server "https://github.com/codexaniket/cipherlink/blob/main/server.js"
click node_server_records "https://github.com/codexaniket/cipherlink/blob/main/server.js"
click node_notify "https://github.com/codexaniket/cipherlink/blob/main/public/notify.js"
click node_worker "https://github.com/codexaniket/cipherlink/blob/main/public/sw.js"
click node_sounds "https://github.com/codexaniket/cipherlink/blob/main/public/sounds.js"

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_page,node_app,node_user,node_remote toneBlue
class node_identity_keys,node_browser_store toneAmber
class node_peer toneMint
class node_signaling_server,node_server_records toneRose
class node_notify,node_worker,node_sounds,node_push_service,node_stun toneIndigo
```

## Components

### Browser app

- [Chat interface](https://github.com/codexaniket/cipherlink/blob/main/public/index.html): `public/index.html`
- [App workflow](https://github.com/codexaniket/cipherlink/blob/main/public/app.js): `public/app.js`

### Identity and history

- [Device keys](https://github.com/codexaniket/cipherlink/blob/main/public/device-key.js): `public/device-key.js`
- [Browser history](https://github.com/codexaniket/cipherlink/blob/main/public/storage.js): `public/storage.js`

### Peer chat

- [WebRTC connection](https://github.com/codexaniket/cipherlink/blob/main/public/peer.js): `public/peer.js`

### Signaling service

- [Signaling server](https://github.com/codexaniket/cipherlink/blob/main/server.js): `server.js`
- [Server records](https://github.com/codexaniket/cipherlink/blob/main/server.js): `server.js`

### Notifications

- [Notification controls](https://github.com/codexaniket/cipherlink/blob/main/public/notify.js): `public/notify.js`
- [Service worker](https://github.com/codexaniket/cipherlink/blob/main/public/sw.js): `public/sw.js`
- [UI sounds](https://github.com/codexaniket/cipherlink/blob/main/public/sounds.js): `public/sounds.js`

### Other components

- **User**
- **Contact browser**
- **Push service**
- **Google STUN**

## Connections

- User → Chat interface: uses
- Chat interface → App workflow: hosts interface
- App workflow → Device keys: loads identity
- Device keys → Browser history: reads/writes key
- App workflow → Browser history: reads/writes chats
- App workflow → Signaling server: signs in; exchanges requests
- Signaling server → App workflow: dispatches signaling
- Signaling server → Server records: stores pending records
- App workflow → WebRTC connection: creates connection
- WebRTC connection → Signaling server: sends handshake signals
- Signaling server → WebRTC connection: forwards handshake signals
- WebRTC connection → Contact browser: exchanges chat and media
- Contact browser → WebRTC connection: returns chat and media
- WebRTC connection → Google STUN: discovers route
- App workflow → Notification controls: controls alerts
- App workflow → UI sounds: plays tones
- Notification controls → Service worker: registers; shows alerts
- Signaling server → Push service: sends encrypted push
- Push service → Service worker: delivers push
- Service worker → User: shows request alert
