A real-time anonymous chat application with voice calling capabilities, built with React and Node.js. Phantom provides secure, instant messaging with WebRTC-powered voice calls in private chat rooms.
- Real-time Messaging: Instant message delivery using Socket.io
- Voice Calling: WebRTC-based peer-to-peer voice calls with Opus codec prioritization
- Room-based Chat: Create or join chat rooms with unique room IDs
- Message Persistence: Chat history stored in MongoDB (last 50 messages per room)
- User Authentication: Secure user registration with bcrypt password hashing
- Online User List: See who's online in your chat room
- Active Rooms Display: Browse and join active chat rooms from the homepage
- Retro-themed Design: Vintage-inspired UI with custom styling
- Responsive Layout: Works seamlessly on desktop and mobile devices
- Toast Notifications: User-friendly notifications using react-hot-toast
- Smooth Animations: Polished user experience with smooth transitions
- React 19.1.1 - UI library
- Vite 7.1.2 - Build tool and dev server
- React Router DOM 7.8.2 - Client-side routing
- Socket.io Client 4.8.1 - Real-time communication
- Tailwind CSS 4.1.12 - Utility-first CSS framework
- React Hot Toast 2.6.0 - Toast notifications
- React Icons 4.11.0 - Icon library
- UUID 11.1.0 - Unique ID generation
- Node.js - Runtime environment
- Express 5.1.0 - Web framework
- Socket.io 4.8.1 - Real-time bidirectional communication
- MongoDB - NoSQL database
- Mongoose 8.19.2 - MongoDB object modeling
- bcryptjs 3.2.2 - Password hashing
- jsonwebtoken 9.0.2 - JWT authentication
- CORS 2.8.5 - Cross-origin resource sharing
- dotenv 17.2.3 - Environment variable management
- STUN Server: Google's public STUN server
- TURN Server: ExpressTurn relay server for NAT traversal
- Opus Codec: Prioritized for high-quality audio
Phantom/
├── client/ # Frontend React application
│ ├── public/ # Static assets
│ ├── src/
│ │ ├── components/ # Reusable React components
│ │ │ ├── AuthForm.jsx
│ │ │ ├── CallUI.jsx
│ │ │ └── UsernameModal.jsx
│ │ ├── pages/ # Page components
│ │ │ ├── ChatRoom.jsx
│ │ │ ├── HomePage.jsx
│ │ │ ├── NotFound.jsx
│ │ │ └── Register.jsx
│ │ ├── App.jsx # Main app component
│ │ ├── App.css # Global styles
│ │ ├── index.css # Base styles
│ │ └── main.jsx # Entry point
│ ├── package.json
│ ├── vite.config.js
│ └── vercel.json # Vercel deployment config
│
└── server/ # Backend Node.js application
├── models/ # MongoDB models
│ ├── user.js
│ └── userMessage.js
├── routes/ # API routes
│ └── user.js
├── src/
│ └── server.js # Main server file
└── package.json
Before you begin, ensure you have the following installed:
- Node.js (v18 or higher)
- npm or yarn
- MongoDB (local instance or MongoDB Atlas account)
git clone <repository-url>
cd Phantomcd client
npm installcd ../server
npm installCreate a .env file in the server/ directory:
MONGO_URL=your_mongodb_connection_string
PORT=3000
JWT_SECRET=your_jwt_secret_keyCreate a .env file in the client/ directory:
VITE_BACKEND_URL=http://localhost:3000For production, set VITE_BACKEND_URL to your deployed backend URL.
cd server
npm run devThe server will start on http://localhost:3000 (or the port specified in your .env file).
In a new terminal:
cd client
npm run devThe client will start on http://localhost:5173 (default Vite port).
cd client
npm run buildThe production build will be created in the client/dist/ directory.
cd server
npm start- Navigate to the homepage
- Click "Create Private Chat Room"
- Enter your username when prompted
- Share the room ID with others to invite them
- From the homepage, browse active rooms or enter a room ID
- Click "Join" on an active room or navigate to
/chat/{roomId} - Enter your username when prompted
- Click the users icon to view online users
- Click the phone icon next to a user to start a call
- Accept or decline incoming calls
- Use the mute button during calls
- End calls using the end call button
- Type messages in the input field at the bottom
- Press Enter or click the send button
- Messages are delivered instantly to all users in the room
- Chat history (last 50 messages) is loaded when joining a room
POST /api/users/register
Content-Type: application/json
{
"username": "string",
"password": "string"
}
-
join_room- Join a chat room{ roomId: string, username: string }
-
send_message- Send a message{ roomId: string, sender: string, content: string, timestamp: string }
-
get_rooms- Get list of active rooms -
call-user- Initiate a voice call{ to: string, from: object, offer: RTCSessionDescription }
-
make-answer- Answer an incoming call{ to: string, answer: RTCSessionDescription }
-
ice-candidate- Send ICE candidate for WebRTC{ to: string, candidate: RTCIceCandidate }
-
end-call- End an active call{ roomId: string }
receive_message- Receive a new messageupdate_user_list- Update list of online usersload_old_messages- Load chat historyrooms_list- List of active roomscall-made- Incoming call notificationanswer-made- Call answer receivedice-candidate- ICE candidate for WebRTCcall_in_progress- Notification that a call is activecall_ended- Call ended notificationmessage_error- Message sending error
{
username: String (unique, required),
password: String (hashed, required)
}{
sender: String (required),
content: String (required, maxlength: 1000),
roomId: String (required, indexed),
messageType: String (enum: ['text', 'image', 'file'], default: 'text'),
createdAt: Date,
updatedAt: Date
}The project includes a vercel.json configuration file for easy deployment to Vercel:
- Push your code to GitHub
- Import the project in Vercel
- Set the
VITE_BACKEND_URLenvironment variable - Deploy
Deploy the server to platforms like:
- Heroku
- Railway
- Render
- DigitalOcean
- AWS EC2
Make sure to:
- Set all environment variables
- Configure MongoDB connection (use MongoDB Atlas for cloud)
- Update CORS settings for production
- Set up proper SSL/TLS certificates
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the ISC License.
For issues, questions, or contributions, please open an issue on the GitHub repository.
- Socket.io for real-time communication
- WebRTC for peer-to-peer voice calling
- React and Vite teams for excellent tooling
- MongoDB for database solutions
Phantom - Anonymous • Secure • Instant
