Skip to content

A full-stack real-time chat application built with MERN, Socket.io, and TailwindCSS featuring JWT authentication, online user tracking, and instant messaging.

License

Notifications You must be signed in to change notification settings

skyeyeye/SmartChat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

✨ 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.

GitHub stars GitHub forks License Contributions welcome

πŸš€ Highlights

  • 🌟 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!

πŸ–Ό Preview

Screenshots coming soon Chat Interface Image Image Image Image

πŸ›  Tech Stack

Frontend

  • React (Vite)
  • Zustand
  • TailwindCSS + DaisyUI

Backend

  • Node.js
  • Express.js
  • MongoDB (Mongoose)
  • Socket.io

Folder Structure

SmartChat/
 β”œβ”€β”€ backend/
 β”‚   β”œβ”€β”€ routes/
 β”‚   β”œβ”€β”€ controllers/
 β”‚   β”œβ”€β”€ models/
 β”‚   β”œβ”€β”€ lib/
 β”‚   └── ...
 β”œβ”€β”€ frontend/
 β”‚   β”œβ”€β”€ src/
 β”‚   β”œβ”€β”€ components/
 β”‚   └── ...
 β”œβ”€β”€ README.md
 └── ...

⚑ Features

  • βœ… 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

πŸ”’ Security Features

  • JWT Authentication stored in HTTP-only cookies to prevent XSS attacks.
  • CSRF Protection using sameSite=strict and conditional secure cookies.
  • Password Hashing implemented with bcrypt.
  • CORS Configuration with credentials: true for safe cross-origin requests.
  • Input Validation on both client and server.

πŸ“‘ API Endpoints

Auth Routes

  • 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).

Message Routes

  • 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.


⚑ Socket.io Events

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

πŸ”§ Installation & Setup

1. Clone the Repository

git clone https://github.com/skyeyeye/SmartChat.git
cd SmartChat

2. Backend Setup

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

3. Frontend Setup

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

4. Open in Browser

Visit:

http://localhost:5173

(Default Vite dev server port)

πŸ“¦ Deployment

  • Frontend: Vercel

  • Backend: Render

  • Database: MongoDB Atlas

🀝 Contributing

  • Pull requests are welcome.
  • For major changes, please open an issue first.

πŸ’– Made with ❀️ by Ayush Saha

About

A full-stack real-time chat application built with MERN, Socket.io, and TailwindCSS featuring JWT authentication, online user tracking, and instant messaging.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages