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.
- Features
- Tech Stack
- Architecture
- Getting Started
- Project Structure
- API Endpoints
- Socket Events
- Contributing
- License
- π 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
- πΌοΈ 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
| 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 |
| 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 |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β CLIENT (React) β
β βββββββββββ ββββββββββββ ββββββββββββ ββββββββββββββ β
β β Pages β βComponentsβ β Store β β Lib β β
β β β β β β(Zustand) β β β β
β ββββββ¬ββββββ ββββββ¬ββββββ ββββββ¬ββββββ βββββββ¬βββββββ β
β ββββββββββββββββ΄ββββββββββββββ΄ββββββββββββββββ β
β β β
β Socket.io + Axios β
βββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β SERVER (Express) β
β ββββββββββββ βββββββββββββ ββββββββββββ βββββββββββββ β
β β Routes β βControllersβ βMiddlewareβ β Lib β β
β ββββββ¬ββββββ βββββββ¬ββββββ ββββββ¬ββββββ βββββββ¬ββββββ β
β ββββββββββββββββ΄ββββββββββββββ΄ββββββββββββββββ β
β β β
β ββββββββββββββ΄βββββββββββββ β
β βΌ βΌ β
β ββββββββββββββββββββ ββββββββββββββββββββ β
β β MongoDB β β Cloudinary β β
β β (Database) β β (Media Storage) β β
β ββββββββββββββββββββ ββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
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)
-
Clone the repository
git clone https://github.com/KaizenPrad/Chat_Application.git cd Chat_Application -
Install root dependencies
npm install
-
Install backend dependencies
cd backend npm install -
Install frontend dependencies
cd ../frontend npm install -
Set up environment variables (see below)
-
Start the development servers
In one terminal (backend):
cd backend npm run devIn another terminal (frontend):
cd frontend npm run dev -
Open your browser
Frontend: http://localhost:5173 Backend: http://localhost:5000
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:5173Chat_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
| 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 |
| 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 |
| Method | Endpoint | Description | Access |
|---|---|---|---|
| GET | /api/messages/:userId |
Get messages with user | Authenticated |
| POST | /api/messages/send/:userId |
Send message | Authenticated |
| Event | Payload | Description |
|---|---|---|
connect |
- | Establish connection |
disconnect |
- | Handle disconnection |
message:send |
{ receiverId, text, image } |
Send a message |
| 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 |
Add screenshots of your application here
[Login Page] [Chat Interface] [Mobile View]
| Command | Description |
|---|---|
npm run build |
Install all dependencies & build frontend |
npm run start |
Start backend server |
| Command | Description |
|---|---|
npm run dev |
Start with nodemon (hot reload) |
npm start |
Start production server |
| 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 |
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch
git checkout -b feature/amazing-feature
- Commit your changes
git commit -m 'Add amazing feature' - Push to the branch
git push origin feature/amazing-feature
- Open a Pull Request
This project is licensed under the ISC License - see the LICENSE file for details.
Pradyumn Dwivedi
- GitHub: @KaizenPrad
- LinkedIn: Pradyumn Dwivedi
- Socket.io Documentation
- Express.js Documentation
- React Documentation
- Tailwind CSS Documentation
- MongoDB Documentation
β Star this repository if you found it helpful! β