A modern, full-stack real-time chat application built with React, Node.js, and WebSocket technology. Connect with friends, send messages, and see who's online instantly.
Live Demo: https://chat-app-5ufs.onrender.com/
GitHub Repository: https://github.com/somandhir/chat-app
- User Authentication - Secure JWT-based authentication with bcryptjs password encryption
- Real-Time Messaging - Instant message delivery using Socket.io
- Online Status - See who's currently online in real-time
- Profile Management - Update profile picture with Cloudinary integration
- Responsive Design - Beautiful UI built with Tailwind CSS and DaisyUI
- Settings Page - User preference management and personalization
- User-Friendly - Intuitive interface with loading states and error handling
- Mobile Optimized - Works seamlessly on desktop and mobile devices
- React 19 - JavaScript library for building user interfaces
- Vite - Next generation frontend tooling
- Tailwind CSS - Utility-first CSS framework
- DaisyUI - Tailwind CSS component library
- React Router - Client-side routing
- Socket.io Client - Real-time communication
- Zustand - State management
- Axios - HTTP client
- React Hot Toast - Toast notifications
- Lucide React - Beautiful SVG icons
- Node.js - JavaScript runtime
- Express.js - Web application framework
- MongoDB - NoSQL database with Mongoose ODM
- Socket.io - Real-time bidirectional communication
- JWT - JSON Web Token authentication
- Bcryptjs - Password hashing
- Cloudinary - Cloud image storage
- Cookie Parser - Parse HTTP request cookies
- CORS - Cross-Origin Resource Sharing
- Dotenv - Environment variables
chat-app/
βββ backend/
β βββ src/
β β βββ controllers/
β β β βββ auth.controller.js # Authentication logic
β β β βββ message.controller.js # Message handling
β β βββ lib/
β β β βββ cloudinary.js # Cloudinary configuration
β β β βββ db.js # Database connection
β β β βββ socket.js # Socket.io setup
β β β βββ utils.js # Utility functions
β β βββ middleware/
β β β βββ auth.middleware.js # JWT verification
β β βββ models/
β β β βββ user.model.js # User schema
β β β βββ message.model.js # Message schema
β β βββ routes/
β β β βββ auth.route.js # Auth endpoints
β β β βββ message.route.js # Message endpoints
β β βββ index.js # Server entry point
β βββ .env # Environment variables
β βββ package.json
β
βββ frontend/
β βββ src/
β β βββ components/
β β β βββ ChatContainer.jsx # Main chat interface
β β β βββ ChatHeader.jsx # Chat header with user info
β β β βββ MessageInput.jsx # Message input form
β β β βββ Navbar.jsx # Top navigation
β β β βββ NoChatSelected.jsx # Empty state
β β β βββ Sidebar.jsx # User list sidebar
β β β βββ Skeletons/ # Loading skeleton components
β β βββ pages/
β β β βββ HomePage.jsx # Main chat page
β β β βββ LoginPage.jsx # Login form
β β β βββ SignUpPage.jsx # Registration form
β β β βββ ProfilePage.jsx # User profile
β β β βββ SettingsPage.jsx # User settings
β β βββ store/
β β β βββ useAuthStore.js # Authentication state
β β β βββ useChatStore.js # Chat state
β β βββ lib/
β β β βββ axios.js # Axios configuration
β β βββ App.jsx # Main component
β β βββ main.jsx # Entry point
β βββ public/ # Static assets
β βββ vite.config.js
β βββ eslint.config.js
β βββ package.json
β
βββ README.md
Before you begin, make sure you have the following installed:
- Node.js (v16 or higher)
- npm or yarn package manager
- MongoDB instance (local or MongoDB Atlas)
- Cloudinary account for image hosting
- Clone the repository
git clone https://github.com/somandhir/chat-app.git
cd chat-app- Set up the Backend
cd backend
npm installCreate a .env file in the backend directory:
PORT=5001
MONGODB_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret_key
CLOUDINARY_CLOUD_NAME=your_cloudinary_cloud_name
CLOUDINARY_API_KEY=your_cloudinary_api_key
CLOUDINARY_API_SECRET=your_cloudinary_api_secret
NODE_ENV=development- Set up the Frontend
cd ../frontend
npm installCreate a .env file in the frontend directory (if needed):
VITE_API_URL=http://localhost:5001Terminal 1 - Backend:
cd backend
npm run devServer runs on http://localhost:5001
Terminal 2 - Frontend:
cd frontend
npm run devFrontend runs on http://localhost:5173
Frontend:
cd frontend
npm run buildThis creates a dist folder that the backend serves in production.
POST /signup- Register a new userPOST /login- Login userPOST /logout- Logout userGET /check-auth- Verify authentication statusPUT /update-profile- Update user profile
GET /users- Get all usersGET /:id- Get messages with specific userPOST /send/:id- Send message to user
Real-time communication is handled through Socket.io:
connection- User connects to socketdisconnect- User disconnectsnewMessage- New message receiveduserOnline- User comes onlineuserOffline- User goes offline
The application is deployed on Render:
- Live URL: https://chat-app-5ufs.onrender.com/
- Push your code to GitHub
- Connect your GitHub repository to Render
- Set environment variables in Render dashboard
- Deploy automatically or manually
- Frontend is served from the backend in production mode
- Password Encryption - Bcryptjs for secure password hashing
- JWT Authentication - Secure token-based authentication
- HTTP-Only Cookies - Secure cookie storage for tokens
- CORS Protection - Cross-origin resource sharing configured
- Input Validation - Server-side validation for all inputs
- Environment Variables - Sensitive data in .env files
PORT=5001
MONGODB_URI=mongodb+srv://user:password@cluster.mongodb.net/chat-app
JWT_SECRET=your_super_secret_jwt_key_here
CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret
NODE_ENV=production
- Verify MongoDB connection string in
.env - Check MongoDB Atlas IP whitelist includes your IP
- Ensure MongoDB is running if using local instance
- Verify backend is running on correct port
- Check CORS configuration in backend
- Ensure API URL is correct in frontend configuration
- Verify Cloudinary credentials in
.env - Check image file size (should be < 5MB)
- Ensure Cloudinary API key is valid
- Clear browser cache and cookies
- Check WebSocket compatibility in your network
- Verify Socket.io port is not blocked by firewall
- Message search functionality
- File sharing capabilities
- Voice and video calling
- Group chat support
- Push notifications
- Dark mode toggle
- Mobile app version
- Message reactions and emojis
Contributions are welcome! Feel free to:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the ISC License - see the LICENSE file for details.
Somandhir
GitHub: @somandhir
If you encounter any issues or have questions:
- Open an issue on GitHub Issues
Visit the live demo to see the application in action!