This is a real-time chat application built using WebSocket architecture with a Relayer Server and User WebSocket Server. It supports room-based messaging, allowing users to join specific chat rooms and receive only relevant messages.
.
├── relayer-ws # Relayer WebSocket Server (broadcasts to all user-ws)
│ └── index.ts
├── user-ws # User WebSocket Server (handles client room connections)
│ └── index.ts
├── fe # Frontend (Not included in this repo structure)
├── node_modules # Node dependencies
├── .git # Git repo
Go to both relayer-ws and user-ws folders and run:
npm installOr if you're using yarn:
yarn installcd relayer-ws
node index.tsThis will start the relayer WebSocket server at ws://localhost:3001.
cd user-ws
node index.tsThis will start the user-facing WebSocket server at ws://localhost:8080.
The frontend should:
- Connect to
ws://localhost:8080 - Send a message like:
{ "type": "join-room", "room": "room-1" }- Then send chat messages:
{ "type": "chat", "room": "room-1", "sender": "Ashutosh", "message": "Hello world!" }- It will receive messages broadcasted to the same room via the relayer.
- Clients connect to the
user-wsserver. - Clients join rooms.
- When someone sends a
"chat"message,user-wsforwards it torelayer-ws. relayer-wsbroadcasts the message to alluser-wsservers.- Each
user-wsthen forwards the message to all clients in the same room.
- WebSocket-based real-time communication
- Room-based architecture
- Modular relayer layer (can be scaled to multiple nodes)
- Simple and extendable
We will try to integrate Nibiru Wallet to add web3 features:
Let users connect their Nibiru wallet to authenticate:
- Integrate wallet connect SDK
- On connect, get wallet address and treat it as the unique user ID
Let users tip others in chat:
- Integrate Nibiru token transfer using
@cosmjs - Use recipient wallet address from user metadata
- Trigger tip via UI button
// Sample logic (pseudocode)
await sendTokens(fromWallet, toWallet, '10nibi');Chat_App.mp4
- Add authentication & validation
- Add persistent chat storage (MongoDB, Redis, etc.)
- Frontend UI
- Unit tests
- Web3/Nibiru integration
Ashutosh Raj
Built with ❤️ using TypeScript + WebSocket + React