Skip to content

MyChatApp is a modern, full-stack real-time chat application that brings people together through seamless instant messaging. Built with React and Express.js, it features real-time communication powered by Socket.io, a comprehensive friend management system, and a beautiful, responsive UI

Notifications You must be signed in to change notification settings

Silence91169/chat-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’¬ MyChatApp β€” Real-time Chat Application

Status Frontend Backend Database Real-time Auth Build Styling Cloud Email Deploy License

MyChatApp is a modern, full-stack real-time chat application that brings people together through seamless instant messaging. Built with React and Express.js, it features real-time communication powered by Socket.io, a comprehensive friend management system, and a beautiful, responsive UI. Users can register with OTP email verification, manage their profiles with custom avatars, discover other users globally, send friend requests, and engage in private conversations with real-time typing indicators and online status tracking. Whether you're connecting with friends or meeting new people, MyChatApp delivers a smooth, secure, and engaging chat experience.

Table of Contents

πŸ“Œ Live Services

Layer Platform Link
Web Vercel https://chat91169.vercel.app/
Server Render https://chat-app-api-59jt.onrender.com

πŸ“ Repository Structure

chat-app/
β”œβ”€ backend/                          # Backend: Express + MongoDB + Socket.io
β”‚  β”œβ”€ server.js                      # Main server entry point
β”‚  β”œβ”€ package.json                   # Backend dependencies
β”‚  β”œβ”€ admin/                         # Admin utilities
β”‚  β”‚  β”œβ”€ deleteAllMessages.js        # Script to delete all messages
β”‚  β”‚  └─ resetDatabase.js            # Script to reset the database
β”‚  β”œβ”€ config/
β”‚  β”‚  β”œβ”€ cloudinary.js               # Cloudinary configuration for image uploads
β”‚  β”‚  └─ db.js                       # MongoDB connection setup
β”‚  β”œβ”€ controllers/
β”‚  β”‚  β”œβ”€ auth.controller.js          # Login, logout, token refresh
β”‚  β”‚  β”œβ”€ authOtp.controller.js       # OTP-based signup flow
β”‚  β”‚  β”œβ”€ friend.controller.js        # Friend request management
β”‚  β”‚  β”œβ”€ messages.controller.js      # Message CRUD operations
β”‚  β”‚  β”œβ”€ profile.controller.js       # Profile updates and avatar
β”‚  β”‚  β”œβ”€ room.controller.js          # Chat room management
β”‚  β”‚  └─ users.controller.js         # User discovery
β”‚  β”œβ”€ middleware/
β”‚  β”‚  β”œβ”€ authenticate.js             # JWT authentication middleware
β”‚  β”‚  └─ multer.js                   # File upload middleware
β”‚  β”œβ”€ model/
β”‚  β”‚  β”œβ”€ friend.model.js             # Friendship schema
β”‚  β”‚  β”œβ”€ messages.model.js           # Message schema
β”‚  β”‚  β”œβ”€ rooms.model.js              # Chat room schema
β”‚  β”‚  β”œβ”€ signupOtp.model.js          # OTP verification schema
β”‚  β”‚  └─ user.model.js               # User schema
β”‚  β”œβ”€ routes/
β”‚  β”‚  β”œβ”€ auth.routes.js              # /api/auth routes
β”‚  β”‚  β”œβ”€ friend.routes.js            # /api/friends routes
β”‚  β”‚  β”œβ”€ messages.routes.js          # /api/messages routes
β”‚  β”‚  β”œβ”€ profile.routes.js           # /api/profile routes
β”‚  β”‚  β”œβ”€ room.routes.js              # /api/rooms routes
β”‚  β”‚  └─ users.routes.js             # /api/users routes
β”‚  β”œβ”€ socket/
β”‚  β”‚  β”œβ”€ index.js                    # Socket.io initialization
β”‚  β”‚  β”œβ”€ chat.js                     # Real-time chat handlers
β”‚  β”‚  β”œβ”€ friend.js                   # Real-time friend request handlers
β”‚  β”‚  β”œβ”€ userStatus.js               # Online/offline status tracking
β”‚  β”‚  └─ middleware/
β”‚  β”‚     └─ auth.js                  # Socket authentication middleware
β”‚  β”œβ”€ uploads/                       # Temporary file uploads
β”‚  └─ utils/
β”‚     β”œβ”€ createOrGetRoom.js          # Room utility functions
β”‚     β”œβ”€ sendEmail.js                # Brevo email service for OTP
β”‚     └─ uploadImage.js              # Cloudinary upload utility
β”‚
└─ frontend/                         # Frontend: React + Vite + Tailwind CSS
   β”œβ”€ index.html                     # HTML entry point
   β”œβ”€ package.json                   # Frontend dependencies
   β”œβ”€ vite.config.js                 # Vite configuration
   β”œβ”€ vercel.json                    # Vercel deployment config
   └─ src/
      β”œβ”€ main.jsx                    # React entry point
      β”œβ”€ App.jsx                     # App router and routes
      β”œβ”€ App.css                     # Global styles
      β”œβ”€ index.css                   # Tailwind imports
      β”œβ”€ api/
      β”‚  └─ axios.jsx                # Axios instance with interceptors
      β”œβ”€ assets/                     # Static assets
      β”œβ”€ components/
      β”‚  β”œβ”€ ChatSection.jsx          # Main chat interface
      β”‚  β”œβ”€ ChatSidebar.jsx          # Navigation sidebar
      β”‚  β”œβ”€ FriendsSection.jsx       # Friend management UI
      β”‚  β”œβ”€ GlobalSection.jsx        # User discovery page
      β”‚  β”œβ”€ ProfileSettings.jsx      # Profile settings page
      β”‚  └─ VerifyOtp.jsx            # OTP verification component
      β”œβ”€ pages/
      β”‚  β”œβ”€ Home.jsx                 # Main dashboard
      β”‚  β”œβ”€ Login.jsx                # Login page
      β”‚  └─ Signup.jsx               # Signup page
      β”œβ”€ socket/
      β”‚  └─ index.js                 # Socket.io client setup
      └─ utils/
         └─ ProtectedRoute.jsx       # Auth route protection

πŸ›  Tech Stack

Languages & Frameworks

  • Frontend: React 19, JavaScript (ES Modules)
  • Backend: Express.js 5, Node.js
  • Database: MongoDB with Mongoose ODM
  • Real-time: Socket.io

Libraries & Tools

  • UI: Tailwind CSS, Lucide Icons
  • Notifications: React Hot Toast
  • Routing: React Router DOM v7
  • HTTP Client: Axios
  • Authentication: JSON Web Tokens (JWT), bcryptjs
  • File Uploads: Multer, Cloudinary
  • Email Service: Brevo (Sendinblue) for OTP emails
  • Build Tool: Vite 7
  • Development: Nodemon, ESLint
  • Deployment: Vercel (frontend), Render (backend)

🧩 High-Level Architecture

   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚   React + Vite       β”‚  HTTP  β”‚   Express.js API        β”‚ Mongooseβ”‚   MongoDB       β”‚
   β”‚   (Frontend)         β”œβ”€β”€β”€β”€β”€β”€β”€>β”‚   /api/auth             β”œβ”€β”€β”€β”€β”€β”€β”€β”€>β”‚   (Users,       β”‚
   β”‚                      β”‚        β”‚   /api/users            β”‚         β”‚    Messages,    β”‚
   β”‚   Tailwind CSS       β”‚ Socket β”‚   /api/friends          β”‚         β”‚    Rooms,       β”‚
   β”‚   React Router       β”œβ”€β”€β”€β”€β”€β”€β”€>β”‚   /api/messages         β”‚         β”‚    Friendships) β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  .io   β”‚   /api/rooms            β”‚         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                   β”‚   /api/profile          β”‚
                                   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                             β”‚
                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                       β”‚                     β”‚                     β”‚
                       β–Ό                     β–Ό                     β–Ό
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚   Cloudinary   β”‚   β”‚     Brevo      β”‚   β”‚   Socket.io    β”‚
              β”‚   (Avatars)    β”‚   β”‚   (OTP Email)  β”‚   β”‚   (Real-time)  β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Architecture Details:

  • Authentication: JWT-based with access tokens (1 hour) and refresh tokens (7 days) stored in httpOnly cookies
  • Real-time Communication: Socket.io handles live messaging, online status, and friend request notifications
  • Token Refresh: Automatic token rotation with failed request retry queue
  • File Storage: Avatar images uploaded to Cloudinary via Multer middleware
  • Email Verification: OTP-based signup flow using Brevo SMTP API
  • CORS: Configured for frontend origin with credentials enabled

πŸš€ Features

Authentication & Security

  • Email + password registration with OTP verification
  • Secure login with JWT access and refresh tokens
  • Automatic token refresh with request retry mechanism
  • Password hashing with bcryptjs
  • Protected routes for authenticated users only

User Management

  • Custom user profiles with avatar uploads
  • Profile name and password updates
  • Global user discovery with pagination
  • Real-time online/offline status tracking
  • Last seen timestamps for offline users

Friend System

  • Send, accept, and reject friend requests
  • Cancel outgoing friend requests
  • Remove existing friends
  • View pending, sent, accepted, and rejected requests
  • Real-time friend request notifications

Messaging

  • Private one-on-one chat rooms
  • Real-time message delivery via Socket.io
  • Unsend messages functionality
  • Unread message count tracking
  • Mark messages as read
  • Message history persistence

Chat Experience

  • Search and filter conversations
  • Sort chats alphabetically or by recent activity
  • Filter to show unread chats only
  • Online status indicators
  • Responsive chat interface
  • Toast notifications for actions

UI/UX

  • Modern, clean design with Tailwind CSS
  • Responsive layout for all screen sizes
  • Gradient accents and smooth transitions
  • Loading states and error handling
  • Navigation sidebar with tab switching

πŸ“‘ API Endpoints

Base URL (local): http://localhost:5000
All authenticated routes require a valid Bearer token in the Authorization header.

Authentication Routes

Endpoint Method Description Access
/api/auth/send-otp POST Send OTP to email for signup Public
/api/auth/verify-otp POST Verify OTP and create account Public
/api/auth/login POST Login with email and password Public
/api/auth/refresh-token POST Refresh access token using cookie Public
/api/auth/logout POST Logout and clear refresh token Public

User Routes

Endpoint Method Description Access
/api/users/all GET Get all users with pagination Auth required

Friend Routes

Endpoint Method Description Access
/api/friends/request POST Send a friend request Auth required
/api/friends/accept POST Accept a friend request Auth required
/api/friends/reject POST Reject a friend request Auth required
/api/friends/remove POST Remove an existing friend Auth required
/api/friends/cancel POST Cancel a sent friend request Auth required
/api/friends/pending GET Get pending friend requests Auth required
/api/friends/sent GET Get sent friend requests Auth required
/api/friends/list GET Get accepted friends list Auth required
/api/friends/rejected GET Get rejected requests Auth required
/api/friends/status/:friendId GET Check friendship status Auth required

Message Routes

Endpoint Method Description Access
/api/messages/:roomId GET Get messages for a room Auth required
/api/messages POST Send a message Auth required
/api/messages/unsend/:messageId PUT Unsend a message Auth required

Room Routes

Endpoint Method Description Access
/api/rooms/my GET Get user's chat rooms Auth required
/api/rooms/with/:friendId GET Get or create room with friend Auth required
/api/rooms/:roomId/mark-read POST Mark room messages as read Auth required

Profile Routes

Endpoint Method Description Access
/api/profile/update PUT Update profile name Auth required
/api/profile/avatar PUT Upload/update avatar image Auth required
/api/profile/change-password PUT Change account password Auth required

βš™οΈ Installation (Local Development)

Prerequisites

  • Node.js >= 18.x
  • npm or yarn
  • MongoDB (local or MongoDB Atlas)
  • Cloudinary account (for avatar uploads)
  • Brevo account (for OTP emails)

1) Clone the repository

git clone https://github.com/silence91169/chat-app.git
cd chat-app

2) Backend Setup

cd backend
npm install

Create a .env file in the backend directory (see Environment Variables).

Start the backend server:

# Development mode with hot reload
npm run dev

# Production mode
npm start

The backend will run on http://localhost:5000.

3) Frontend Setup

cd frontend
npm install

Create a .env file in the frontend directory (see Environment Variables).

Start the frontend development server:

npm run dev

The frontend will run on http://localhost:5173.

πŸ” Environment Variables

Backend (backend/.env)

# Server
PORT=5000
NODE_ENV=development

# MongoDB Connection
MONGO_URI=mongodb://localhost:27017/chatapp

# JWT Secrets (use strong random strings)
ACCESS_TOKEN_SECRET=your-access-token-secret
REFRESH_TOKEN_SECRET=your-refresh-token-secret

# Frontend URL (for CORS)
FRONTEND_URL=http://localhost:5173

# Cloudinary Configuration
CLOUDINARY_CLOUD_NAME=your-cloud-name
CLOUDINARY_API_KEY=your-api-key
CLOUDINARY_API_SECRET=your-api-secret

# Brevo Email Configuration
BREVO_API_KEY=your-brevo-api-key
EMAIL=[email protected]

Frontend (frontend/.env)

# Backend API URL
VITE_API_URL=http://localhost:5000

πŸ§ͺ Usage Guide

Running the Application

  1. Start the backend server (from backend/ directory):
    npm run dev

Frontend Testing

cd frontend
npm test

πŸš€ Deployment

Backend Deployment (Railway/Render/Heroku)

  1. Set environment variables in your hosting platform
  2. Update FRONTEND_URL to your production URL
  3. Set NODE_ENV=production
  4. Deploy using Git or CLI

Frontend Deployment (Vercel/Netlify)

  1. Build the project:
npm run build
  1. Set VITE_API_URL to your backend URL
  2. Deploy the dist folder

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ‘¨β€πŸ’» Author

Shitanshu Singh


πŸ™ Acknowledgments


πŸ“ž Support

If you have any questions or need help, please:


Made with ❀️ by Shitanshu Singh

⭐ Star this repository if you found it helpful!

About

MyChatApp is a modern, full-stack real-time chat application that brings people together through seamless instant messaging. Built with React and Express.js, it features real-time communication powered by Socket.io, a comprehensive friend management system, and a beautiful, responsive UI

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages