Skip to content

sugamghising/ChatApp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’¬ ChatApp - Real-Time Chat Application

A full-stack real-time chat application built with React, TypeScript, Node.js, Express, MongoDB, and Socket.IO.

✨ Features

  • πŸ” JWT Authentication - Secure login and signup
  • πŸ’¬ Real-Time Messaging - Instant message delivery via Socket.IO
  • πŸ“· Image Upload - Send images in chat (Cloudinary)
  • πŸ‘₯ Online Status - See who's online with green indicators
  • πŸ”” Unseen Message Counts - Red badges show unread messages
  • βœ… Message Status - Seen/unseen indicators (βœ“/βœ“βœ“)
  • πŸ‘€ Profile Management - Edit name, bio, and profile picture
  • πŸ“± Responsive Design - Works seamlessly on mobile and desktop
  • 🎨 Modern UI - WhatsApp/Messenger-style interface

πŸ› οΈ Tech Stack

Frontend

  • React 19 - UI framework
  • TypeScript - Type safety
  • Tailwind CSS - Styling
  • Socket.IO Client - Real-time communication
  • Zustand - State management
  • React Router - Navigation
  • Axios - HTTP requests
  • React Hot Toast - Notifications
  • Lucide React - Icons

Backend

  • Node.js - Runtime environment
  • Express - Web framework
  • TypeScript - Type safety
  • MongoDB - Database
  • Mongoose - ODM
  • Socket.IO - Real-time communication
  • JWT - Authentication
  • Cloudinary - Image storage
  • bcryptjs - Password hashing

πŸ“‹ Prerequisites

  • Node.js (v16 or higher)
  • npm or yarn
  • MongoDB Atlas account (or local MongoDB)
  • Cloudinary account (for image uploads)

πŸš€ Installation

1. Clone the repository

git clone <your-repo-url>
cd ChatApp

2. Install Backend Dependencies

cd server
npm install

3. Install Frontend Dependencies

cd ../client
npm install

4. Configure Environment Variables

Backend (.env in server folder)

Create a server/.env file:

MONGODB_URI=your_mongodb_connection_string
PORT=5000
JWT_SECRET=your_jwt_secret_key

CLOUDINARY_CLOUD_NAME=your_cloudinary_cloud_name
CLOUDINARY_API_KEY=your_cloudinary_api_key
CLOUDINARY_API_SECRET=your_cloudinary_api_secret

Frontend (.env in client folder)

Create a client/.env file:

REACT_APP_API_URL=http://localhost:5000

5. Start the Application

Start Backend (Terminal 1)

cd server
npm run dev

Backend will run on http://localhost:5000

Start Frontend (Terminal 2)

cd client
npm start

Frontend will open on http://localhost:3000

πŸ“ Project Structure

ChatApp/
β”œβ”€β”€ server/                  # Backend (Node.js + Express)
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ config/         # Database configuration
β”‚   β”‚   β”œβ”€β”€ controller/     # Route controllers
β”‚   β”‚   β”œβ”€β”€ middleware/     # Auth middleware
β”‚   β”‚   β”œβ”€β”€ models/         # Mongoose models
β”‚   β”‚   β”œβ”€β”€ routes/         # API routes
β”‚   β”‚   β”œβ”€β”€ types/          # TypeScript types
β”‚   β”‚   β”œβ”€β”€ utils/          # Utilities (JWT, Cloudinary)
β”‚   β”‚   └── index.ts        # Entry point
β”‚   β”œβ”€β”€ .env                # Environment variables
β”‚   β”œβ”€β”€ package.json
β”‚   └── tsconfig.json
β”‚
└── client/                 # Frontend (React + TypeScript)
    β”œβ”€β”€ src/
    β”‚   β”œβ”€β”€ components/     # React components
    β”‚   β”œβ”€β”€ pages/          # Page components
    β”‚   β”œβ”€β”€ store/          # Zustand stores
    β”‚   β”œβ”€β”€ config/         # API configuration
    β”‚   β”œβ”€β”€ lib/            # Socket.IO setup
    β”‚   β”œβ”€β”€ types/          # TypeScript interfaces
    β”‚   β”œβ”€β”€ utils/          # Utility functions
    β”‚   β”œβ”€β”€ App.tsx         # Main app component
    β”‚   └── index.tsx       # Entry point
    β”œβ”€β”€ public/
    β”œβ”€β”€ .env                # Environment variables
    β”œβ”€β”€ package.json
    β”œβ”€β”€ tailwind.config.js
    └── tsconfig.json

πŸ”Œ API Endpoints

Authentication

  • POST /api/auth/signup - Register new user
  • POST /api/auth/login - Login user
  • GET /api/auth/check - Verify authentication
  • PUT /api/auth/update-profile - Update user profile

Messages

  • GET /api/messages/users - Get all users with unseen counts
  • GET /api/messages/:id - Get messages with specific user
  • POST /api/messages/send/:id - Send message to user
  • PUT /api/messages/mark/:id - Mark message as seen

πŸ”„ Socket.IO Events

Client β†’ Server

  • connect - Connect with userId in query

Server β†’ Client

  • getOnlineUsers - List of online user IDs
  • newMessage - New message received

🎨 Color Theme

  • Sidebar Background: #6A89A7
  • Sent Messages: #BDDDFC
  • Received Messages: #88BDF2
  • Dark Background: #384959

πŸ“ Usage

  1. Sign Up: Create a new account with full name, email, password, and bio
  2. Login: Use your credentials to login
  3. Select User: Click on a user from the sidebar to start chatting
  4. Send Messages: Type text or upload images to send
  5. Real-Time: Messages appear instantly for both users
  6. Edit Profile: Click settings icon to update your profile

πŸ› Troubleshooting

Backend won't start

  • Check if MongoDB connection string is correct
  • Ensure port 5000 is not in use
  • Verify all environment variables are set

Frontend can't connect to backend

  • Make sure backend is running on port 5000
  • Check client/src/config/api.ts has correct API_URL
  • Verify CORS is enabled in backend

Images won't upload

  • Verify Cloudinary credentials in .env
  • Check image size is under 4MB
  • Ensure Cloudinary account is active

Socket.IO not connecting

  • Verify backend server is using server.listen() not app.listen()
  • Check browser console for connection errors
  • Ensure userId is passed in socket connection

πŸš€ Deployment

Backend (Heroku/Railway/Render)

  1. Set environment variables on hosting platform
  2. Deploy backend code
  3. Update frontend API_URL to deployed backend URL

Frontend (Vercel/Netlify)

  1. Update client/src/config/api.ts with production backend URL
  2. Build: npm run build
  3. Deploy build/ folder

πŸ“„ License

This project is open source and available under the MIT License.

🀝 Contributing

Contributions, issues, and feature requests are welcome!

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

Your Name

πŸ™ Acknowledgments

  • React Team for React
  • Tailwind CSS for the styling framework
  • Socket.IO for real-time communication
  • Cloudinary for image hosting

Happy Chatting! πŸ’¬βœ¨

About

A full-stack real-time chat application built with React, TypeScript, Node.js, Express, MongoDB, and Socket.IO.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published