A real-time chat application built with React, Vite, TailwindCSS, Socket.IO, Express.js, and MongoDB. The project is structured with separate frontend and backend folders for clean development and deployment.
- π Authentication (JWT, bcrypt)
- π€ User registration & login
- π¬ Real-time messaging (Socket.IO)
- ποΈ MongoDB database integration (via Mongoose)
- π¨ Modern UI with TailwindCSS & Radix UI
- π± Responsive design
- β‘ Fast development with Vite & React 19
- π‘οΈ CORS & secure API endpoints
- π§ͺ API testing with Postman
- React 19, Vite, TypeScript
- TailwindCSS, Radix UI, Lucide Icons
- React Router v7
- Socket.IO Client
- Axios
- Lottie React
- Utility: clsx, class-variance-authority, tailwind-merge
- Node.js, Express.js
- MongoDB with Mongoose
- Socket.IO (WebSocket)
- JWT (jsonwebtoken), bcrypt
- dotenv, CORS, body-parser
- Dev: nodemon
react-chat-app/
ββ frontend/ # React + Vite + TailwindCSS client
β ββ src/
β ββ index.html
β ββ package.json
β ββ ...
ββ backend/ # Express + MongoDB + Socket.IO server
ββ index.js # Your server entry (example)
ββ package.json
ββ .env # Environment variables (see below)
ββ ...
-
Node.js (LTS recommended)
-
MongoDB:
- Local MongoDB instance or
- MongoDB Atlas connection string
-
Postman (optional, for API testing)
git clone https://github.com/serhatbarisaydin/react-chat-app.git
cd react-chat-appFrontend
cd frontend
npm installBackend
cd ../backend
npm installCreate a .env file inside the backend folder:
MONGO_URI= "mongodb://localhost:27017/<yourProjectName>"
JWT_SECRET=your_jwt_secret
PORT=8000MONGO_URI: Your MongoDB connection string (local or Atlas)JWT_SECRET: Any strong secret stringPORT: Backend port (defaults to 5000 in examples)
cd backend
npm startEnsure your
startscript runs your server entry (e.g.,nodemon index.js).
cd frontend
npm run dev- Frontend:
http://localhost:5173 - Backend (example):
http://localhost:5000
- User data is stored in MongoDB using Mongoose ODM.
- Auth flows (register/login) interact with MongoDB collections.
- Configure your MongoDB connection in the backend via
.env.
The backend endpoints were tested with Postman.
-
POST /api/auth/registerβ Register a new user -
POST /api/auth/loginβ Login & receive JWT -
POST /api/users/createβ Create a new user (protected) -
GET /api/users/getAllUsersβ Fetch all users (protected) -
DELETE /api/users/delete/:idβ Delete user by ID (protected) -
PUT /api/users/update/:idβ Update user by ID (protected)
Include
Authorization: Bearer <token>header for all protected routes.
Client (example):
import { io } from "socket.io-client";
const socket = io("http://localhost:5000", {
withCredentials: true,
transports: ["websocket"],
});
socket.on("connect", () => {
console.log("connected", socket.id);
});
socket.on("message", (msg) => {
// handle incoming chat message
});Server (example idea):
io.on("connection", (socket) => {
socket.on("message", (payload) => {
// persist to DB, then emit to room/users
io.emit("message", payload);
});
});npm run devβ Start Vite dev servernpm run buildβ Build for productionnpm run previewβ Preview production buildnpm run lintβ Run ESLint
npm startβ Start backend (e.g.,nodemon index.js)
- Fork the repo
- Create a feature branch:
git checkout -b feature/awesome - Commit changes:
git commit -m "feat: add awesome feature" - Push branch:
git push origin feature/awesome - Open a Pull Request
This project is licensed under the MIT License.