# π¬ Chatify (MERN + Socket.IO)
π Authentication β’ π¬ Real-time messaging β’ π’ Online users β’ πΌοΈ Cloudinary uploads
Chatify is a full-stack real-time chat app built with Node.js, Express, MongoDB, React (Vite), and Socket.IO.
---
## π Live Website
- **Frontend (Vercel):** https://chatify-plum.vercel.app/
- **Backend (Render):** https://chatify-backend-4qij.onrender.com/
---
π A production-ready real-time chat app with a scalable MERN backend and low-latency Socket.IO messaging.
## β¨ Features
- π Cookie-based JWT authentication (signup/login/logout)
- π¬ Real-time chat with Socket.IO
- π’ Online user tracking
- πΌοΈ Profile picture upload via Cloudinary
- π¨ Modern UI (React + Tailwind) with Zustand state management
---
## π§° Tech Stack
- **Backend:** Node.js, Express, MongoDB (Mongoose), JWT (cookie-based), Socket.IO
- **Frontend:** React, Vite, Zustand, Axios, Tailwind CSS, Socket.IO Client
- **Media:** Cloudinary (uploads stored in Cloudinary, DB stores image URL)
---
## π Project Structure
```text
LIVE_CHAT/
βββ Readme.md
βββ Home.png
βββ Login.png
βββ Backend/ # Express + MongoDB + Socket.IO
β βββ src/
β β βββ app.js # Express app + socket bootstrap
β β βββ 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/ # React (Vite) client
βββ 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 (Local)
## β
Prerequisites
- Node.js installed
- MongoDB connection string (Atlas or local)
- Cloudinary account
### 1) Backend Setup
```bash
cd Backend
npm install
```
Create `Backend/.env` (copy from `Backend/.env.example`):
```bash
copy .env.example .env
```
Start backend:
```bash
npm start
```
### 2) Frontend Setup
```bash
cd Frontend/vite-project
npm install
```
Create `Frontend/vite-project/.env` (copy from `.env.example`):
```bash
copy .env.example .env
```
Start frontend:
```bash
npm run dev
```
---
## π Environment Variables
### Backend (`Backend/.env`)
| Variable | Required | Description |
| --- | --- | --- |
| `PORT` | β | Server port |
| `MONGODB_URI` | β
| MongoDB connection string |
| `secretKey` | β
| JWT secret used to sign cookies |
| `CLIENT_URL` | β | Frontend URL allowed by CORS (Vercel domain) |
| `CLOUDINARY_CLOUD_NAME` | β
| Cloudinary cloud name |
| `CLOUDINARY_API_KEY` | β
| Cloudinary API key |
| `CLOUDINARY_SECRET_KEY` | β
| Cloudinary API secret |
### Frontend (`Frontend/vite-project/.env`)
| Variable | Required | Description |
| --- | --- | --- |
| `VITE_API_BASE_URL` | β
| Backend API base URL (e.g. `http://localhost:5000/api`) |
| `VITE_SOCKET_URL` | β
| Backend socket URL (e.g. `http://localhost:5000`) |
---
## π’ Deployment
### Backend (Render)
1. Deploy `Backend/` as a Node service.
2. Set env vars from `Backend/.env` in Render dashboard.
3. Set `CLIENT_URL` = your Vercel frontend domain.
### Frontend (Vercel)
1. Deploy `Frontend/vite-project/`.
2. Set `VITE_API_BASE_URL` and `VITE_SOCKET_URL` to your deployed Render backend URLs.
---
## β‘ Challenges Faced
- Fixed CORS issues during deployment
- Managed socket connections across environments
- Handled cookie-based authentication in production
## π§© Common Issues
- **CORS errors:** make sure backend `CLIENT_URL` matches your deployed frontend domain.
- **Socket not connecting:** ensure `VITE_SOCKET_URL` points to backend.
- **Uploads failing:** verify Cloudinary env vars.
---
## π¨βπ» Author
Built by Avinash.