A production-ready Web3 chat backend with Discord-like rooms, wallet authentication, and real-time messaging using plain SQL (no ORM).
- Wallet Authentication: EIP-191
personal_signbased authentication - Room Types: Public, Private, and P2P (one-to-one) rooms
- Room Permissions: Admin controls with join request system for public rooms
- Real-time Messaging: Socket.IO powered real-time chat
- Message Reactions: Like/unlike messages with real-time updates
- Typing Indicators: Real-time typing status
- Invitation System: Wallet-based invitations for private rooms
- Runtime: Node.js + Express
- Database: PostgreSQL (NeonDB compatible)
- Driver:
pgwithpg-poolconnection pooling - Real-time: Socket.IO
- Authentication: JWT + EIP-191 signatures
users ├── wallet_address (unique) ├── nonce (for signing) └── timestamps
chat_rooms ├── name, description ├── room_type (public/private/p2p) ├── admin_id (references users) └── timestamps
room_members ├── room_id, user_id (composite unique) ├── status (pending/approved/rejected/left) ├── is_admin └── timestamps
messages ├── room_id, sender_id ├── content ├── parent_message_id (for replies) └── timestamps
message_likes ├── message_id, user_id, reaction_type └── timestamps
room_invitations ├── room_id, inviter_id, invitee_wallet_address ├── status (pending/accepted/rejected) └── expiration
text
POST /api/auth/nonce- Get nonce for walletPOST /api/auth/verify- Verify signature and get JWTPOST /api/auth/refresh- Refresh JWT tokenGET /api/auth/me- Get user profile
POST /api/rooms- Create roomGET /api/rooms/public- Get public roomsGET /api/rooms/my- Get user's roomsGET /api/rooms/:roomId- Get room detailsPOST /api/rooms/:roomId/join- Request to join public roomPOST /api/rooms/:roomId/invite- Invite to private room (admin only)GET /api/rooms/:roomId/requests- Get pending requests (admin only)POST /api/rooms/:roomId/leave- Leave roomDELETE /api/rooms/:roomId- Delete room (admin only)POST /api/rooms/p2p/:walletAddress- Create/get P2P room
GET /api/rooms/:roomId/messages- Get room messagesPOST /api/rooms/:roomId/messages- Send messagePUT /api/messages/:messageId- Edit messageDELETE /api/messages/:messageId- Delete messagePOST /api/messages/:messageId/like- Like messageDELETE /api/messages/:messageId/like- Unlike messageGET /api/messages/:messageId/likes- Get message likes
GET /api/invitations- Get user invitationsPOST /api/invitations/:invitationId/accept- Accept invitationPOST /api/invitations/:invitationId/reject- Reject invitation
join_room- Join a roomleave_room- Leave a roomsend_message- Send message to roomtyping- Typing indicator starttyping_stop- Typing indicator stoplike_message- Like a messageunlike_message- Unlike a message
rooms_joined- List of joined rooms on connectroom_joined- Room join confirmationroom_left- Room leave confirmationuser_joined- Another user joined roomuser_left- Another user left roomnew_message- New message in roomuser_typing- User typing in roomuser_typing_stop- User stopped typingmessage_liked- Message likedmessage_unliked- Message unliked
- Clone the repository
git clone <repository-url>
cd web3-chat-backend
Install dependencies