A modern, real-time chat application built with React and Node.js. Experience seamless messaging with real-time notifications, user authentication, and a beautiful responsive UI.
- Features
- Tech Stack
- Project Structure
- Prerequisites
- Installation & Setup
- Environment Variables
- Running the Application
- Project Architecture
- API Endpoints
- Usage Guide
- Contributing
- 💬 Real-time Messaging: Instant message delivery using Socket.io
- 🔐 User Authentication: Secure JWT-based authentication with password hashing (bcryptjs)
- 👤 User Profiles: Upload and manage profile pictures via Cloudinary
- 📧 Email Notifications: Email verification and notifications using Resend
- 🛡️ Security: Rate limiting and protection against abuse using Arcjet
- 📱 Responsive Design: Beautiful UI built with React, TailwindCSS + DaisyUI
- ⚙️ State Management: Efficient state management with Zustand
- ⏳ Loading States: Skeleton loading screens for better UX
- ⚛️ Framework: React 19
- ⚡ Build Tool: Vite
- 🎨 Styling: TailwindCSS + DaisyUI
- 🔄 State Management: Zustand
- 🌐 HTTP Client: Axios
- 🔌 Real-time Communication: Socket.io Client
- 🗺️ Routing: React Router v7
- 🎯 UI Icons: Lucide React
- 🔔 Notifications: React Hot Toast
- 🖥️ Runtime: Node.js
- 🚀 Framework: Express.js v5
- 🗄️ Database: MongoDB with Mongoose ODM
- 🔌 Real-time: Socket.io
- 🔑 Authentication: JWT (jsonwebtoken) + bcryptjs
- 🖼️ File Upload: Cloudinary
- 📨 Email Service: Resend
- 🛡️ Security: Arcjet
- 🔧 Dev Tool: Nodemon
- 🔗 Middleware: Cookie Parser, CORS
CHATIFY-APP/
├── backend/
│ ├── src/
│ │ ├── server.js # Main server entry point
│ │ ├── controllers/
│ │ │ ├── auth.controller.js # Authentication logic
│ │ │ └── message.controller.js # Message handling
│ │ ├── routes/
│ │ │ ├── auth.routes.js # Auth endpoints
│ │ │ └── message.routes.js # Message endpoints
│ │ ├── models/
│ │ │ ├── User.js # User schema
│ │ │ └── Message.js # Message schema
│ │ ├── middleware/
│ │ │ ├── auth.middleware.js # JWT verification
│ │ │ ├── arcjet.middleware.js # Rate limiting
│ │ │ └── socket.auth.middleware.js # Socket auth
│ │ ├── lib/
│ │ │ ├── db.js # MongoDB connection
│ │ │ ├── socket.js # Socket.io setup
│ │ │ ├── cloudinary.js # Image upload config
│ │ │ ├── resend.js # Email service config
│ │ │ ├── arcjet.js # Security config
│ │ │ └── util.js # Utility functions
│ │ └── emails/
│ │ ├── emailHandler.js # Email sending logic
│ │ └── emailTemplate.js # Email templates
│ ├── .env # Environment variables
│ └── package.json
│
├── frontend/
│ ├── src/
│ │ ├── main.jsx # React app entry point
│ │ ├── App.jsx # Main app component
│ │ ├── index.css # Global styles
│ │ ├── pages/
│ │ │ ├── ChatPage.jsx # Main chat interface
│ │ │ ├── LogInPage.jsx # Login page
│ │ │ └── SignUpPage.jsx # Sign up page
│ │ ├── components/
│ │ │ ├── ChatContainer.jsx # Chat messages display
│ │ │ ├── ChatHeader.jsx # Chat header with user info
│ │ │ ├── ChatList.jsx # List of conversations
│ │ │ ├── MessageInput.jsx # Message input field
│ │ │ ├── ContactList.jsx # Available contacts
│ │ │ ├── ActiveTabSwitch.jsx # Tab switcher
│ │ │ ├── ProfileHeader.jsx # User profile section
│ │ │ ├── NoChatFound.jsx # Empty state
│ │ │ ├── NoChatHistory.jsx # No messages state
│ │ │ ├── PageLoader.jsx # Page loading spinner
│ │ │ ├── BorderAnimatedContainer.jsx # Animated UI
│ │ │ ├── MessagesLoadingSkeleton.jsx # Message skeleton
│ │ │ └── UsersLoadingSkeleton.jsx # User skeleton
│ │ ├── hooks/
│ │ │ └── useKeyboardSound.js # Keyboard sound effect hook
│ │ ├── lib/
│ │ │ └── axios.js # Axios instance with config
│ │ ├── store/
│ │ │ ├── useAuthStore.js # Auth state management
│ │ │ └── useChatStore.js # Chat state management
│ │ └── public/
│ │ └── sounds/ # Audio assets
│ ├── vite.config.js
│ ├── tailwind.config.js
│ ├── postcss.config.js
│ └── package.json
│
└── package.json (root)
Before you begin, ensure you have the following installed:
- 🖥️ Node.js (v18 or higher) - Download here
- 📦 npm or yarn - Comes with Node.js
- 🗄️ MongoDB (Local or Atlas Cloud) - Setup MongoDB
- 🖼️ Cloudinary Account - Sign up here (for image uploads)
- 📧 Resend Account - Sign up here (for email services)
- 🛡️ Arcjet Account - Sign up here (for security/rate limiting)
cd CHATIFY-APPcd backend
npm installcd ../frontend
npm installcd ..Create a .env file in the backend directory with the following variables:
# Server Configuration
PORT=5000
NODE_ENV=development
# Database
MONGODB_URI=mongodb+srv://<username>:<password>@<cluster>.mongodb.net/chatify
# JWT
JWT_SECRET=your_jwt_secret_key_here
# Cloudinary (Image Upload)
CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret
# Resend (Email Service)
RESEND_API_KEY=your_resend_api_key
# Arcjet (Security/Rate Limiting)
ARCJET_KEY=your_arcjet_key
# Client URL (for CORS)
CLIENT_URL=http://localhost:5173
# Email Configuration
SENDER_EMAIL=noreply@yourdomain.comIf you need to configure the API endpoint, create a .env file in the frontend directory:
VITE_API_URL=http://localhost:5000/apiTerminal 1 - Start Backend:
cd backend
npm run devThe backend server will start on http://localhost:5000
Terminal 2 - Start Frontend:
cd frontend
npm run devThe frontend will be available at http://localhost:5173
To build the frontend for production deployment:
cd frontend
npm run buildThen start the backend, which will serve the built frontend files.
-
🔐 Authentication
- User signs up/logs in on
SignUpPageorLogInPage - Credentials sent to backend via Axios
- JWT token stored in cookies
- User redirected to
ChatPage
- User signs up/logs in on
-
💬 Chat Interface
ChatPagedisplays three main sections:ContactList: Available users to chat withChatList: Recent conversationsChatContainer: Active conversation messages
-
⚡ Real-time Messaging
- Socket.io connection established with authentication
- Messages sent and received in real-time
- UI updates automatically via Zustand state management
-
🔄 State Management (Zustand Stores)
useAuthStore: Manages user authentication and profileuseChatStore: Manages conversations and messages
-
🔑 Authentication Flow
- User registration: Password hashed with bcryptjs
- User login: JWT token generated
- Protected routes verified via
auth.middleware.js
-
💾 Message Flow
- GET messages: Retrieve conversation history from MongoDB
- POST message: Save message to MongoDB and broadcast via Socket.io
-
🔌 Real-time Socket Events
connection: User connects to Socket.iosend_message: Emit message to recipientreceive_message: Listen for incoming messagesuser_online_status: Update user online status
-
🛡️ Security
- Arcjet middleware protects against rate limiting and abuse
- CORS enabled for frontend origin only
- Socket authentication via middleware
| Method | Endpoint | Description |
|---|---|---|
| POST | /signup |
Register new user |
| POST | /login |
User login |
| POST | /logout |
User logout |
| GET | /me |
Get current user profile |
| PUT | /profile |
Update user profile |
| POST | /profile/upload |
Upload profile picture |
| Method | Endpoint | Description |
|---|---|---|
| GET | /users |
Get all available users |
| GET | /:userId |
Get messages with specific user |
| POST | /send/:id |
Send message to user |
- Visit the application URL
- Click "Sign Up"
- Enter your email, password, and username
- 📧 Email verification (if enabled)
- Create your account
- Select a user from the Contacts list
- Type your message in the Message Input field
- Press Enter or click Send button
- Messages appear in real-time for both users via Socket.io
- Click on your profile icon
- Click "Upload Picture"
- Select an image from your device
- Profile picture updates immediately via Cloudinary
- 🟢 Green indicator shows when users are online
- Status updates in real-time via Socket.io
Backend:
- 🔄
npm run dev- Start development server with hot reload via Nodemon - 🚀
npm start- Start production server
Frontend:
- ⚡
npm run dev- Start development server with Vite - 📦
npm run build- Build for production - 🔍
npm run lint- Run ESLint - 👀
npm run preview- Preview production build
- Backend: Nodemon automatically restarts the server on file changes
- Frontend: Vite provides instant hot module replacement (HMR)
- Backend: Add
console.log()statements or use a debugger - Frontend: Use React Developer Tools browser extension
- Network: Check browser DevTools Network tab for API calls
We welcome contributions! Here's how to get started:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the ISC License - see the LICENSE file for details.
Backend won't start:
- Check if port 5000 is already in use
- Verify MongoDB connection string in
.env - Ensure all required environment variables are set
Frontend won't connect to backend:
- Check if backend is running on port 5000
- Verify
CLIENT_URLin backend.envmatches frontend URL - Check browser console for CORS errors
Messages not sending:
- Verify Socket.io connection is established
- Check browser console for errors
- Ensure user is authenticated
Database connection error:
- Verify MongoDB URI in
.env - Check MongoDB credentials
- Ensure MongoDB service is running
For issues, questions, or suggestions, please open an issue in the repository.
Happy Chatting! 🚀
