A modern, feature-rich WhatsApp-like chat application built with Next.js, featuring AI chat integration, real-time messaging, video calling, and a beautiful, responsive UI.
- Next.js 15 (App Router) + React 19
- TypeScript for type safety
- Tailwind CSS 3 for styling
- shadcn + Radix UI for accessible components
- Lucide React for beautiful icons
- Convex for real-time backend and database
- Real-time Queries for live updates
- File Storage for media uploads
- User Authentication with Clerk integration
- WebRTC for peer-to-peer video calls
- ZegoCloud API for scalable video infrastructure
- Real-time messaging with Convex
- Live user presence and typing indicators
- OpenAI GPT-4 for intelligent chat responses
- Multi-modal AI understanding (text, images, videos)
- Context-aware conversations with memory
- Smart message processing and routing
- Yarn package manager
- Vitest + Testing Library for testing
- ESLint + prettier for code quality
- Docker for containerization
This project follows a modern, scalable architecture with clear separation of concerns, real-time capabilities, AI integration, and video calling infrastructure.
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Frontend β β Backend β β External β
β (Next.js) βββββΊβ (Convex) βββββΊβ Services β
β β β β β β
β β’ React 19 β β β’ Real-time DB β β β’ Clerk Auth β
β β’ TypeScript β β β’ File Storage β β β’ OpenAI API β
β β’ Tailwind CSS β β β’ Webhooks β β β’ ZegoCloud β
β β’ PWA Support β β β’ HTTP Routes β β β’ WebRTC β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
src/
βββ app/ # Next.js App Router
β βββ api/ # API Routes
β β βββ video-proxy/ # Video CORS proxy
β β βββ zego-cloud/ # ZegoCloud integration
β βββ globals.css # Global styles
β βββ layout.tsx # Root layout
β βββ page.tsx # Home page
β βββ sign-in/ # Authentication pages
β βββ video-call/ # Video calling interface
βββ components/ # Reusable UI components
β βββ home/ # Main chat components
β βββ providers/ # Context providers
β β βββ convex/ # Convex client provider
β β βββ theme/ # Theme provider
β βββ ui/ # Base UI components
β βββ video-call/ # Video calling components
β βββ types.ts # TypeScript definitions
βββ hooks/ # Custom React hooks
βββ lib/ # Utility functions
βββ store/ # State management
βββ test/ # Test configuration
src/components/home/
βββ chat-bubble/ # Chat message system
β βββ components/ # Message components
β β βββ chat-bubble.tsx # Main message component
β β βββ video-message.tsx # Video handling with proxy
β β βββ image-message.tsx # Image display
β β βββ text-message.tsx # Text messages
β β βββ message-time.tsx # Timestamps
β β βββ chat-avatar-action.tsx # Message actions
β β βββ date-indicator.tsx # Date separators
β βββ api/ # Message utilities
β β βββ message-utils.ts # Formatting & styling
β β βββ video-utils.ts # Video processing
β βββ index.tsx # Feature exports
βββ conversation/ # Conversation management
βββ message-input/ # Message composition
βββ media-dropdown/ # File upload system
βββ left-panel/ # Navigation sidebar
βββ right-panel/ # Chat interface
βββ message-container/ # Message display area
βββ user-list-dialog/ # User management
βββ group-members-dialog/ # Group administration
βββ index.tsx # Main exports
src/components/video-call/
βββ api/
β βββ zegoc-cloud-assistant.ts # ZegoCloud integration
βββ components/
βββ video-ui-kit.tsx # Video calling interface
// Core entities
users: {
_id: Id<"users">
tokenIdentifier: string
name: string
email: string
image: string
isOnline: boolean
lastSeen: number
}
conversations: {
_id: Id<"conversations">
name: string
participants: Id<"users">[]
isGroup: boolean
admin?: Id<"users">
lastMessage?: Id<"messages">
createdAt: number
}
messages: {
_id: Id<"messages">
conversationId: Id<"conversations">
sender: Id<"users">
content: string
messageType: "text" | "image" | "video"
_creationTime: number
}- Live Queries: Automatic UI updates when data changes
- Mutations: Server-side data modifications with validation
- Actions: Complex operations with external API calls
- Webhooks: Integration with Clerk authentication
- File Storage: Secure media file handling
convex/http.ts
βββ /clerk # Clerk webhook handler
β βββ user.created # User registration
β βββ user.updated # Profile updates
β βββ session.created # User login
β βββ session.ended # User logout
βββ /video-proxy # Video CORS proxy
// Video calling infrastructure
src/components/video-call/
βββ api/
β βββ zegoc-cloud-assistant.ts # ZegoCloud API integration
βββ components/
βββ video-ui-kit.tsx # Video calling interface
// Key features:
- Peer-to-peer video calls
- Group video conferencing
- Screen sharing capabilities
- High-quality video streaming
- Cross-platform compatibility- Real-time Communication: Low-latency video/audio
- Peer-to-Peer: Direct user connections
- Fallback Support: ZegoCloud infrastructure backup
- Quality Optimization: Adaptive bitrate and resolution
// Chat Store (Zustand)
useConversationStore: {
selectedConversation: Conversation | null
setSelectedConversation: (conv: Conversation) => void
// ... other state and actions
}
// Theme Store
useThemeStore: {
theme: "light" | "dark" | "system"
setTheme: (theme: Theme) => void
}- Convex Queries: Real-time data subscriptions
- Optimistic Updates: Immediate UI feedback
- Conflict Resolution: Automatic merge strategies
- Offline Support: Local-first architecture
User Input β Message Input β Convex Mutation β Database Update β
Real-time Query β UI Update β Other Users Receive
File Upload β Convex Storage β Generate URL β Store Reference β
Message Creation β Real-time Delivery β Proxy Loading (if needed)
User Message β AI Processing β OpenAI API β Response Generation β
Message Creation β Real-time Delivery β Context Preservation
Call Initiation β ZegoCloud Setup β WebRTC Connection β
Peer Connection β Video/Audio Stream β Real-time Communication
- Clerk Integration: Secure user authentication
- JWT Tokens: Stateless authentication
- Role-based Access: User permissions and admin controls
- Session Management: Secure session handling
- Input Validation: Server-side validation
- SQL Injection Protection: Parameterized queries
- XSS Prevention: Content sanitization
- CORS Management: Controlled cross-origin access
- Code Splitting: Lazy-loaded components
- Image Optimization: Next.js image optimization
- Bundle Analysis: Webpack bundle optimization
- PWA Support: Offline capabilities
- Real-time Queries: Efficient data subscriptions
- Indexing: Optimized database queries
- Caching: Strategic data caching
- CDN Integration: Global content delivery
- Feature-based Structure: Logical component grouping
- API Separation: Clear separation of concerns
- Type Safety: Full TypeScript coverage
- Testing Strategy: Comprehensive test coverage
- Multi-stage Docker: Optimized container builds
- CI/CD Pipeline: Automated testing and deployment
- Environment Management: Configurable deployments
- Clerk: Authentication and user management
- OpenAI: AI chat capabilities
- Convex: Backend-as-a-Service
- ZegoCloud: Video calling infrastructure
- Vercel: Hosting and deployment (optional)
- RESTful Endpoints: Standard HTTP methods
- WebSocket Support: Real-time communication (convex)
- Webhook Integration: Event-driven architecture (convex)
- Node.js 22+
- Yarn package manager
- Convex account (for backend)
- Clerk account (for authentication)
- ZegoCloud account (for video calls)
- OpenAI API key (for AI features)
-
Clone the repository
git clone <your-repo-url> cd whatsapp-clone
-
Install dependencies
yarn install
-
Set up environment variables
cp .env.example .env.local # Fill in your Convex, Clerk, ZegoCloud, and OpenAI credentials -
Start development server
yarn dev
-
Visit
http://localhost:3000
- Click on a user or group from the left panel
- Type your message in the input field
- Send text, images, or videos
- Use AI chat by selecting ChatGPT from the conversation list
- Send message to chatgpt by starting the text message with
@gpt your-message
- Start a Call: Click the camera icon in any conversation
- Group Calls: Invite multiple participants for group video chats
- Screen Sharing: Share your screen during calls
- Quality Control: Adjust video/audio settings in real-time
- Chat with AI: Start conversations with ChatGPT
- Smart Responses: Get intelligent, context-aware replies
- Media Understanding: AI can process and respond to images/videos
- Conversation Memory: AI remembers conversation context
- Create Groups: Start group conversations
- Add Members: Invite users to groups
- Admin Controls: Manage group settings and members
- Group Chat: Collaborate with multiple users
Run the test suite:
# Run tests once
yarn test
# Run tests in watch mode
yarn test:watch
# Run tests with coverage
yarn test:coverageyarn build
yarn startdocker build -t whatsapp-clone .
docker run -p 3000:3000 whatsapp-clone# Convex Configuration
NEXT_PUBLIC_CONVEX_URL=your_convex_url
# Clerk Authentication
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=your_clerk_key
CLERK_SECRET_KEY=your_clerk_secret
# ZegoCloud Video Calling
ZEGOCLOUD_APP_ID=your_zegocloud_app_id
ZEGOCLOUD_SERVER_SECRET=your_zegocloud_secret
# AI Integration
OPENAI_API_KEY=your_openai_keyyarn dev- Start development serveryarn build- Build for productionyarn start- Start production serveryarn lint- Run ESLintyarn test- Run unit testsyarn ci- Full CI pipeline (lint, test, build)
- ESLint: Code linting and formatting
- TypeScript: Static type checking
- Prettier: Code formatting
- Husky: Git hooks for quality checks
- CodeRabbit: AI-powered code review and suggestions
- Automatic PR Reviews: AI analyzes code for performance, errors, and maintainability
- Code Quality Insights: Identifies potential issues and suggests improvements
- Test Coverage Analysis: Ensures comprehensive testing coverage
- Performance Optimization: Suggests performance improvements
- Security Scanning: Detects potential security vulnerabilities
- Instant message delivery
- Live typing indicators
- Real-time user presence
- Live conversation updates
- High-quality video calls with WebRTC
- Group video conferencing support
- Screen sharing capabilities
- Cross-platform compatibility
- ZegoCloud infrastructure for scalability
- ChatGPT integration
- Intelligent responses
- Context awareness
- Multi-modal understanding
- Responsive design
- Dark/light themes
- Smooth animations
- Professional styling
- Optimized video loading
- CORS proxy support
- Offline capabilities
- Progressive Web App
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License.
For support and questions:
- Create an issue in the repository
- Check the documentation
- Review the component README files
Built with β€οΈ using Next.js, React, and modern web technologies