A modern, full-stack real-time messaging application built with React, Node.js, Socket.io, and MongoDB. Features infinite scroll pagination, responsive mobile-first design, and real-time bidirectional communication.
- π User Authentication - Secure registration and login with JWT tokens
- π¬ Real-Time Messaging - Instant bidirectional communication via WebSocket (Socket.io)
- π₯ User Directory - Searchable list of all active users with online status
- βΎοΈ Infinite Scroll - Pagination for both users and messages for optimal performance
- π Online Status - Real-time user availability indicators
- π― User Profiles - Profile creation with avatar generation and customization
- π± Fully Responsive Design - Mobile, tablet, and desktop optimized
- π¨ Dark Theme - Modern dark mode interface with Tailwind CSS
- β‘ Performance Optimized - Lazy loading, infinite scroll, efficient re-renders
- π Real-Time Sync - Instant UI updates across all connected clients
- π± WhatsApp-Style Layout - Mobile shows chat list, taps open chat (with back button)
- π‘οΈ Secure Authentication - Password hashing with bcryptjs, JWT tokens
- ποΈ MongoDB Integration - NoSQL database for scalable data storage
- π Socket.io Real-Time - Full-duplex communication channels
- β° Inactivity Cleanup - Automatic cleanup of inactive user sessions via cron jobs
- π Production Ready - Error handling, middleware, async utilities
| Technology | Purpose |
|---|---|
| React 19 | UI library |
| Redux Toolkit | State management |
| Tailwind CSS | Styling |
| Vite | Build tool & dev server |
| Socket.io Client | Real-time communication |
| Axios | HTTP requests |
| React Router | Navigation |
| React Hot Toast | Notifications |
| React Infinite Scroll | Pagination component |
| React Icons | Icon library |
| Technology | Purpose |
|---|---|
| Express.js | Web framework |
| Node.js | Runtime environment |
| MongoDB | NoSQL database |
| Socket.io | Real-time communication |
| JWT | Authentication tokens |
| Bcryptjs | Password hashing |
| Mongoose | MongoDB ODM (optional) |
| Node-cron | Scheduled tasks |
| Nodemon | Dev server auto-reload |
Before you begin, ensure you have:
- Node.js v18.0.0 or higher
- npm v9.0.0 or higher
- MongoDB v5.0+ (local or cloud - Atlas)
- Git for version control
Verify installations:
node --version # Should be v18+
npm --version # Should be v9+git clone https://github.com/mk-manishkumar/echosphere.git
cd echospherecd server
# Install dependencies
npm install
# Create .env file
cp .env.sample .env
# Configure environment variables (see Environment Variables section)
# Edit .env with your database URL, JWT secret, etc.
# Start development server
npm run dev
# Server runs on http://localhost:5000cd ../client
# Install dependencies
npm install
# Create .env file (if needed for API URL)
cp .env.sample .env
# Start development server
npm run dev
# App runs on http://localhost:5173Both servers should now be running. Open http://localhost:5173 in your browser.
# Server Configuration
PORT=5000
NODE_ENV=development
# Database
MONGODB_URI=mongodb://localhost:27017/echosphere
# OR for MongoDB Atlas:
# MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/echosphere
# JWT Configuration
JWT_SECRET=your_super_secret_jwt_key_here_min_32_chars
JWT_EXPIRES=7d
COOKIE_EXPIRES=7
# CORS
CORS_ORIGIN=http://localhost:5173
# Socket.io
SOCKET_CORS_ORIGIN=http://localhost:5173VITE_API_URL=http://localhost:5000echosphere/
βββ client/ # React Frontend
β βββ src/
β β βββ components/ # Reusable components
β β β βββ ProtectedRoute.jsx # Route protection
β β β βββ utilities/
β β β βββ axiosInstance.js # API client
β β βββ pages/
β β β βββ authentication/ # Login, Signup
β β β βββ home/ # Main chat interface
β β β β βββ Home.jsx # Main layout
β β β β βββ UserSidebar.jsx # Users list
β β β β βββ MessageContainer.jsx
β β β β βββ SendMessage.jsx
β β β β βββ User.jsx
β β β βββ profile/ # User profile
β β βββ store/ # Redux store
β β β βββ store.js # Store configuration
β β β βββ socketMiddleware.js # Socket.io integration
β β β βββ slice/ # Redux slices
β β β βββ user/
β β β βββ message/
β β β βββ socket/
β β βββ App.jsx # Main app component
β β βββ router.jsx # Route configuration
β β βββ main.jsx # Entry point
β βββ package.json
β βββ vite.config.js
β βββ tailwind.config.js
β
βββ server/ # Express Backend
β βββ controllers/ # Business logic
β β βββ user.controller.js # User operations
β β βββ message.controller.js # Message operations
β βββ models/ # MongoDB models
β β βββ User.model.js
β β βββ Message.model.js
β β βββ Conversation.model.js
β βββ routes/ # API routes
β β βββ user.route.js
β β βββ message.route.js
β βββ middlewares/ # Express middlewares
β β βββ auth.middleware.js # JWT verification
β β βββ error.middleware.js # Error handling
β βββ socket/ # Socket.io handlers
β β βββ socket.js
β βββ cron/ # Scheduled tasks
β β βββ inactivityCleanup.cron.js
β βββ utils/ # Utility functions
β β βββ asyncHandler.utility.js
β β βββ errorHandler.utility.js
β βββ db/
β β βββ connection1.db.js # MongoDB connection
β βββ server.js # Entry point
β βββ package.json
β
βββ RESPONSIVE_LAYOUT.md # Responsive design documentation
βββ README.md # This file
| Method | Endpoint | Description |
|---|---|---|
| POST | /user/register |
Create new account |
| POST | /user/login |
Login to account |
| POST | /user/logout |
Logout from account |
| GET | /user/get-profile |
Get current user profile |
| Method | Endpoint | Description |
|---|---|---|
| GET | /user/get-other-users?skip=0&limit=10 |
Get users list (paginated) |
| GET | /user/check-username?username=test |
Check username availability |
| PUT | /user/update-profile |
Update user profile |
| PUT | /user/change-password |
Change password |
| DELETE | /user/account |
Delete account |
| Method | Endpoint | Description |
|---|---|---|
| GET | /message/get-messages/:receiverId?skip=0&limit=20 |
Get conversation messages (paginated) |
| POST | /message/send/:receiverId |
Send message |
| Event | Payload | Description |
|---|---|---|
connect |
- | User connects to socket |
user-online |
{ userId } |
Notify user is online |
disconnect |
- | User disconnects |
| Event | Payload | Description |
|---|---|---|
onlineUsers |
[userId, ...] |
List of online users |
newMessage |
{ message object } |
New incoming message |
userOnline |
{ userId } |
User came online |
userOffline |
{ userId } |
User went offline |
Both users and messages use infinite scroll for performance:
Users List:
- Loads 10 users initially
- Fetches next 10 when scrolled to bottom
- Prevents loading during search
Messages:
- Loads 20 most recent messages
- Loads older messages when scrolled to top
- Shows "Beginning of conversation" when all loaded
- Desktop (β₯768px): Split layout with sidebar + chat
- Tablet/Mobile (<768px): Full-screen chat with back button
- Smooth transitions between layouts
- Socket.io maintains persistent connection
- Bi-directional communication for instant updates
- Online/offline status tracking
- Real-time message delivery
{
_id: ObjectId,
fullName: String,
username: String (unique),
password: String (hashed),
email: String,
gender: String ("male" | "female"),
avatar: String (URL),
last_login_at: Date,
createdAt: Date,
updatedAt: Date
}{
_id: ObjectId,
senderId: ObjectId (ref: User),
receiverId: ObjectId (ref: User),
message: String,
createdAt: Date,
updatedAt: Date
}{
_id: ObjectId,
participants: [ObjectId, ObjectId] (ref: User),
messages: [ObjectId] (ref: Message),
createdAt: Date,
updatedAt: Date
}- Ensure MongoDB is running
- Check MONGODB_URI in
.env - Verify credentials for MongoDB Atlas
- Change port in
.envor use:PORT=3001 npm run dev - Kill existing process:
lsof -i :5000thenkill -9 <PID>
- Verify backend is running
- Check CORS settings match frontend URL
- Clear browser cache and restart
- Already fixed! Redux state resets on route change
- See user.slice.js
resetUsersaction
- Check infinite scroll implementation
- Verify MongoDB has messages
- Check browser console for errors
- β Infinite scroll prevents loading entire lists
- β Lazy loading components with React.lazy
- β Redux for state management efficiency
- β Memoization for expensive computations
- β Image optimization via avatar generation
- β CSS optimization with Tailwind purge
- β JWT authentication with HttpOnly cookies
- β Password hashing with bcryptjs (10 rounds)
- β CORS protection
- β Input validation on frontend & backend
- β Protected routes with authentication
- β Error messages don't leak sensitive info
cd client
npm run lint- Register new account
- Login with credentials
- Search for users
- Send message to user
- Receive message in real-time
- Check online/offline status
- Edit profile
- Responsive on mobile
- Logout
- Fork the repository
- Create feature branch:
git checkout -b feature/AmazingFeature - Commit changes:
git commit -m 'Add AmazingFeature' - Push to branch:
git push origin feature/AmazingFeature - Open Pull Request
This project is licensed under the The Unlicense - see LICENSE file for details.
Manish Kumar
- GitHub: @mk-manishkumar
- Repository: echosphere
- Socket.io for real-time communication
- Tailwind CSS for styling framework
- Redux Toolkit for state management
- React for UI library
- MongoDB for database
For issues, questions, or suggestions:
- Check Troubleshooting section
- Review RESPONSIVE_LAYOUT.md
- Open an issue on GitHub
- Contact: GitHub Issues
Future Features:
- Group chats
- File/image sharing
- Message encryption (E2E)
- Typing indicators
- Read receipts
- Message search
- Voice/video calls
- User blocking
- Message reactions
Last Updated: April 2026
Version: 1.0.0
β If you like this project, please give it a star on GitHub!