A modern, real-time WebSocket chat application with live upvoting and dynamic message ranking. Built with React and Node.js.
RankedChat enables users to engage in real-time conversations where messages are dynamically ranked based on community upvotes. The application provides three simultaneous views of the conversation, updating instantly without page reloads.
- Real-time Communication - Instant message delivery using WebSockets
- Live Voting System - Upvote messages to influence their ranking
- Dynamic UI Updates - Three synchronized views (All Messages, Top 5, Top 2)
- Connection Monitoring - Visual status indicator for WebSocket connection
- Responsive Design - Optimized for desktop, tablet, and mobile devices
- ⚡ Real-time messaging with WebSocket protocol
- 👍 Live upvoting and downvoting system
- 📊 Automatic message sorting by vote count
- 🔄 Instant UI synchronization across all views
- 🎯 Room-based chat organization
- 🟢 Connection status monitoring
- 📱 Fully responsive layout (mobile-first design)
- 🎨 Clean, professional UI with Tailwind CSS
- 📈 Multiple ranking views:
- All Messages - Complete conversation history
- Top 5 Messages - Highest voted messages
- Top 2 Messages - Best two messages
- ⌨️ Form submission with Enter key support
- 🎭 Smooth hover effects and transitions
| Technology | Purpose |
|---|---|
| React 18+ | UI framework with hooks |
| Vite | Fast build tool and dev server |
| Tailwind CSS | Utility-first CSS framework |
| WebSocket API | Real-time client communication |
| Technology | Purpose |
|---|---|
| Node.js | JavaScript runtime |
| Express | Web server framework |
| ws | WebSocket library |
┌─────────────┐ WebSocket ┌─────────────┐
│ Client 1 │◄──────────────────────────►│ │
└─────────────┘ │ │
│ Server │
┌─────────────┐ WebSocket │ (Node.js) │
│ Client 2 │◄──────────────────────────►│ │
└─────────────┘ │ │
└─────────────┘
▲ │
│ │
└──────────── Broadcasts Updates ─────────┘
- Client connects to WebSocket server
- User sends message via input form
- Server receives and broadcasts to all clients
- Clients update local state and re-render
- User upvotes trigger UPDATE_CHAT events
- UI automatically sorts and displays rankings
- Single source of truth (
messagesarray) - Derived views computed on render
- Sorted by upvote count for rankings
- Immutable state updates for React optimization
Join a chat room on connection.
{
"type": "JOIN_ROOM",
"payload": {
"name": "John Doe",
"userId": "123456",
"roomId": "1"
}
}Send a new chat message.
{
"type": "SEND_MESSAGE",
"payload": {
"message": "Hello, world!",
"userId": "123456",
"roomId": "1"
}
}Upvote an existing message.
{
"type": "UPVOTE_MESSAGE",
"payload": {
"chatId": "msg_abc123",
"userId": "123456",
"roomId": "1"
}
}Broadcast when a new message is added.
{
"type": "ADD_CHAT",
"payload": {
"chatId": "msg_abc123",
"message": "Hello, world!",
"upvotes": 0
}
}Broadcast when a message is upvoted.
{
"type": "UPDATE_CHAT",
"payload": {
"chatId": "msg_abc123",
"upvotes": 5
}
}⭐ Star this repository if you found it helpful!