A modern, full-stack real-time chat application built with React, Express.js, MongoDB, and Socket.IO. Features user authentication, real-time messaging, follow/unfollow system, and user profiles with Clerk authentication integration.
- Real-time Messaging: Instant message delivery using Socket.IO
- User Authentication: Secure authentication with Clerk
- Follow/Unfollow System: Connect with other users
- User Profiles: Customizable profiles with bio and profile pictures
- Online Status: See who's online in real-time
- Search Users: Find and connect with other users
- Responsive Design: Optimized for desktop, tablet, and mobile devices
- File Uploads: Profile picture uploads with Cloudinary integration
- React with Vite
- Clerk for authentication
- Socket.IO Client for real-time communication
- Axios for API calls
- Tailwind CSS for styling
- Node.js with Express.js
- MongoDB with Mongoose
- Socket.IO for real-time features
- JWT for authentication tokens
- Cloudinary for file uploads
- CORS enabled for cross-origin requests
Real-Time-Chat/
βββ client/ # React frontend
β βββ src/
β β βββ components/ # React components
β β β βββ Sidebar.jsx # User list and search
β β β βββ ChatContainer.jsx # Chat interface
β β β βββ RightSidebar.jsx # Additional UI elements
β β βββ context/ # React context providers
β β β βββ AuthContext.jsx # Authentication context
β β β βββ ChatContext.jsx # Chat state management
β β βββ pages/ # Page components
β β β βββ LoginPage.jsx # Login page
β β βββ App.jsx # Main app component
β β βββ main.jsx # App entry point
β β βββ index.css # Global styles
β βββ package.json
β βββ vite.config.js
βββ server/ # Express.js backend
β βββ controllers/ # Route controllers
β β βββ user.controller.js # User-related operations
β βββ middleware/ # Custom middleware
β β βββ auth.js # Authentication middleware
β βββ model/ # Database models
β β βββ user.model.js # User schema
β βββ routes/ # API routes
β β βββ user.routes.js # User routes
β βββ utils/ # Utility functions
β β βββ asyncHandler.js # Async error handling
β β βββ cloudinary.js # Cloudinary configuration
β β βββ ApiError.js # Custom error class
β β βββ ApiResponse.js # Standard response format
β βββ lib/ # Library files
β β βββ db.js # Database connection
β βββ server.js # Main server file
β βββ package.json
βββ .env.example # Environment variables template
βββ README.md
- Node.js (v16 or later)
- npm or yarn
- MongoDB database
- Clerk account for authentication
- Cloudinary account for file uploads
-
Clone the repository
git clone <your-repository-url> cd Real-Time-Chat
-
Install backend dependencies
cd server npm install -
Install frontend dependencies
cd ../client npm install -
Set up environment variables
- Copy
.env.exampleto.envin both client and server directories - Fill in your actual values for all environment variables
- Copy
-
Start the development servers
Backend (from server directory):
npm run dev
Frontend (from client directory):
npm run dev
MONGODB_URL=your_mongodb_connection_string
REFRESH_TOKEN_SECRET=your_jwt_refresh_token_secret
REFRESH_TOKEN_EXPIRY=7d
CLOUDINARY_API_NAME=your_cloudinary_cloud_name
CLOUDINARY_API_KEY=your_cloudinary_api_key
CLOUDINARY_API_SECRET=your_cloudinary_api_secret
PORT=5000
NODE_ENV=developmentVITE_BACKEND_URL=http://localhost:5000
VITE_CLERK_PUBLISHABLE_KEY=your_clerk_publishable_key- Create an account at Clerk
- Create a new application and get your publishable key
- Add the key to your client
.envfile asVITE_CLERK_PUBLISHABLE_KEY
- Create an account at Cloudinary
- Get your cloud name, API key, and API secret from the dashboard
- Add these values to your server
.envfile
- Use MongoDB Atlas (cloud) or local MongoDB installation
- Get your connection string and add it to server
.envasMONGODB_URL
npm run dev # Start development server
npm start # Start production server
npm test # Run testsnpm run dev # Start development server
npm run build # Create production build
npm run preview # Preview production build- Set all environment variables in your deployment platform
- Deploy the server directory
- Update client's
VITE_BACKEND_URLto point to your deployed backend
- Set environment variables in your deployment platform
- Deploy the client directory
- Ensure CORS is properly configured on the backend
- Fork the project
- Create your 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 MIT License - see the LICENSE file for details.
If you have any questions or run into issues, please:
- Check the console for error messages
- Ensure all environment variables are properly set
- Verify that MongoDB and other services are running
- Open an issue on GitHub with detailed information about the problem
- Clerk for authentication services
- Cloudinary for file upload services
- Socket.IO for real-time communication
- MongoDB for database services