How anthonejc/chat-e2ee works
1. Repository shape
- This is a monorepo with three main runtime surfaces: the browser UI in client/, the Node/Express backend in backend/, and a reusable client-side SDK in service/.
- The root app.ts / index.ts files are the server entrypoints; in production the backend also serves the built frontend assets.
2. Primary product boundary
- The system is designed for ephemeral, disposable 1:1 encrypted chat sessions.
- A key architectural constraint is that private keys never leave the user’s device; the backend relays encrypted content and does not act as a decryption boundary.
3. Frontend/UI layer
- client/ is a lightweight React-based UI that consumes the SDK rather than embedding most protocol logic itself.
- This keeps the presentation layer thin: UI interactions are separated from encryption, signaling, and transport logic.
4. SDK layer
- service/ is the core client-facing package (@chat-e2ee/service) intended for both the bundled UI and custom frontends.
- It wraps cryptography, link/session handling, socket communication, and WebRTC call setup into a single client library.
- Key modules include cryptoAES.ts, cryptoRSA.ts, socket/, webrtc.ts, webrtcSession.ts, and helpers for links, users, and message sending.
5. Backend API layer
- backend/api/ groups the HTTP-facing business endpoints by concern:
- chatHash/ for link/PIN/channel validation and session identity,
- messaging/ for message-related operations,
- call/ for call/session setup.
- backend/middleware/asyncHandler.ts suggests the API is built around async Express handlers with centralized error wrapping.
6. Realtime signaling and presence
- backend/socket.io/ is the realtime backbone.
- clients.ts tracks connected users/participants, listeners.ts wires event handlers, and index.ts initializes the socket server.
- This channel is used for low-latency relay and for WebRTC signaling, not as a message store.
7. Session and channel model
- The app centers on a chat hash / link / PIN concept, implemented in backend/api/chatHash/utils/.
- Utilities such as link.ts, pin.ts, and validateChannel.ts indicate a session bootstrapping flow where two users join the same channel after sharing a generated link or PIN.
- This is the primary identity mechanism; there is no username/password account model.
8. Data storage strategy
- backend/db/inMemDB.ts implies the backend uses in-memory state, not a durable database.
- That matches the product goal: minimal retention, no chat history after the session ends, and no long-lived server-side user records.
- backend/db/const.ts likely holds shared session/status constants used across API and socket code.
9. Cryptography boundary
- The SDK handles encryption on the client side using browser cryptography and helper implementations in service/src/cryptoAES.ts and service/src/cryptoRSA.ts.
- The README states that private keys are generated on-device and never uploaded; the backend only sees encrypted payloads.
- This makes the server a transport/signaling relay rather than a trusted decryption service.
10. WebRTC audio path
- Audio calling is a separate realtime path from text chat, implemented in service/src/webrtc.ts and service/src/webrtcSession.ts.
- backend/api/call/session.ts and socket signaling coordinate session establishment, while media itself is intended to flow peer-to-peer.
- The README notes experimental end-to-end audio encryption using RTCRtpSender.createEncodedStreams, which is a notable browser capability constraint.
11. External service integrations
- backend/external/imgbb.ts, imgur.ts, and uploadImage.ts indicate optional image-upload integration with third-party hosts.
- These are ancillary to the core chat path and represent the only obvious external data boundary beyond the backend itself.
12. Build, deployment, and delivery
- The repo includes Docker support under docker/, a native wrapper under native/, and CI/publish workflows in .github/workflows/.
- This suggests the project can be run locally, containerized, or packaged as a reusable service/SDK.
- In production, the backend serves the compiled frontend, so the deployable unit is effectively a single Node service plus static assets.
13. Verification and quality gates
- Unit tests exist around critical protocol utilities and crypto (service/src/*.test.ts, backend chat-hash tests), and there is a Playwright e2e flow for joining a session.
- These tests reflect the architecture’s most sensitive seams: session joining, channel validation, and cryptographic helpers.
Main entry points: sdk.ts Client SDK · api/index.ts HTTP API · socket.io/index.ts Socket relay · app.ts Server entry
Components 18
Frontend
Browser UI and client SDK
- React UI · Thin browser presentation layer that consumes the SDK
client/app.ts - Client SDK · Reusable client package wrapping crypto, links, sockets, and WebRTC
service/src/sdk.ts - Crypto · Client-side AES and RSA helpers; private keys stay on-device
service/src/cryptoAES.ts - Links & users · Link generation, chat URL handling, user lookup, and session messaging helpers
service/src/getChatLink.ts - Socket client · Client-side socket communication used by the SDK
service/src/socket/socket.ts - WebRTC · Peer-to-peer audio call setup and session management
service/src/webrtc.ts - Protocol helpers · UUID, logging, config context, and shared public types
service/src/public/types.ts
Backend
Express API, realtime relay, and in-memory state
- Server entry · Top-level Node entrypoints that bootstrap the app and serve the production build
app.ts - HTTP API · Backend API surface grouped by chat hash, messaging, and call concerns
backend/api/index.ts - Chat hash · Link, PIN, and channel validation for joining disposable sessions
backend/api/chatHash/index.ts - Messaging API · HTTP operations for chat message flow
backend/api/messaging/index.ts - Call API · HTTP setup for audio call sessions
backend/api/call/session.ts - Socket relay · Socket.io server for presence, low-latency relay, and WebRTC signaling
backend/socket.io/index.ts - Clients · Tracks connected users and channel participants
backend/socket.io/clients.ts - Listeners · Wires socket events into backend behavior
backend/socket.io/listeners.ts - In-memory DB · Transient server state for sessions and channels
backend/db/inMemDB.ts - Image upload · Optional integrations for uploading images to external hosts
backend/external/uploadImage.ts
Delivery
Build, deployment, and packaging
- Build & deploy · Docker, native packaging, and publish workflows for delivery
docker/Dockerfile
Connections 25
- Server entry → HTTP API: boots · Server entrypoint mounts the HTTP API
- Server entry → Socket relay: starts · Server entrypoint initializes realtime signaling
- Server entry → In-memory DB: shares state · Backend runtime uses transient in-memory session state
- HTTP API → Chat hash: routes · API delegates session identity and join validation
- HTTP API → Messaging API: routes · API exposes message operations
- HTTP API → Call API: routes · API exposes call/session setup
- Chat hash → In-memory DB: reads/writes · Session bootstrap relies on ephemeral backend state
- Messaging API → In-memory DB: stores transient · Messaging metadata is kept only for the live session
- Call API → Socket relay: signals · Call setup coordinates via realtime channel
- Socket relay → Clients: tracks · Realtime server maintains connected participants
- Socket relay → Listeners: dispatches · Socket events are bound to handlers
- Listeners → In-memory DB: updates · Handlers mutate transient session state
- React UI → Client SDK: uses · UI delegates protocol logic to the SDK
- Client SDK → Crypto: wraps · SDK exposes client-side encryption primitives
- Client SDK → Links & users: wraps · SDK handles session links, users, and message flow
- Client SDK → Socket client: connects · SDK uses sockets for signaling and relay
- Client SDK → WebRTC: orchestrates · SDK sets up peer-to-peer audio sessions
- Client SDK → Protocol helpers: depends on · SDK shares public types and client utilities
- Crypto → HTTP API: encrypts for · Client encrypts payloads before sending them to the server
- Socket client → Socket relay: connects to · Client SDK speaks to backend realtime relay
- WebRTC → Call API: initiates · WebRTC session setup begins through call endpoints
- Image upload → Messaging API: supports · Optional image upload augments message flow
- Build & deploy → Server entry: packages · Delivery tooling builds the server artifact
- Build & deploy → React UI: bundles · Delivery tooling compiles frontend assets
- Build & deploy → Client SDK: publishes · SDK is packaged for reuse by other frontends