Skip to content

Latest commit

Β 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’¬ Real-Time Chat Application

A full-stack real-time chat application built with the PERN stack (PostgreSQL, Express, React, Node.js) featuring instant messaging, user authentication, and media sharing capabilities.

Chat Application Node.js Express Socket.io MongoDB Tailwind CSS


πŸ“‹ Table of Contents


✨ Features

Core Features

  • πŸ” User Authentication - Secure JWT-based authentication with access & refresh tokens
  • πŸ’¬ Real-Time Messaging - Instant message delivery using Socket.io
  • πŸ‘₯ One-on-One Chat - Private conversations between users
  • 🟒 Online Status - See who's online in real-time
  • πŸ“± Responsive Design - Seamless experience across desktop, tablet, and mobile

Advanced Features

  • πŸ–ΌοΈ Media Sharing - Send images and files via Cloudinary integration
  • πŸ”” Toast Notifications - Instant feedback for user actions
  • 🎨 Modern UI - Clean interface with Tailwind CSS and DaisyUI components
  • ⚑ State Management - Efficient state handling with Zustand
  • πŸ”„ Auto-Reconnect - Automatic reconnection on network issues

πŸ› οΈ Tech Stack

Backend

Technology Purpose
Node.js Runtime environment
Express.js Web framework
MongoDB NoSQL database
Mongoose ODM for MongoDB
Socket.io Real-time communication
JWT Authentication tokens
bcryptjs Password hashing
Cloudinary Media storage & optimization
Cookie Parser Cookie handling
CORS Cross-origin resource sharing

Frontend

Technology Purpose
React 19 UI library
Vite Build tool & dev server
Tailwind CSS Utility-first CSS framework
DaisyUI Tailwind component library
Zustand State management
Socket.io Client Real-time communication
Axios HTTP client
React Router Client-side routing
Lucide React Icon library
React Hot Toast Notifications

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      CLIENT (React)                         β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚  Pages   β”‚  β”‚Componentsβ”‚  β”‚  Store   β”‚  β”‚   Lib      β”‚  β”‚
β”‚  β”‚          β”‚  β”‚          β”‚  β”‚(Zustand) β”‚  β”‚            β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β”‚
β”‚                           β”‚                                  β”‚
β”‚                    Socket.io + Axios                         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β”‚
                            β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    SERVER (Express)                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚  Routes   β”‚  β”‚Controllersβ”‚  β”‚Middlewareβ”‚  β”‚   Lib     β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β”‚
β”‚       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β”‚
β”‚                           β”‚                                  β”‚
β”‚              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                    β”‚
β”‚              β–Ό                         β–Ό                    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β”‚
β”‚  β”‚     MongoDB      β”‚      β”‚    Cloudinary     β”‚            β”‚
β”‚  β”‚    (Database)    β”‚      β”‚  (Media Storage)  β”‚            β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Getting Started

Prerequisites

Before you begin, ensure you have the following installed:

  • Node.js (v18.0.0 or higher)
  • npm (v9.0.0 or higher)
  • MongoDB (local instance or MongoDB Atlas account)
  • Cloudinary account (for media storage)

Installation

  1. Clone the repository

    git clone https://github.com/KaizenPrad/Chat_Application.git
    cd Chat_Application
  2. Install root dependencies

    npm install
  3. Install backend dependencies

    cd backend
    npm install
  4. Install frontend dependencies

    cd ../frontend
    npm install
  5. Set up environment variables (see below)

  6. Start the development servers

    In one terminal (backend):

    cd backend
    npm run dev

    In another terminal (frontend):

    cd frontend
    npm run dev
  7. Open your browser

    Frontend: http://localhost:5173
    Backend:  http://localhost:5000
    

Environment Variables

Create a .env file in the backend directory:

# Server Configuration
PORT=5000
NODE_ENV=development

# MongoDB Connection
MONGODB_URI=mongodb://localhost:27017/chat-application

# JWT Secrets
ACCESS_TOKEN_SECRET=your_access_token_secret_here
REFRESH_TOKEN_SECRET=your_refresh_token_secret_here

# Cloudinary Configuration
CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret

# Client URL (for CORS)
CLIENT_URL=http://localhost:5173

πŸ“ Project Structure

Chat_Application/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ controllers/     # Request handlers
β”‚   β”‚   β”œβ”€β”€ lib/            # Utility functions & configurations
β”‚   β”‚   β”œβ”€β”€ middlewares/    # Custom middleware (auth, error handling)
β”‚   β”‚   β”œβ”€β”€ models/        # Mongoose data models
β”‚   β”‚   β”œβ”€β”€ routes/        # API route definitions
β”‚   β”‚   └── server.js      # Entry point & Socket.io setup
β”‚   β”œβ”€β”€ package.json
β”‚   └── .env
β”‚
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/    # Reusable UI components
β”‚   β”‚   β”œβ”€β”€ constants/     # App constants & configurations
β”‚   β”‚   β”œβ”€β”€ lib/           # Utility functions
β”‚   β”‚   β”œβ”€β”€ pages/         # Route-level components
β”‚   β”‚   β”œβ”€β”€ store/         # Zustand state management
β”‚   β”‚   β”œβ”€β”€ App.jsx        # Main app with routing
β”‚   β”‚   β”œβ”€β”€ index.css      # Global styles
β”‚   β”‚   └── main.jsx       # Entry point
β”‚   β”œβ”€β”€ public/            # Static assets
β”‚   β”œβ”€β”€ index.html         # HTML template
β”‚   β”œβ”€β”€ vite.config.js     # Vite configuration
β”‚   β”œβ”€β”€ tailwind.config.js # Tailwind configuration
β”‚   └── package.json
β”‚
β”œβ”€β”€ .gitignore
β”œβ”€β”€ package.json           # Root package.json (scripts)
└── README.md

πŸ“‘ API Endpoints

Authentication

Method Endpoint Description Access
POST /api/auth/signup Register new user Public
POST /api/auth/login Login user Public
POST /api/auth/logout Logout user Authenticated
GET /api/auth/check Check auth status Authenticated
POST /api/auth/refresh-token Refresh access token Public

Users

Method Endpoint Description Access
GET /api/users Get all users Authenticated
GET /api/users/:id Get user by ID Authenticated
PUT /api/users/profile Update profile Authenticated

Messages

Method Endpoint Description Access
GET /api/messages/:userId Get messages with user Authenticated
POST /api/messages/send/:userId Send message Authenticated

πŸ”Œ Socket Events

Client β†’ Server

Event Payload Description
connect - Establish connection
disconnect - Handle disconnection
message:send { receiverId, text, image } Send a message

Server β†’ Client

Event Payload Description
message:receive { senderId, text, image, createdAt } Receive a message
user:online { userId } User came online
user:offline { userId } User went offline
users:online [userId1, userId2, ...] List of online users

🎨 Screenshots

Add screenshots of your application here

[Login Page]  [Chat Interface]  [Mobile View]

πŸ”§ Available Scripts

Root

Command Description
npm run build Install all dependencies & build frontend
npm run start Start backend server

Backend

Command Description
npm run dev Start with nodemon (hot reload)
npm start Start production server

Frontend

Command Description
npm run dev Start Vite dev server
npm run build Build for production
npm run preview Preview production build
npm run lint Run ESLint

🀝 Contributing

Contributions are welcome! Please follow these steps:

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

πŸ“ License

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


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

Pradyumn Dwivedi


πŸ™ Acknowledgments


⭐ Star this repository if you found it helpful! ⭐

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages