NextChat is a real-time chat application built with Next.js, Socket.IO, MongoDB, and NextAuth. It supports both one-on-one and group messaging, enabling users to communicate instantly with rich features such as typing indicators, online status, group administration, and cross-provider authentication. Messages are stored in MongoDB and delivered in real-time for a seamless chat experience.
- ⚡ Frontend & Backend: Next.js (API Routes used as backend)
- 🔌 WebSocket Communication: Socket.IO
- 🧠 Database: MongoDB & Mongoose
- 🔐 Authentication: NextAuth.js (OAuth providers: Google, Microsoft)
- ☁️ Deployment-Ready: Built with performance and scalability in mind
-
🗨️ One-to-One & Group Chats
- Create, manage, and leave group conversations
- Assign group admins with control over membership
-
👤 Real-Time Authentication with OAuth
- Secure login via Google Facebook Github and Microsoft
- Unified user accounts: When a user logs in with multiple providers, their account is merged and tracked via
providersarray in the DB
-
🧑🤝🧑 Group Management
- Admins can add/remove members
- Group messages delivered instantly with sender info (name + image)
-
💬 Real-Time Messaging
- Instant message delivery using Socket.IO
- Optimized filtering and ordering based on the latest message
- Smooth scrolling and live updates in chat window and chat list
-
🟢 User Presence Detection
- See who's online
- Detect when a user is typing in real time
-
🧾 Message Persistence
- Messages are stored in MongoDB with sender and receiver ID
- Ensures consistency, history tracking, and persistence across sessions
-
🧠 Database-Optimized Architecture
- Efficient message structure:
{ "_id": "6838583092c3d73faa3abf3e", "chatId": "68361f01a0d760c48b3be0f1", "senderId": "6833256a380d1d2bdeeabda0", "receiverId": "683325eda6319d7b1f0aa634", "message": "hi", "createdAt": "2025-05-29T12:50:56.136Z", "updatedAt": "2025-05-29T12:50:56.136Z" }
- Efficient message structure:
-
👨💼 User Schema Sample
{ "_id": "6833256a380d1d2bdeeabda0", "name": "Shayan Kashif", "email": "shayanfarooqui789@gmail.com", "image": "https://freepngimg.com/thumb/email_marketing/2-2-email-internet-png.png", "providers": ["azure-ad", "google"], "accountId": "AAAAAAAAAAAAAAAAAAAAACaW0hVJn82GDNGQ4Ql1kWM" }
# Clone the repository
git clone https://github.com/your-username/nextchat.git
cd nextchat
# Install dependencies
npm install
# Run the development server
npm run dev