A modern, production-ready real-time chat application built with React.js, Node.js, Express, and Socket.IO.
- Real-time messaging with Socket.IO
- Multi-user support with live user list
- Typing indicators showing who's currently typing
- User join/leave notifications with sound alerts
- Message timestamps with smart formatting
- Auto-scroll to latest messages
- Input validation and message sanitization
- Responsive design for mobile, tablet, and desktop
- Dark/light mode toggle with system preference detection
- Emoji picker with popular emojis
- Sound notifications for new messages
- Connection status indicators
- Rate limiting and spam protection
- Clean architecture with separated concerns
- TypeScript for type safety
- Real-time WebSocket communication
- Session persistence with localStorage
- Error handling and graceful degradation
- Memory-efficient message management
- React 18 with TypeScript
- TailwindCSS for styling
- Socket.IO Client for real-time communication
- Lucide React for icons
- Vite for development and building
- Node.js with Express.js
- Socket.IO for WebSocket communication
- CORS for cross-origin requests
- Helmet for security headers
- Express Rate Limit for API protection
- Node.js (v16 or higher)
- npm or yarn
# Install frontend dependencies
npm install
# Install backend dependencies
cd server
npm install
cd ..cd server
npm startnpm run dev- Frontend: http://localhost:5173
- Backend API: http://localhost:5000
- Health Check: http://localhost:5000/health
- Join the Chat: Enter a unique username (2-20 characters)
- Send Messages: Type your message and press Enter or click Send
- See Who's Online: Check the user list sidebar
- Typing Indicators: See when others are typing
- Emoji Support: Click the smile icon to add emojis
- Theme Toggle: Switch between light and dark modes
- Notifications: Get notified when users join/leave or send messages
βββ src/ # Frontend source code
β βββ components/ # React components
β β βββ ChatInterface.tsx # Main chat container
β β βββ ChatHeader.tsx # Header with user info
β β βββ MessageList.tsx # Message display area
β β βββ MessageBubble.tsx # Individual message component
β β βββ MessageInput.tsx # Message input with emoji picker
β β βββ UserList.tsx # Online users sidebar
β β βββ TypingIndicator.tsx # Shows typing users
β β βββ NotificationCenter.tsx # Toast notifications
β β βββ LoginPage.tsx # Username entry page
β βββ contexts/ # React contexts
β β βββ SocketContext.tsx # Socket.IO connection
β β βββ ThemeContext.tsx # Dark/light theme
β βββ types/ # TypeScript definitions
β β βββ chat.ts # Chat-related types
β βββ utils/ # Utility functions
β β βββ dateUtils.ts # Date formatting helpers
β βββ App.tsx # Main app component
βββ server/ # Backend source code
β βββ sockets/ # Socket.IO handlers
β β βββ socketHandlers.js # Connection and message handling
β βββ utils/ # Server utilities
β β βββ userManager.js # User session management
β β βββ messageManager.js # Message handling and validation
β βββ package.json # Backend dependencies
β βββ server.js # Express server setup
βββ README.md # This file
The application works out of the box with these default configurations:
- Frontend Port: 5173 (Vite default)
- Backend Port: 5000
- Socket.IO Transport: WebSocket with polling fallback
You can customize various aspects:
- Server Port: Change
PORTinserver/server.js - Socket URL: Update the connection URL in
src/contexts/SocketContext.tsx - Message Limits: Modify limits in
server/utils/messageManager.js - Rate Limiting: Adjust limits in
server/server.js
-
Set environment variables:
PORT(default: 5000)NODE_ENV=production
-
Update CORS settings in
server/server.jsto match your frontend domain
- Update the Socket.IO connection URL in
src/contexts/SocketContext.tsx - Build the application:
npm run build - Serve the
distfolder with a static file server
- Enable HTTPS in production
- Configure proper CORS origins
- Set up rate limiting
- Use environment variables for sensitive config
- Consider adding authentication for user management
GET /health- Server health check with statistics
join- Join chat with usernamesendMessage- Send a new messagetyping- Toggle typing indicatorping- Connection health check
newMessage- Broadcast new messageuserJoined- User joined notificationuserLeft- User left notificationuserListUpdate- Updated list of online usersuserTyping- Typing indicator update
- Instant message delivery using WebSocket
- Automatic reconnection on connection loss
- Typing indicators with smart timeout
- Connection status monitoring
- Unique username validation
- Session persistence across page reloads
- Online user tracking
- Join/leave notifications
- Message length validation (1000 chars max)
- HTML sanitization for security
- Timestamp formatting (smart relative time)
- Auto-scroll to latest messages
- Message history (last 1000 messages)
- Responsive design for all screen sizes
- Dark/light theme with system preference
- Smooth animations and transitions
- Accessible keyboard navigation
- Sound notifications (can be disabled)
- Emoji picker with popular emojis
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Make your changes and test them
- Commit your changes:
git commit -m 'Add feature' - Push to the branch:
git push origin feature-name - Submit a pull request
This project is open source and available under the MIT License.
- Socket.IO team for the excellent real-time library
- Tailwind CSS for the utility-first CSS framework
- Lucide React for the beautiful icon set
- React team for the amazing frontend library
Made by β€οΈ with Ajay Dhangar using React, Node.js, and Socket.IO
