Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

Professional WhatsApp Clone - A full-stack, production-ready chat application demonstrating. Built with Next.js 15, React 19, TypeScript, and Convex real-time database. it include real-time messaging, AI-powered chat assistance, media sharing, group conversations, user authentication, and responsive design.

Notifications You must be signed in to change notification settings

frckbrice/AI-powered-chat-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

45 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AI-Integrated WhatsApp Clone (WIP--work in progress)

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.

πŸ› οΈ Tech Stack

Frontend

  • 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

Backend & Database

  • Convex for real-time backend and database
  • Real-time Queries for live updates
  • File Storage for media uploads
  • User Authentication with Clerk integration

Real-time Communication

  • WebRTC for peer-to-peer video calls
  • ZegoCloud API for scalable video infrastructure
  • Real-time messaging with Convex
  • Live user presence and typing indicators

AI & External Services

  • OpenAI GPT-4 for intelligent chat responses
  • Multi-modal AI understanding (text, images, videos)
  • Context-aware conversations with memory
  • Smart message processing and routing

Development Tools

  • Yarn package manager
  • Vitest + Testing Library for testing
  • ESLint + prettier for code quality
  • Docker for containerization

πŸ—οΈ Architecture

System Overview

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       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Frontend Architecture

Next.js App Router Structure

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

Component Architecture

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

Backend Architecture (Convex)

Database Schema

// 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
}

Real-time Features

  • 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

HTTP Routes

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 Architecture

ZegoCloud Integration

// 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

WebRTC Implementation

  • Real-time Communication: Low-latency video/audio
  • Peer-to-Peer: Direct user connections
  • Fallback Support: ZegoCloud infrastructure backup
  • Quality Optimization: Adaptive bitrate and resolution

State Management

Client-Side State

// 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
}

Server-Side State

  • Convex Queries: Real-time data subscriptions
  • Optimistic Updates: Immediate UI feedback
  • Conflict Resolution: Automatic merge strategies
  • Offline Support: Local-first architecture

Data Flow Architecture

Message Flow

User Input β†’ Message Input β†’ Convex Mutation β†’ Database Update β†’
Real-time Query β†’ UI Update β†’ Other Users Receive

Media Flow

File Upload β†’ Convex Storage β†’ Generate URL β†’ Store Reference β†’
Message Creation β†’ Real-time Delivery β†’ Proxy Loading (if needed)

AI Integration Flow

User Message β†’ AI Processing β†’ OpenAI API β†’ Response Generation β†’
Message Creation β†’ Real-time Delivery β†’ Context Preservation

Video Call Flow

Call Initiation β†’ ZegoCloud Setup β†’ WebRTC Connection β†’
Peer Connection β†’ Video/Audio Stream β†’ Real-time Communication

Security Architecture

Authentication & Authorization

  • Clerk Integration: Secure user authentication
  • JWT Tokens: Stateless authentication
  • Role-based Access: User permissions and admin controls
  • Session Management: Secure session handling

Data Security

  • Input Validation: Server-side validation
  • SQL Injection Protection: Parameterized queries
  • XSS Prevention: Content sanitization
  • CORS Management: Controlled cross-origin access

Performance Architecture

Frontend Optimization

  • Code Splitting: Lazy-loaded components
  • Image Optimization: Next.js image optimization
  • Bundle Analysis: Webpack bundle optimization
  • PWA Support: Offline capabilities

Backend Optimization

  • Real-time Queries: Efficient data subscriptions
  • Indexing: Optimized database queries
  • Caching: Strategic data caching
  • CDN Integration: Global content delivery

Development Architecture

Code Organization

  • Feature-based Structure: Logical component grouping
  • API Separation: Clear separation of concerns
  • Type Safety: Full TypeScript coverage
  • Testing Strategy: Comprehensive test coverage

Build & Deployment

  • Multi-stage Docker: Optimized container builds
  • CI/CD Pipeline: Automated testing and deployment
  • Environment Management: Configurable deployments

Integration Points

External Services

  • Clerk: Authentication and user management
  • OpenAI: AI chat capabilities
  • Convex: Backend-as-a-Service
  • ZegoCloud: Video calling infrastructure
  • Vercel: Hosting and deployment (optional)

API Design

  • RESTful Endpoints: Standard HTTP methods
  • WebSocket Support: Real-time communication (convex)
  • Webhook Integration: Event-driven architecture (convex)

πŸš€ Getting Started

Prerequisites

  • 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)

Installation

  1. Clone the repository

    git clone <your-repo-url>
    cd whatsapp-clone
  2. Install dependencies

    yarn install
  3. Set up environment variables

    cp .env.example .env.local
    # Fill in your Convex, Clerk, ZegoCloud, and OpenAI credentials
  4. Start development server

    yarn dev
  5. Visit http://localhost:3000

🎯 Usage

Starting a Chat

  1. Click on a user or group from the left panel
  2. Type your message in the input field
  3. Send text, images, or videos
  4. Use AI chat by selecting ChatGPT from the conversation list
  5. Send message to chatgpt by starting the text message with @gpt your-message

Video Calling

  1. Start a Call: Click the camera icon in any conversation
  2. Group Calls: Invite multiple participants for group video chats
  3. Screen Sharing: Share your screen during calls
  4. Quality Control: Adjust video/audio settings in real-time

AI Features

  • 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

Group Management

  • Create Groups: Start group conversations
  • Add Members: Invite users to groups
  • Admin Controls: Manage group settings and members
  • Group Chat: Collaborate with multiple users

πŸ§ͺ Testing

Run the test suite:

# Run tests once
yarn test

# Run tests in watch mode
yarn test:watch

# Run tests with coverage
yarn test:coverage

πŸš€ Deployment

Production Build

yarn build
yarn start

Docker Deployment

docker build -t whatsapp-clone .
docker run -p 3000:3000 whatsapp-clone

Environment Variables

# 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_key

πŸ”§ Development

Available Scripts

  • yarn dev - Start development server
  • yarn build - Build for production
  • yarn start - Start production server
  • yarn lint - Run ESLint
  • yarn test - Run unit tests
  • yarn ci - Full CI pipeline (lint, test, build)

Code Quality

  • 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

🌟 Key Features

Real-time Communication

  • Instant message delivery
  • Live typing indicators
  • Real-time user presence
  • Live conversation updates

Video Calling

  • High-quality video calls with WebRTC
  • Group video conferencing support
  • Screen sharing capabilities
  • Cross-platform compatibility
  • ZegoCloud infrastructure for scalability

AI-Powered Chat

  • ChatGPT integration
  • Intelligent responses
  • Context awareness
  • Multi-modal understanding

Modern UI/UX

  • Responsive design
  • Dark/light themes
  • Smooth animations
  • Professional styling

Performance & Reliability

  • Optimized video loading
  • CORS proxy support
  • Offline capabilities
  • Progressive Web App

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License.

πŸ†˜ Support

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

About

Professional WhatsApp Clone - A full-stack, production-ready chat application demonstrating. Built with Next.js 15, React 19, TypeScript, and Convex real-time database. it include real-time messaging, AI-powered chat assistance, media sharing, group conversations, user authentication, and responsive design.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages