Skip to content
capJillurPublic

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

6 Commits

Folders and files

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

Repository files navigation

πŸ’¬ ChitChat - Real-Time Chat Application

App Link

https://chit-chat-khaki-ten.vercel.app

A modern real-time chat application built with React, Node.js, Express, Socket.IO, and MongoDB Atlas.

Users can exchange messages instantly without refreshing the page while all chat history is persisted in MongoDB and automatically loaded when the application starts.


Features

Core Features

  • βœ… Real-time messaging using Socket.IO
  • βœ… Store chat messages in MongoDB Atlas
  • βœ… Retrieve previous chat history
  • βœ… REST API for sending and fetching messages
  • βœ… Instant message broadcasting
  • βœ… Auto-scroll to latest message
  • βœ… Responsive chat interface
  • βœ… Display message timestamps
  • βœ… Clean and reusable project architecture
  • βœ… Input validation
  • βœ… Error handling for API requests
  • βœ… Error handling for Socket.IO events

✨ Bonus Features

  • βœ… Dummy username login (LocalStorage)
  • βœ… Typing indicator
  • βœ… Online user counter
  • βœ… Auto reconnect with Socket.IO
  • βœ… Loading state while sending messages
  • βœ… Empty chat state
  • βœ… Enter key to send message
  • βœ… Logout functionality

πŸ›  Tech Stack

Frontend

  • React
  • TypeScript
  • Vite
  • Tailwind CSS
  • Axios
  • Socket.IO Client

Backend

  • Node.js
  • Express.js
  • TypeScript
  • Socket.IO
  • MongoDB Atlas
  • Mongoose

πŸ“ Project Structure

ChitChat
β”‚
β”œβ”€β”€ chat-backend
β”‚   β”œβ”€β”€ src
β”‚   β”‚   β”œβ”€β”€ config
β”‚   β”‚   β”œβ”€β”€ controllers
β”‚   β”‚   β”œβ”€β”€ models
β”‚   β”‚   β”œβ”€β”€ routes
β”‚   β”‚   β”œβ”€β”€ services
β”‚   β”‚   β”œβ”€β”€ sockets
β”‚   β”‚   β”œβ”€β”€ utils
β”‚   β”‚   β”œβ”€β”€ app.ts
β”‚   β”‚   └── server.ts
β”‚   β”‚
β”‚   β”œβ”€β”€ package.json
β”‚   └── .env
β”‚
β”œβ”€β”€ chat-frontend
β”‚   β”œβ”€β”€ src
β”‚   β”‚   β”œβ”€β”€ api
β”‚   β”‚   β”œβ”€β”€ components
β”‚   β”‚   β”œβ”€β”€ hooks
β”‚   β”‚   β”œβ”€β”€ pages
β”‚   β”‚   β”œβ”€β”€ services
β”‚   β”‚   β”œβ”€β”€ types
β”‚   β”‚   β”œβ”€β”€ App.tsx
β”‚   β”‚   └── main.tsx
β”‚   β”‚
β”‚   β”œβ”€β”€ package.json
β”‚   └── .env
β”‚
└── README.md

βš™οΈ Installation

1. Clone Repository

git clone https://github.com/your-username/chitchat.git

cd chitchat

Backend Setup

Navigate to backend

cd chat-backend

Install dependencies

npm install

Create a .env

PORT=5000

MONGODB_URI=your_mongodb_connection_string

CLIENT_URL=http://localhost:5173

Run development server

npm run dev

Backend runs on

http://localhost:5000

Frontend Setup

Navigate to frontend

cd chat-frontend

Install dependencies

npm install

Run frontend

npm run dev

Frontend runs on

http://localhost:5173

REST API

Send Message

POST

POST /api/messages

Get Chat History

GET

GET /api/messages

Socket.IO Events

Client β†’ Server

user-typing

socket.emit("user-typing")

user-stop-typing

socket.emit("user-stop-typing")

Server β†’ Client

new-message

Broadcasts every newly created message.

socket.on("new-message")

online-users

Broadcasts connected user count.

socket.on("online-users")

user-typing

Broadcasts when another user starts typing.

socket.on("user-typing")

user-stop-typing

Broadcasts when another user stops typing.

socket.on("user-stop-typing")

Design Decisions

The application follows a modular architecture to improve maintainability and scalability.

Backend

  • Controller-Service architecture
  • Socket events separated into dedicated socket modules
  • Environment variables centralized
  • Shared API response utility
  • MongoDB used for persistent storage

Frontend

  • Reusable components
  • Dedicated API layer
  • Dedicated Socket service
  • Type-safe models using TypeScript
  • Local state managed with React Hooks
  • Axios instance for API communication

Error Handling

The application gracefully handles:

  • Missing username
  • Empty messages
  • Database connection failures
  • Socket disconnections
  • Invalid API requests
  • Network failures
  • Empty chat history

Future Improvements

  • Private messaging
  • User avatars
  • Emoji support
  • Image sharing
  • File uploads
  • Read receipts
  • Delivered status
  • Message reactions
  • Group chats
  • Infinite scrolling
  • Docker support
  • Unit & Integration Tests
  • CI/CD Pipeline
  • Redis Adapter for multi-server Socket.IO deployment

Deployment

Frontend

Vercel

Backend

Render

Database

MongoDB Atlas

Author

Md Jillur Rahman

License

md.jillur.rahman

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages