A Next.js application that enables real-time chat synchronization across multiple devices. Watch your conversations update simultaneously on different browsers or devices!
DO NOT USE IN PRODUCTION! This application uses aggressive polling to synchronize chat messages across devices. This implementation will result in:
- Extremely high API call volumes (requests every 2 seconds per active client)
- Skyrocketing costs if deployed to production
- Rate limiting issues with most hosting providers
- Poor scalability and server resource exhaustion
This is a demonstration/development project only. For production use, implement proper WebSocket connections, Server-Sent Events (SSE), or a real-time database solution instead.
- Next.js 16.0.1 - React framework with App Router
- React 19.2.0 - UI library
- TypeScript 5 - Type safety
- Tailwind CSS 4 - Utility-first CSS framework
- Lucide React - Icon library
- SweetAlert2 - Beautiful alert modals
- Vercel Analytics - Web analytics
Before you begin, ensure you have the following installed:
- Node.js (v18 or higher recommended)
- npm (comes with Node.js) or yarn
-
Clone the repository
git clone https://github.com/siyabuilds/chatduo.git cd chatduo -
Install dependencies
npm install
-
Run the development server
npm run dev
-
Open in your browser Navigate to http://localhost:3000
- Open the application in your default browser
- Start a new chat or join an existing one (use the chat ID from the URL)
- Open the same URL in a different browser or incognito window
- Type messages in one browser and watch them appear in the other in real-time!
- Start the development server on your primary device
- Find your local IP address:
- Linux/Mac: Run
ip addr showorifconfig(look for 192.168.x.x) - Windows: Run
ipconfig(look for IPv4 Address)
- Linux/Mac: Run
- On your other devices, navigate to
http://YOUR_IP_ADDRESS:3000- Example:
http://192.168.1.100:3000
- Example:
- Open the same chat on both devices and watch the magic happen!
- Install ngrok
- Start your dev server:
npm run dev - In a new terminal:
ngrok http 3000 - Use the ngrok URL on any device anywhere in the world
- Start a new chat: Click "Start New Chat" on the homepage
- Share the chat: Copy the URL from your browser and share it with another device/browser
- Send messages: Type your message and press Enter or click Send
- Real-time sync: Messages appear instantly across all connected devices
# Build for production (but remember the warning above!)
npm run build
# Start production server
npm start
# Run linter
npm run lintchatduo/
├── app/
│ ├── api/chat/[chatId]/ # API routes for chat operations
│ ├── chat/[chatId]/ # Dynamic chat pages
│ ├── utils/ # Utility functions (chatMap)
│ ├── globals.css # Global styles
│ ├── layout.tsx # Root layout
│ └── page.tsx # Homepage
├── public/ # Static assets
└── Configuration files
ChatDuo uses an in-memory Map to store chat messages on the server. Each client polls the server every 2 seconds to check for new messages. This approach:
- ✅ Works without a database
- ✅ Simple to understand and implement
- ❌ Doesn't scale
- ❌ Loses data on server restart
- ❌ Creates excessive API calls
- ❌ Expensive in production environments
This is a demonstration project. Feel free to fork and experiment, but please heed the production warning!
Remember: This is a learning/demo project. Never deploy this polling approach to production! 🚨