This real-time chat application delivers a modern, seamless messaging experience. Packed with features like real-time communication, secure authentication, media sharing, and dynamic themes, itβs designed to provide both functionality and aesthetics.
π Live Demo: Check it out here
- Powered by Socket.IO,, ensuring instant message delivery between users.
- Efficient handling of user connections and disconnections.
io.on("connection", (socket) => {
console.log("A user connected", socket.id);
io.emit("getOnlineUsers", Object.keys(userSocketMap));
socket.on("disconnect", () => {
console.log("A user disconnected", socket.id);
delete userSocketMap[userId];
io.emit("getOnlineUsers", Object.keys(userSocketMap));
});
- Password hashing with bcrypt ensures data safety.
- JWT (JSON Web Tokens) for secure session management.
import jwt from "jsonwebtoken";
export const generateToken = (userId, res) => {
const token = jwt.sign({ userId }, process.env.JWT_SECRET, {
expiresIn: "7d",
});
res.cookie("jwt", token, {
maxAge: 7 * 24 * 60 * 60 * 1000, //Millisecond
httpOnly: true, //prevent XSS attacks croos-site scripting attacks
sameSite: "strict", // CSRF attacks cross-site request forgery attacks
secure: process.env.NODE_ENV !== "development",
});
return token;
};
- Supports 26 customizable themes using Tailwind CSS and DaisyUI.
- Fully responsive UI for desktops, tablets, and mobile devices.
- Built with Tailwind CSS and DaisyUI, the application is fully responsive, providing a smooth experience across all devices, from desktops to mobile phones.
<div
data-theme={theme}
className="h-screen container mx-auto px-4 pt-20 max-w-5xl"
>
<div className="space-y-6">
<div className="flex flex-col gap-1">
<h2 className="text-lg font-semibold">Theme</h2>
<p className="text-sm text-base-content/70">
Choose a theme for your chat interface
</p>
</div>
</div>
- Upload and share images/files seamlessly through Cloudinary integration.
cloudinary.config({
cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
api_key: process.env.CLOUDINARY_API_KEY,
api_secret: process.env.CLOUDINARY_API_SECRET,
});
- React with JSX for UI development.
- Tailwind CSS and DaisyUI for styling and themes
- Node.js with Express for the server.
- MongoDB for database management.
- Socket.IO for real-time messaging
- bcrypt for password hashing
- JWT for authentication
- Cloudinary for media storage
- dotenv for environment configuration
- cookie-parser for handling cookies
- CORS for managing cross-origin requests
MONGODB_URI=...
PORT=5001
JWT_SECRET=...
CLOUDINARY_CLOUD_NAME=...
CLOUDINARY_API_KEY=...
CLOUDINARY_API_SECRET=...
NODE_ENV=development
π Project-Directory/
βββ π frontend/ # Front-end application
β βββ π public/ # Public folder for static assets
β β βββ avatar.png # default profile picture
β β βββ vite.png
β β
β βββ π src/ # Source files for React app
β β βββ π components/ # Reusable UI components
β β β βββ AuthImagePattern.jsx
β β β βββ ChatContainer.jsx
β β β βββ ChatHeader.jsx
β β β βββ MessageInput.jsx
β β β βββ Navbar.jsx
β β β βββ NoChatSelected.jsx
β β β βββ Sidebar.jsx
β β β βββ π skeletons/ # Placeholder skeleton components
β β β βββ MessageSkeleton.jsx
β β β βββ SidebarSkeleton.jsx
| | |
β β βββ π constant/ # Context for global state management
β β β βββ index.js
| | |
β β βββ π lib/ # Api calls
β β β βββ axios.js
β β β βββ utils.js
| | |
β β βββ π pages/ # Page-level components
β β β βββ Homepage.jsx
β β β βββ LoginPage.jsx
β β β βββ SettingsPage.jsx
β β β βββ ProfilePage.jsx
| | |
β β βββ π store/ # State Managment Files
β β β βββ useAuthStore.js
β β β βββ useChatStore.js
β β β βββ useThemeStore.js
| | |
β β βββ App.js # Main app component
β β βββ main.jsx # Entry point for React app
β β βββ index.css # CSS or Tailwind configuration files
| |
| βββ favicon-32x32.png # App icon
| βββ Readme.md # Installed md file
| βββ index.html # Main HTML file
| βββ package-lock.json # Detailed description of dependencies and core materials
β βββ eslint.config.js.json # ESLint configuration
β βββ postcss.config.js # PostCSS configuration
β βββ tailwind.config.js # Tailwind CSS configuration
β βββ vite.config.js # Vite configuration
β βββ package.json # Dependencies for front-end
|
| βββ π backend/ # Back-end application
| βββ π src/ # Source folder for the backend
| β βββ π controllers/ # Business logic for routes
| β β βββ authController.js # Authentication-related logic
| β β βββ messageController.js # Message-related logic
| | |
| β βββ π lib/ # Configuration files
| β β βββ db.js # MongoDB connection
| β β βββ cloudinary.js # Cloudinary configuration
| β β βββ socket.js # Socket configuration
| β β βββ utils.js
| | |
| β βββ π middleware/ # Custom middleware (e.g., authentication)
| β β βββ authMiddelware.js # Error handling middleware
| | |
| β βββ π models/ # Mongoose schemas
| β β βββ usersmodel.js # User schema
| β β βββ messagemodel.js # Message schema
| | |
| β βββ π routes/ # API routes
| β β βββ authRoutes.js # Auth-related routes
| β β βββ messageRoutes.js # Message-related routes
| | |
| β βββ π seeds/ # Seeds as a test users
| β β βββ user.seeds.js # list of test users
| |
| β βββ π utils/ # Utility functions
| β β βββ generateToken.js # JWT token generator
| β β βββ validateInputs.js # Input validation helpers
| β βββ index.js # Main server file
| βββ package.json # Dependencies for back-end
| βββ package-lock.json # Lock file for dependencies
| βββ.env # Environment variables
βββ .gitignore # Files and directories to ignore in Git
βββ README.md # Project documentation
βββ package.json # Dependencies for the entire project
Endpoint | Method | Description | Authentication |
---|---|---|---|
/api/auth/signup |
POST | Registers a new user | No |
/api/auth/login |
POST | Logs in a user | No |
/api/auth/logout |
POST | Logs out the user | Yes (JWT) |
/api/auth/check |
GET | Checks if the user is authenticated | Yes (JWT) |
/api/users |
GET | Fetches all users for the sidebar | Yes (JWT) |
/api/messages/:id |
GET | Fetches all messages between the current user and another user | Yes (JWT) |
/api/messages/send/:id |
POST | Sends a new message to a specific user | Yes (JWT) |
/api/upload/image |
POST | Uploads an image via Cloudinary | Yes (JWT) |
/api/profile/update-profile |
PUT | Updates user profile information | Yes (JWT) |
Feature | Description | Dependencies |
---|---|---|
Authentication | Handles user login, registration, and logout | Axios, JWT cookies |
User Management | Fetches and displays the list of all users | Axios, Socket.IO |
Real-Time Messaging | Enables chat functionality between users | Socket.IO for WebSocket comm |
Media Sharing | Allows users to upload and share files/images | Axios, Cloudinary API |
Theme Switching | Lets users toggle between 26 themes | DaisyUI |
- Node.js must be installed.
// Initialize package.json
npm init -y
// Install required dependencies
npm install express socket.io mongoose bcrypt jsonwebtoken cors cookie-parser dotenv multer cloudinary multer-storage-cloudinary
-
User Authentication: Users register or log in securely using hashed passwords and JWT.
-
Real-Time Communication: Messages are exchanged instantly using Socket.IO.
-
Database Storage: MongoDB stores user data, messages, and media links.
-
Dynamic Themes: Users can switch between 26 available themes.
-
Responsive UI: Tailored for desktops and mobile devices with responsive design.
npm run build
npm run start
-
AI-Based Message Filtering: Detect and block spam messages in real time.
-
End-to-End Encryption: Improve privacy and data security.
-
Voice & Video Calling: Add support for multimedia communication.