A real-time chat application built with Node.js, Express, Socket.IO, and vanilla JavaScript. Features user authentication, friend system, and instant messaging with modern UI/UX.
- Real-time Messaging - Instant message delivery using Socket.IO
- User Authentication - Secure login and registration system
- Friend System - Add friends, send/accept friend requests
- Online Status - See when friends are online or last seen
- Typing Indicators - Real-time typing status
- Modern UI - Clean, responsive WhatsApp-inspired design
- Toast Notifications - User-friendly feedback system
- Message History - Persistent chat history
- Search Users - Find users by username or email
- Node.js - JavaScript runtime
- Express.js - Web framework
- Socket.IO - Real-time communication
- MongoDB - Database (assumed)
- JWT - Authentication tokens
- bcrypt - Password hashing
- Vanilla JavaScript - No framework dependencies
- Socket.IO Client - Real-time client
- CSS3 - Modern styling with animations
- Font Awesome - Icons
- HTML5 - Semantic markup
chat-cluster/
├── backend/
│ └── index.js # Express server & Socket.IO setup
├── frontend/
│ ├── index.html # Main HTML structure
│ ├── style.css # Styling and animations
│ └── js/
│ ├── config.js # Configuration & global variables
│ ├── utils.js # Utility functions
│ ├── socket.js # Socket.IO event handlers
│ ├── auth.js # Authentication logic
│ ├── friends.js # Friend management
│ ├── chat.js # Chat functionality
│ └── app.js # Application initialization
└── README.md # This file
- Node.js (v14 or higher)
- MongoDB (running instance)
- npm or yarn package manager
// Server configuration
const PORT = process.env.PORT || 3000;
const MONGODB_URI = process.env.MONGODB_URI || 'mongodb://localhost:27017/chatcluster';// API endpoint configuration
window.API_BASE = "http://localhost:3000";POST /api/register- Create new user accountPOST /api/login- User loginGET /api/me- Get current user info
GET /api/friends- Get user's friends listGET /api/friends/requests- Get pending friend requestsPOST /api/friends/request- Send friend requestPOST /api/friends/accept- Accept friend requestPOST /api/friends/reject- Reject friend request
GET /api/messages/:friendId- Get chat historyPOST /api/messages- Send message (via Socket.IO)
GET /api/users/search- Search users by username/email
authenticate- Authenticate socket connectionsend-message- Send a messagetyping- Typing indicatormark-messages-read- Mark messages as read
authenticated- Authentication successfulauthentication-error- Authentication failednew-message- Receive new messagemessage-sent- Message sent confirmationuser-typing- User typing statusfriend-online- Friend came onlinefriend-offline- Friend went offlinefriend-request- New friend requestfriend-accepted- Friend request accepted
- Login form with email/password
- Registration form with username/email/password
- Password visibility toggle
- Form validation and error handling
- Sidebar: Friends list, search, add friend button
- Chat Area: Message history, typing indicators, message input
- Header: User info, online status, logout button
- Add Friend modal with user search
- Friend Requests modal with accept/reject actions
- JWT token authentication
- Password hashing with bcrypt
- Input validation and sanitization
- CORS protection
- XSS prevention with HTML escaping
- Efficient DOM manipulation
- Debounced typing indicators
- Lazy loading of chat history
- Optimized Socket.IO event handling
- CSS animations for smooth UX
- Backend: Add routes to
backend/index.js - Frontend: Create new modules in
frontend/js/ - Styling: Add styles to
frontend/style.css - Initialize: Update
frontend/js/app.jsif needed
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
Made with ❤️ for real-time communication