A modern, real-time chat application built with the MERN stack (MongoDB, Express, React, Node.js) featuring WebSocket-based instant messaging, user authentication, and a beautiful UI.
Screen.Recording.2026-01-11.205510.mp4
- Real-time Messaging: Instant message delivery using Socket.IO
- User Authentication: Secure JWT-based authentication with HTTP-only cookies
- Profile Management: Update display name and profile picture
- Message Status: Sent, Delivered, and Read indicators
- Online Status: See when users are online/offline
- User Search: Find and start conversations with other users
- Responsive Design: Mobile-first design with TailwindCSS and DaisyUI
- Image Upload: Cloudinary integration for avatar uploads with compression
- Redis Caching: Efficient caching for online users and unread counts
- Type Safety: Full TypeScript support on both frontend and backend
- React 19 - UI library
- TypeScript - Type safety
- Vite - Build tool
- TailwindCSS 4 - Styling
- DaisyUI - Component library
- Zustand - State management
- Socket.IO Client - Real-time communication
- React Router - Navigation
- React Hot Toast - Notifications
- Axios - HTTP client
- Zod - Schema validation
- Node.js - Runtime
- Express 5 - Web framework
- TypeScript - Type safety
- MongoDB - Database
- Mongoose - ODM
- Socket.IO - WebSocket server
- Redis - Caching
- JWT - Authentication
- Bcrypt - Password hashing
- Cloudinary - Image storage
- Zod - Schema validation
Before you begin, ensure you have the following installed:
- Node.js (v20.19.0 or higher)
- MongoDB (local or Atlas account)
- Redis (local or cloud instance)
- Cloudinary account (for image uploads)
git clone https://github.com/yourusername/pingchat.git
cd pingchatcd backend
npm installCreate a .env file in the backend directory:
# Database
DB_URL=mongodb://localhost:27017/pingchat
# Server
PORT=5000
NODE_ENV=development
# Redis
REDIS_URL=localhost
REDIS_PORT=6379
REDIS_PASS=your_redis_password
# JWT
JWT_SECRET=your_super_secret_jwt_key_here
# Cloudinary
Cloudinary_Cloud_Name=your_cloud_name
Cloudinary_API_Key=your_api_key
Cloudinary_API_Secret=your_api_secret
# Client URL
CLIENT_URL=http://localhost:5173cd ../client
npm installCreate a .env file in the client directory:
VITE_API_URL=http://localhost:5000- Start Backend Server (from
backenddirectory):
npm run devServer will run on http://localhost:5000
- Start Frontend (from
clientdirectory):
npm run devClient will run on http://localhost:5173
Backend:
cd backend
npm run build
npm startFrontend:
cd client
npm run build
npm run previewpingchat/
βββ backend/
β βββ src/
β β βββ config/ # Configuration files
β β βββ controller/ # Route controllers
β β βββ middleware/ # Custom middleware
β β βββ model/ # Mongoose models
β β βββ router/ # Express routes
β β βββ services/ # Business logic
β β βββ validation/ # Zod schemas
β β βββ index.ts # Entry point
β βββ package.json
β βββ tsconfig.json
β
βββ client/
β βββ src/
β β βββ assets/ # Static assets
β β βββ components/ # React components
β β βββ lib/ # Utilities and config
β β βββ pages/ # Page components
β β βββ store/ # Zustand stores
β β βββ App.tsx
β β βββ main.tsx
β βββ package.json
β βββ vite.config.ts
β
βββ README.md
- Socket.IO handles bidirectional communication
- Messages are optimistically rendered for instant feedback
- Acknowledgment system ensures message delivery
- User registers/logs in
- Server generates JWT token
- Token stored in HTTP-only cookie
- Protected routes validate token
- Socket connection authenticated via cookie
- Sent: Message sent to server
- Delivered: Message delivered to recipient's socket
- Read: Recipient opened the chat and viewed message
- Online users stored in Redis hash
- Unread counts cached per user-chat combination
- Reduces database queries for frequently accessed data
- Sidebar: Chat list with search functionality
- ChatContainer: Message display and input
- MessageBubble: Individual message component
- SearchContainer: User search interface
- ProfilePage: User profile management
- HTTP-only cookies for JWT storage
- CORS configuration
- Password hashing with bcrypt
- Input validation with Zod
- Environment variable protection
- Secure cookie settings in production
The application is fully responsive with:
- Mobile-first approach
- Breakpoints for tablets and desktops
- Touch-friendly interface
- Optimized layouts for all screen sizes
- No file/image messaging (text only)
- No group chat functionality
- No message editing/deletion
- No typing indicators
- Limited to single device per user
Made with β€οΈ and TypeScript
