β¨ Full Stack Realtime Chat App β¨ Website Link
A production-ready MERN-based chat application featuring real-time messaging, secure authentication, and online user tracking. Built with modern technologies for performance, scalability, and ease of deployment.
- π Tech Stack: MongoDB, Express.js, React (Vite), Node.js, Socket.io, TailwindCSS, DaisyUI
- π Authentication & Authorization: Secure JWT-based system with cookies
- πΎ Real-Time Messaging: Powered by Socket.io for instant communication
- π Online User Status: Live presence tracking
- π State Management: Global state handled by Zustand
- π Error Handling: Comprehensive client & server error management
- β Deployment Ready: Configured for Render (backend) and Vercel (frontend)
- β³ And much more!
Frontend
- React (Vite)
- Zustand
- TailwindCSS + DaisyUI
Backend
- Node.js
- Express.js
- MongoDB (Mongoose)
- Socket.io
SmartChat/
βββ backend/
β βββ routes/
β βββ controllers/
β βββ models/
β βββ lib/
β βββ ...
βββ frontend/
β βββ src/
β βββ components/
β βββ ...
βββ README.md
βββ ...
- β Real-time one-to-one chat
- β JWT authentication with cookies
- β Online/offline user indicators
- β Responsive & mobile-friendly UI
- β Secure API calls (CORS + HTTPS)
- β Persistent sessions
- JWT Authentication stored in HTTP-only cookies to prevent XSS attacks.
- CSRF Protection using
sameSite=strict
and conditionalsecure
cookies. - Password Hashing implemented with bcrypt.
- CORS Configuration with
credentials: true
for safe cross-origin requests. - Input Validation on both client and server.
- POST
/api/auth/signup
β Register a new user. - POST
/api/auth/login
β Login and get auth token. - POST
/api/auth/logout
β Logout current user. - PUT
/api/auth/update-profile
β Update user profile (requires JWT). - GET
/api/auth/check
β Verify authentication (requires JWT).
- GET
/api/messages/users
β Get all users for sidebar (requires JWT). - GET
/api/messages/:id
β Fetch chat history with a user (requires JWT). - POST
/api/messages/send/:id
β Send a message to a user (requires JWT).
Auth: Most routes require JWT stored in cookies. Ensure
withCredentials: true
in frontend requests.
Server β Client
Event Name | Payload | Description |
---|---|---|
getOnlineUsers |
[userId, ...] |
Sends an array of online user IDs |
Client β Server
Event Name | Payload | Description |
---|---|---|
sendMessage |
{ to, message } |
Sends a message to a user |
disconnect |
none | Fires when user disconnects |
git clone https://github.com/skyeyeye/SmartChat.git
cd SmartChat
cd backend
npm install
Create a .env file inside the backend/ directory:
PORT=5001
MONGO_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret
FRONTEND_URL=https://your-frontend.vercel.app
Run the backend:
npm run dev
cd ../frontend
npm install
Create a .env file inside the frontend/ directory:
VITE_BACKEND_URL=https://your-backend.onrender.com
Run the frontend:
npm run dev
Visit:
http://localhost:5173
-
Frontend: Vercel
-
Backend: Render
-
Database: MongoDB Atlas
- Pull requests are welcome.
- For major changes, please open an issue first.