Skip to content

A real-time chat app with secure JWT authentication, responsive design using Tailwind CSS, and Socket.IO for instant messaging. It supports media uploads via Cloudinary and offers 25+ themes for a personalized experienceβ€”deployed on Render.com for seamless accessibility.

Notifications You must be signed in to change notification settings

JurgenHonest/FullStack---Chat-App

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

63 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Real-Time Chat Application πŸ“±πŸ’¬

image (2)

Overview

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


πŸš€ Features

πŸ”΄ Real-Time Messaging

  • 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));
  });

πŸ”’ Secure User Authentication

  • 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;
};

🎨 Dynamic Themes

  • Supports 26 customizable themes using Tailwind CSS and DaisyUI.

πŸ“± Responsive Design

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

πŸ–ΌοΈ Media Sharing

  • 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,
});

πŸ› οΈ Tech Stack

Front-End:

  • React with JSX for UI development.
  • Tailwind CSS and DaisyUI for styling and themes

Back-End:

  • Node.js with Express for the server.
  • MongoDB for database management.
  • Socket.IO for real-time messaging

Additional Tools:

  1. bcrypt for password hashing
  2. JWT for authentication
  3. Cloudinary for media storage
  4. dotenv for environment configuration
  5. cookie-parser for handling cookies
  6. CORS for managing cross-origin requests

Setup .env file

MONGODB_URI=...
PORT=5001
JWT_SECRET=...

CLOUDINARY_CLOUD_NAME=...
CLOUDINARY_API_KEY=...
CLOUDINARY_API_SECRET=...

NODE_ENV=development


πŸ“‚ Project Structure

πŸ“ 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

πŸ“‘ API Documentation

🌐 Back-End APIs

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)

🌐 Front-End APIs

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

πŸ“¦ Installation

Prerequisites:

  • Node.js must be installed.

Install Dependencies:

// 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

βš™οΈ How It Works

  1. User Authentication: Users register or log in securely using hashed passwords and JWT.

  2. Real-Time Communication: Messages are exchanged instantly using Socket.IO.

  3. Database Storage: MongoDB stores user data, messages, and media links.

  4. Dynamic Themes: Users can switch between 26 available themes.

  5. Responsive UI: Tailored for desktops and mobile devices with responsive design.

Build App

npm run build

Start the App

npm run start

🚧 Future Enhancements

  1. AI-Based Message Filtering: Detect and block spam messages in real time.

  2. End-to-End Encryption: Improve privacy and data security.

  3. Voice & Video Calling: Add support for multimedia communication.


About

A real-time chat app with secure JWT authentication, responsive design using Tailwind CSS, and Socket.IO for instant messaging. It supports media uploads via Cloudinary and offers 25+ themes for a personalized experienceβ€”deployed on Render.com for seamless accessibility.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published