π Authentication β’ π¬ Real-Time Messaging β’ π’ Online Users β’ πΌοΈ Cloudinary Uploads
Chatify is a full-stack real-time chat application built with Node.js, Express, MongoDB, React, Vite, Socket.IO, Zustand, and Cloudinary.
--- ## π Live Demo ### Frontend π [**Chatify β Live Website**](https://chatify-plum.vercel.app/) ### Backend π [**Chatify β Backend**](https://chatify-backend-4qij.onrender.com/) --- ## π Overview **Chatify** is a full-stack real-time messaging application built using the MERN stack and Socket.IO. The application provides a modern chat experience with authentication, real-time communication, online user tracking, profile image uploads, and client-side state management. The project uses a separated frontend and backend architecture, with the React frontend deployed on Vercel and the Node.js/Express backend deployed on Render. --- ## β¨ Features - π Cookie-based JWT authentication - π User signup and login - πͺ Secure logout functionality - π¬ Real-time one-to-one messaging - β‘ Socket.IO-based communication - π’ Online user tracking - πΌοΈ Profile picture uploads using Cloudinary - π¨ Responsive React interface - π§ Zustand state management - π Axios-based API communication - ποΈ MongoDB persistence with Mongoose - π Separate production frontend and backend deployment --- ## π§° Tech Stack ### Frontend | Technology | Purpose | |---|---| | React | User interface | | Vite | Frontend tooling | | Zustand | State management | | Axios | API communication | | Tailwind CSS | Styling | | Socket.IO Client | Real-time communication | ### Backend | Technology | Purpose | |---|---| | Node.js | Runtime | | Express.js | Backend framework | | MongoDB | Database | | Mongoose | MongoDB ODM | | JWT | Authentication | | Socket.IO | Real-time communication | ### Media | Technology | Purpose | |---|---| | Cloudinary | Profile image storage and delivery | --- ## ποΈ Architecture ```text ββββββββββββββββββββββββββ β React Frontend β β Vite + Zustand + UI β ββββββββββββββ¬ββββββββββββ β REST API + Socket.IO β ββββββββββββββΌββββββββββββ β Node.js + Express β β β β Authentication β β REST APIs β β Socket.IO Server β βββββββββββ¬ββββββββ¬βββββββ β β β β βββββββββββΌβββ ββββΌβββββββββββββ β MongoDB β β Cloudinary β β + Mongoose β β Media β β β β Storage β ββββββββββββββ βββββββββββββββββ ``` --- ## π Project Structure ```text LIVE_CHAT/ β βββ README.md βββ Home.png βββ Login.png β βββ Backend/ β βββ src/ β β βββ app.js β β β β β βββ controllers/ β β β βββ authController.js β β β βββ messageController.js β β β β β βββ routes/ β β β βββ authRoute.js β β β βββ messageRoute.js β β β β β βββ middlewares/ β β β βββ authMiddleware.js β β β β β βββ model/ β β β βββ userModel.js β β β βββ messageModel.js β β β β β βββ lib/ β β βββ cloudinary.js β β βββ socket.js β β βββ token.js β β β βββ package.json β βββ .env.example β βββ Frontend/ βββ vite-project/ βββ src/ β βββ Pages/ β β βββ HomePage.jsx β β βββ LoginPage.jsx β β βββ ProfilePage.jsx β β βββ SignUpPage.jsx β β β βββ components/ β β βββ ChatContainer.jsx β β βββ ChatHeader.jsx β β βββ MessageInput.jsx β β βββ Messages.jsx β β βββ Navbar.jsx β β βββ NoChatSelected.jsx β β βββ Sidebar.jsx β β βββ UserChatHeader.jsx β β β βββ store/ β β βββ authStore.js β β βββ chatStore.js β β β βββ lib/ β β βββ axios.js β β βββ utils.js β β β βββ App.jsx β β βββ main.jsx β β β βββ public/ β βββ vite.config.js βββ package.json ``` --- ## πΈ Preview ### π Home / Chat  ### π Login  --- ## βοΈ Getting Started ### Prerequisites Before running the project locally, make sure you have: - Node.js installed - MongoDB Atlas or a local MongoDB instance - Cloudinary account --- ## 1. Backend Setup ```bash cd Backend npm install ``` Create: ```text Backend/.env ``` Use `Backend/.env.example` as the reference for the required variables. For PowerShell: ```powershell Copy-Item .env.example .env ``` Start the backend: ```bash npm start ``` --- ## 2. Frontend Setup Open another terminal: ```bash cd Frontend/vite-project npm install ``` Create: ```text Frontend/vite-project/.env ``` Use the provided environment example as the reference. For PowerShell: ```powershell Copy-Item .env.example .env ``` Start the frontend: ```bash npm run dev ``` --- ## π Environment Variables ### Backend Create: ```text Backend/.env ``` | Variable | Required | Description | |---|---|---| | `PORT` | No | Backend server port | | `MONGODB_URI` | Yes | MongoDB connection string | | `secretKey` | Yes | JWT secret | | `CLIENT_URL` | No | Frontend URL allowed by CORS | | `CLOUDINARY_CLOUD_NAME` | Yes | Cloudinary cloud name | | `CLOUDINARY_API_KEY` | Yes | Cloudinary API key | | `CLOUDINARY_SECRET_KEY` | Yes | Cloudinary API secret | ### Frontend Create: ```text Frontend/vite-project/.env ``` | Variable | Required | Description | |---|---|---| | `VITE_API_BASE_URL` | Yes | Backend API base URL | | `VITE_SOCKET_URL` | Yes | Backend Socket.IO URL | ### Local Example ```env VITE_API_BASE_URL=http://localhost:5000/api VITE_SOCKET_URL=http://localhost:5000 ``` --- ## π’ Deployment ### Backend β Render 1. Create a Node.js service on Render. 2. Set the backend root directory to `Backend/`. 3. Install dependencies using `npm install`. 4. Configure the required environment variables. 5. Set `CLIENT_URL` to the deployed Vercel frontend URL. 6. Deploy the backend. ### Frontend β Vercel 1. Import the repository into Vercel. 2. Set the frontend root directory to: ```text Frontend/vite-project ``` 3. Configure: ```env VITE_API_BASE_URL=https://chatify-backend-4qij.onrender.com/api VITE_SOCKET_URL=https://chatify-backend-4qij.onrender.com ``` 4. Deploy the frontend. --- ## π§ Key Technical Concepts Chatify demonstrates practical experience with: - MERN stack development - REST API architecture - JWT authentication - Cookie-based authentication - MongoDB data modeling - Mongoose - Real-time communication with Socket.IO - Online presence tracking - React component architecture - Zustand state management - Axios API integration - Cloudinary media handling - CORS configuration - Production deployment with Vercel and Render --- ## π Application Flow ```text User β React Frontend β Axios / Socket.IO Client β Node.js + Express β Authentication / API / Socket Events β MongoDB + Mongoose β Cloudinary for media β Response / Real-Time Update β React UI ``` --- ## β‘ Challenges Faced ### CORS Configuration Configured communication between the separately deployed frontend and backend. ### Real-Time Connections Handled Socket.IO connections across local and production environments. ### Cookie-Based Authentication Configured JWT-based authentication using cookies between the frontend and backend. ### Media Uploads Integrated Cloudinary for profile picture uploads and stored the resulting image URL in MongoDB. ### Production Deployment Configured separate deployments using Vercel and Render for the frontend and backend. --- ## π§© Common Issues ### CORS Errors Make sure the backend `CLIENT_URL` exactly matches the deployed frontend URL. ### Socket.IO Not Connecting Verify: ```env VITE_SOCKET_URL=https://chatify-backend-4qij.onrender.com ``` ### API Requests Failing Verify: ```env VITE_API_BASE_URL=https://chatify-backend-4qij.onrender.com/api ``` ### Cloudinary Upload Errors Check all Cloudinary credentials in the backend environment variables. --- ## π¨βπ» Author **Avinash Kumar** GitHub: https://github.com/Avinash-sdbegin ---β If you found Chatify useful, consider giving the repository a star.