The web client for a messaging and social app: chats, groups, channels, business tools and a social feed, kept in sync with the user's phone.
The product is a mobile messaging and social app. Users wanted it on a computer too, the way WhatsApp Web works: log in by scanning a QR code with the phone, see the same chats, and have anything done on the web show up on the phone and the other way round.
The web client had to fit an existing backend and existing mobile apps, so it had to match their REST and socket contracts and their encryption scheme. It also had a large surface: one-to-one and group chat, channels, broadcasts, stories, business tools and a social feed.
The UI doesn't render from API responses. On load, a REST sync writes rooms and messages into a Dexie (IndexedDB) database for the signed-in user; socket events write into the same tables; components read through live queries. Every source of data has one path into the UI, and a returning user sees their chats immediately from the local copy.
The local store is a cache, not the source of truth. Sync removes rooms the server no longer returns and adds messages that are missing, and writes are keyed by message ID, so replays and duplicate events do no harm.
Chat, channels, the social feed and polls each have their own Socket.IO connection and listener hook. Listeners are attached once and read the latest handlers through a ref, so React re-renders don't detach and reattach them.
Anything the user changes on the web (a sent message, a read receipt, a star, a label) is also emitted to their other sessions, so the phone and other tabs stay in step without polling.
Each room has a random AES key that encrypts its messages. That key is wrapped for every member with their RSA public key using RSA-OAEP. The Web Crypto API does the work, with a node-forge fallback for the key formats the mobile apps use.
Every path writes into the same IndexedDB store, and the UI reads only from that store.
QR login streams the session state over Server-Sent Events until the phone approves it. Phone number and OTP is the fallback.
A sent message appears at once with a temporary local ID and a pending state. The socket acknowledgement replaces it with the server's copy and mirrors it to the user's other devices.
History pages from a compound index on room and timestamp. Jumping to a search result or a quoted reply counts the newer messages on that index and widens the window just enough to include the target.
A message is marked seen only when it is on screen and the tab is visible and focused, using an IntersectionObserver.
Catalogue, labels, quick replies, away and greeting messages and business hours, all on the same sync model.
A true local-first design, with an offline write queue and conflict resolution, would have needed backend changes. Treating IndexedDB as a read model gave instant loads and a single render path while keeping the server in charge. The trade-off is that sending needs a connection.
Interoperability came first: the web client had to read messages the phones encrypted. I used Web Crypto where it supports the formats and a library fallback where it doesn't, rather than choosing different primitives.