A modern, real-time chat application that breaks language barriers by automatically translating messages between users who speak different languages. Built with React.js, Node.js, Express.js, MongoDB, Socket.io, and Google's Gemini API.
- Simple Registration: Sign up with just your name, phone number, and preferred language
- OTP Verification: Secure phone number verification with OTP
- Auto-Login: Seamless login experience for returning users
- Development Mode: OTP displayed on screen/console for easy testing
- Real-Time Translation: Messages automatically translated using Google's Gemini API
- 22+ Languages Supported: Including English, Hindi, Spanish, French, German, Arabic, Chinese, and more
- Bidirectional Translation: Both users see messages in their preferred language
- Original Text Preservation: Original messages stored alongside translations
- Instant Messaging: Real-time message delivery using Socket.io
- Typing Indicators: See when someone is typing
- Online/Offline Status: Accurate presence detection
- Message Delivery Status: Read receipts and delivery confirmations
- Persistent Messages: Messages delivered even when recipient is offline
- Automatic Contact List: All registered users visible like WhatsApp
- Smart Search: Find users by name or phone number
- Language Indicators: See each user's preferred language
- Dark Theme: Beautiful dark interface optimized for messaging
- Responsive Design: Works seamlessly on desktop and mobile
- Smooth Animations: Polished user experience with subtle animations
- Accessibility: Built with accessibility best practices
- React 18: Modern React with hooks and context
- Tailwind CSS: Utility-first CSS framework
- Socket.io Client: Real-time communication
- React Router: Client-side routing
- React Hot Toast: Beautiful notifications
- Lucide React: Modern icon library
- Node.js: JavaScript runtime
- Express.js: Web application framework
- Socket.io: Real-time bidirectional communication
- MongoDB: NoSQL database with Mongoose ODM
- JWT: JSON Web Token authentication
- Google Gemini API: AI-powered translation
- Vercel: Deployment platform
- MongoDB Atlas: Cloud database
- Environment Variables: Secure configuration management
- Node.js 16+ and npm
- MongoDB database (local or Atlas)
- Google Gemini API key
git clone https://github.com/Rajkoli145/New-chatting-App.git
cd New-chatting-App# Install root dependencies
npm install
# Install all dependencies (root, backend, frontend)
npm run install-deps
# Or install individually:
npm run install-backend # Install backend dependencies
npm run install-frontend # Install frontend dependenciescd backend
cp .env.example .envEdit backend/.env:
# Database
MONGODB_URI=mongodb://localhost:27017/cross-lingo-chat
# Or for MongoDB Atlas:
# MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/cross-lingo-chat
# JWT Secret (generate a secure random string)
JWT_SECRET=your-super-secret-jwt-key-here
# Gemini API Key (get from Google AI Studio)
GEMINI_API_KEY=your-gemini-api-key-here
# Optional: Twilio for real SMS (for production)
TWILIO_ACCOUNT_SID=your-twilio-account-sid
TWILIO_AUTH_TOKEN=your-twilio-auth-token
TWILIO_PHONE_NUMBER=your-twilio-phone-number
# Server Configuration
PORT=5001
NODE_ENV=development
CLIENT_URL=http://localhost:3000cd frontend
cp .env.example .envEdit frontend/.env:
REACT_APP_API_URL=http://localhost:5001/api
REACT_APP_SERVER_URL=http://localhost:5001# From root directory - starts both backend and frontend
npm run dev
# Or start individually:
# npm run backend (starts backend on port 5001)
# npm run frontend (starts frontend on port 3000)- Frontend: http://localhost:3000
- Backend API: http://localhost:5001/api
- Health Check: http://localhost:5001/api/health
POST /api/auth/register- Register new userPOST /api/auth/verify-otp- Verify OTP and complete registrationPOST /api/auth/login- Login existing userPOST /api/auth/resend-otp- Resend OTPGET /api/auth/profile- Get user profilePUT /api/auth/profile- Update user profile
GET /api/users/all- Get all usersGET /api/users/search?q=query- Search usersGET /api/users/:userId- Get user by IDGET /api/users/stats/online- Get online user stats
GET /api/messages/conversations- Get user conversationsGET /api/messages/conversation/:id- Get conversation messagesPOST /api/messages/send- Send messagePUT /api/messages/read/:conversationId- Mark messages as readGET /api/messages/unread-count- Get unread message count
join-conversation- Join conversation roomsend-message- Send new messagetyping-start- Start typing indicatortyping-stop- Stop typing indicatormark-messages-read- Mark messages as read
new-message- Receive new messagemessage-sent- Message delivery confirmationuser-typing- User typing statususer-online- User came onlineuser-offline- User went offlinemessages-read- Messages read receipt
# Build the client
cd client
npm run buildIn your Vercel dashboard, add these environment variables:
MONGODB_URI: Your MongoDB Atlas connection stringJWT_SECRET: Secure random string for JWT signingGEMINI_API_KEY: Your Google Gemini API keyNODE_ENV:production
# Install Vercel CLI
npm i -g vercel
# Deploy
vercel --prodAfter deployment, update client/.env:
REACT_APP_API_URL=https://your-app.vercel.app/api
REACT_APP_SERVER_URL=https://your-app.vercel.app{
name: String, // User's full name
phone: String, // Phone number (unique)
preferredLanguage: String, // Language code (en, hi, es, etc.)
isOnline: Boolean, // Current online status
lastSeen: Date, // Last activity timestamp
socketId: String, // Current socket connection ID
isVerified: Boolean, // Phone verification status
avatar: String // Profile picture URL
}{
participants: [ObjectId], // Array of user IDs (exactly 2)
lastMessage: ObjectId, // Reference to last message
lastMessageTime: Date, // Timestamp of last message
isActive: Boolean // Conversation status
}{
conversationId: ObjectId, // Reference to conversation
sender: ObjectId, // Reference to sender user
originalText: String, // Original message text
translatedText: String, // Translated message text
senderLanguage: String, // Sender's language code
recipientLanguage: String, // Recipient's language code
messageType: String, // 'text', 'image', 'file', 'system'
isRead: Boolean, // Read status
readAt: Date, // Read timestamp
isDelivered: Boolean, // Delivery status
deliveredAt: Date, // Delivery timestamp
isTranslated: Boolean // Translation status
}{
phone: String, // Phone number
otpCode: String, // 6-digit OTP code
expiresAt: Date, // Expiration timestamp (10 minutes)
isVerified: Boolean, // Verification status
attempts: Number, // Number of verification attempts
isUsed: Boolean // Usage status
}The application supports 22+ languages:
- English (en), Hindi (hi), Spanish (es), French (fr)
- German (de), Italian (it), Portuguese (pt), Russian (ru)
- Japanese (ja), Korean (ko), Chinese (zh), Arabic (ar)
- Bengali (bn), Urdu (ur), Tamil (ta), Telugu (te)
- Malayalam (ml), Kannada (kn), Gujarati (gu), Punjabi (pa)
- Marathi (mr), Odia (or)
The app uses Google's Gemini API for translation with fallback handling:
- Primary: Gemini Pro model for accurate translations
- Fallback: Returns original text if translation fails
- Language Detection: Automatic detection of source language
- JWT token authentication with 7-day expiration
- Rate limiting on API endpoints
- Input validation and sanitization
- CORS configuration for secure cross-origin requests
- Helmet.js for security headers
# Backend tests
cd backend
npm test
# Frontend tests
cd frontend
npm testβββ backend/ # Backend application
β βββ models/ # MongoDB models
β βββ routes/ # API routes
β βββ services/ # Business logic services
β βββ middleware/ # Custom middleware
β βββ socket/ # Socket.io handlers
β βββ index.js # Server entry point
βββ frontend/ # Frontend application
β βββ src/
β β βββ components/ # React components
β β βββ contexts/ # React context providers
β β βββ pages/ # Page components
β β βββ utils/ # Utility functions
β β βββ App.js # App entry point
β βββ public/ # Static assets
βββ vercel.json # Vercel deployment config
# Root level
npm run dev # Start both backend and frontend
npm run backend # Start backend only
npm run frontend # Start frontend only
npm run build # Build frontend for production
npm run install-deps # Install all dependencies
# Backend level
npm start # Start production server
npm run dev # Start development server with nodemon
# Frontend level
npm start # Start development server
npm run build # Build for production
npm test # Run tests- 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 MIT License - see the LICENSE file for details.
If you encounter any issues or have questions:
- Check the Issues page
- Create a new issue with detailed information
- Include error logs and steps to reproduce
- Google Gemini API for powerful translation capabilities
- Socket.io for real-time communication
- Tailwind CSS for beautiful styling
- MongoDB for flexible data storage
- Vercel for seamless deployment
Built with β€οΈ by Raj Koli