Skip to content

Dryex-yo/whatsapp-clone

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

52 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’¬ WhatsApp Clone - Real-Time Chat Application

Laravel 12 React 18 TypeScript Tailwind CSS MIT License

Aplikasi Chat Real-Time Modern dengan Fitur Lengkap & Performa Tinggi

Fitur β€’ Tech Stack β€’ Setup β€’ Dokumentasi β€’ Kontribusi


πŸ“‹ Daftar Isi


Tentang Proyek

WhatsApp Clone adalah aplikasi chat real-time yang meniru fitur dan desain WhatsApp Web. Dibangun dengan teknologi modern, aplikasi ini menampilkan arsitektur yang scalable, performa tinggi, dan user experience yang responsif.

Proyek ini menggunakan Laravel 12 untuk backend API, React 18 dengan Inertia.js untuk frontend, dan Tailwind CSS untuk styling yang elegan. Semua fitur dirancang untuk memberikan pengalaman pengguna yang seamless dengan optimasi database yang minimal N+1 queries.


✨ Fitur Utama

πŸ—¨οΈ Chat & Messaging

  • Percakapan 1-on-1 - Komunikasi langsung antar pengguna
  • Grup Chat - Buat dan kelola grup dengan multiple members
  • Pesan Teks - Kirim dan terima pesan dengan real-time delivery
  • Pesan Media - Upload dan share file, gambar dengan batasan 50MB
  • Pesan Hilang - Atur pesan untuk otomatis hilang setelah waktu tertentu
  • Pesan Terenkripsi - End-to-end encryption untuk privasi maksimal
  • Typing Indicator - Lihat ketika orang lain sedang mengetik
  • Delivery Status - Indikator sent, delivered, dan read

πŸ‘₯ Manajemen Kontak

  • Search Kontak - Cari pengguna dengan case-insensitive search (email, phone, name)
  • Pengguna di Sekitar - Temukan pengguna terdekat menggunakan geolocation (Haversine formula)
  • Exact Email Match - Pencarian email yang presisi dengan trim() otomatis
  • Profil Pengguna - Lihat informasi lengkap kontak dengan last seen status
  • Block/Unblock Users - Blokir pengguna yang tidak diinginkan
  • Blocking Privacy - Pengguna terblokir tidak bisa melihat status online Anda

πŸ”” Notifikasi & Status

  • Online Status - Lihat siapa yang sedang online (real-time presence)
  • Last Seen - Informasi kapan terakhir kali pengguna online
  • Presence Channels - Real-time update status online/offline via WebSocket (Laravel Reverb)
  • Web Notifications - Browser notifications untuk pesan masuk
  • Sound Alerts - Notifikasi audio saat ada pesan baru
  • Favicon Badge - Indikator unread count di browser tab

⭐ Pesan Spesial

  • Starred Messages - Tandai pesan penting untuk referensi cepat
  • Message Search - Cari pesan dalam percakapan atau secara global
  • Message Edit - Edit pesan yang sudah terkirim
  • Message Delete - Hapus pesan untuk semua atau hanya Anda
  • Reaction Support - Tambah emoji reactions pada pesan

πŸ‘€ Profil & Pengaturan

  • Profil Pengguna - Edit nama, bio, foto profil, nomor telepon
  • Avatar Upload - Crop dan upload foto profil dengan preview
  • Privacy Settings - Kontrol privasi last seen
  • Theme Selection - Pilih dark/light/system theme
  • Two-Factor Auth - Keamanan login dengan 2FA (optional)

πŸ€– AI Assistant

  • Meta AI Integration - Chatbot AI powered untuk assistance
  • Smart Responses - AI memberikan saran respons cerdas
  • Job Queue - Background job processing untuk AI responses
  • Rate Limiting - Proteksi dari spam dengan rate limiting

🎨 UI/UX Modern

  • Responsive Design - Sempurna di desktop, tablet, dan mobile
  • Dark/Light Mode - Tema yang dapat disesuaikan
  • Smooth Animations - Animasi halus menggunakan Framer Motion
  • Loading States - Skeleton loader dan loading indicators
  • Error Handling - Error messages yang user-friendly
  • Real-time Updates - Data update real-time tanpa refresh manual

πŸ› οΈ Tech Stack

Backend

Teknologi Versi Deskripsi
Laravel 12 Framework PHP modern dengan Eloquent ORM
PHP 8.2+ Server-side language
PostgreSQL 14+ Database relational yang powerful
Laravel Reverb 1.0 WebSocket server untuk real-time features
Laravel Sanctum 4.0 API authentication dengan token
Intervention Image 3.0 Image processing dan manipulation

Frontend

Teknologi Versi Deskripsi
React 18 UI library dengan component-based approach
TypeScript 5.0 Type-safe JavaScript development
Inertia.js 2.0 Adapter antara Laravel & React
Tailwind CSS 3.2 Utility-first CSS framework
Framer Motion 12 Animation library untuk smooth UX
Vite 7 Lightning-fast build tool

Tools & Libraries

  • Laravel Echo React - Real-time event broadcasting
  • Axios - HTTP client untuk API requests
  • CryptoJS - Client-side encryption
  • DOMPurify - XSS protection untuk user content
  • Lucide React - Icon library yang modern
  • Vitest - Unit testing framework
  • Pest PHP - PHP testing framework

πŸ“¦ Prasyarat

Pastikan Anda sudah menginstall:

Opsional untuk Fitur Real-Time:

  • Redis - Untuk caching dan queue
  • Laravel Reverb - Untuk WebSocket server

πŸš€ Instalasi & Konfigurasi

1. Clone Repository

git clone https://github.com/yourusername/whatsapp-clone.git
cd whatsapp-clone

2. Setup Backend (Laravel)

# Install PHP dependencies
composer install

# Copy environment file
cp .env.example .env

# Generate application key
php artisan key:generate

# Configure database di .env
# DB_CONNECTION=pgsql
# DB_HOST=127.0.0.1
# DB_PORT=5432
# DB_DATABASE=whatsapp_clone
# DB_USERNAME=postgres
# DB_PASSWORD=yourpassword

# Jalankan migrations & seeders
php artisan migrate --seed

# Storage link untuk file uploads
php artisan storage:link

3. Setup Frontend (React + Vite)

# Install Node dependencies
npm install

# Setup development server (run di terminal terpisah)
npm run dev

# Untuk production build
npm run build

4. Jalankan Aplikasi

# Terminal 1: Laravel development server
php artisan serve
# Aplikasi akan berjalan di http://localhost:8000

# Terminal 2: Vite dev server
npm run dev
# Frontend akan di-compile di http://localhost:5173

# Terminal 3 (Opsional): Laravel Reverb untuk real-time
php artisan reverb:start

5. Akses Aplikasi

Buka browser dan navigasi ke http://localhost:8000

πŸ“§ Email Default: user@example.com
πŸ” Password: password

πŸ“ Struktur Proyek

whatsapp-clone/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ Http/
β”‚   β”‚   β”œβ”€β”€ Controllers/
β”‚   β”‚   β”‚   β”œβ”€β”€ ChatController.php       # Controller untuk chat & messaging
β”‚   β”‚   β”‚   β”œβ”€β”€ ContactController.php    # Controller untuk manajemen kontak
β”‚   β”‚   β”‚   β”œβ”€β”€ NearbyUserController.php # Controller untuk geolocation
β”‚   β”‚   β”‚   └── MetaAIController.php     # Controller untuk AI assistant
β”‚   β”‚   β”œβ”€β”€ Middleware/                  # Custom middleware
β”‚   β”‚   └── Resources/                   # API resources untuk data transformation
β”‚   β”œβ”€β”€ Models/
β”‚   β”‚   β”œβ”€β”€ User.php                     # Model User dengan relationships
β”‚   β”‚   β”œβ”€β”€ Conversation.php             # Model untuk chat conversations
β”‚   β”‚   β”œβ”€β”€ Message.php                  # Model untuk individual messages
β”‚   β”‚   └── MessageAttachment.php        # Model untuk file attachments
β”‚   β”œβ”€β”€ Events/                          # Broadcasting events untuk real-time
β”‚   β”œβ”€β”€ Jobs/                            # Queue jobs untuk background tasks
β”‚   └── Services/                        # Business logic services
β”‚
β”œβ”€β”€ resources/
β”‚   β”œβ”€β”€ js/
β”‚   β”‚   β”œβ”€β”€ Pages/
β”‚   β”‚   β”‚   β”œβ”€β”€ Chat/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ Index.tsx           # Chat list page (main layout)
β”‚   β”‚   β”‚   β”‚   └── Show.tsx            # Active conversation page
β”‚   β”‚   β”‚   β”œβ”€β”€ Contacts/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ Add.tsx             # Add contact modal page
β”‚   β”‚   β”‚   β”‚   └── AddContact.tsx      # Advanced contact search & nearby
β”‚   β”‚   β”‚   └── Auth/                    # Authentication pages
β”‚   β”‚   β”œβ”€β”€ Components/
β”‚   β”‚   β”‚   β”œβ”€β”€ Chat/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ ChatWindow.tsx      # Main chat message area
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ ConversationSidebar.tsx # List conversations
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ AddContactModal.tsx # Add contact with geolocation
β”‚   β”‚   β”‚   β”‚   └── WelcomeScreen.tsx   # Welcome screen
β”‚   β”‚   β”‚   └── Common/                  # Reusable components
β”‚   β”‚   β”œβ”€β”€ hooks/                       # Custom React hooks
β”‚   β”‚   β”œβ”€β”€ utils/                       # Utility functions
β”‚   β”‚   └── types/                       # TypeScript type definitions
β”‚   └── css/
β”‚       β”œβ”€β”€ app.css                      # Global styles
β”‚       └── tailwind.css                 # Tailwind configuration
β”‚
β”œβ”€β”€ routes/
β”‚   β”œβ”€β”€ web.php                          # Web routes (Inertia pages)
β”‚   β”œβ”€β”€ api.php                          # API routes (JSON endpoints)
β”‚   └── channels.php                     # Broadcasting channels
β”‚
β”œβ”€β”€ database/
β”‚   β”œβ”€β”€ migrations/                      # Database migrations
β”‚   β”œβ”€β”€ factories/                       # Model factories untuk testing
β”‚   └── seeders/                         # Database seeders
β”‚
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ Unit/                            # Unit tests
β”‚   └── Feature/                         # Feature/integration tests
β”‚
└── public/                              # Public files & uploads


πŸ—„οΈ Database Schema

User Table

users
β”œβ”€β”€ id (PK)
β”œβ”€β”€ name              # Nama pengguna
β”œβ”€β”€ email             # Email unik untuk login
β”œβ”€β”€ phone             # Nomor telepon opsional
β”œβ”€β”€ avatar            # URL foto profil
β”œβ”€β”€ bio               # Bio pengguna
β”œβ”€β”€ password          # Hash password
β”œβ”€β”€ last_seen         # Timestamp kapan terakhir online
β”œβ”€β”€ latitude          # Koordinat untuk nearby users feature
β”œβ”€β”€ longitude         # Koordinat untuk nearby users feature
β”œβ”€β”€ location_updated_at # Timestamp update lokasi
β”œβ”€β”€ theme             # Preferensi tema (dark/light/system)
β”œβ”€β”€ last_seen_privacy # Privacy setting untuk last seen
└── timestamps

Conversation Table

conversations
β”œβ”€β”€ id (PK)
β”œβ”€β”€ name              # Nama grup (NULL untuk 1-on-1)
β”œβ”€β”€ is_group          # Boolean apakah grup atau direct
β”œβ”€β”€ avatar            # Avatar grup
β”œβ”€β”€ description       # Deskripsi grup
β”œβ”€β”€ created_by        # User ID yang membuat grup
β”œβ”€β”€ admin_id          # Admin grup (untuk permissions)
└── timestamps

Message Table

messages
β”œβ”€β”€ id (PK)
β”œβ”€β”€ conversation_id (FK)
β”œβ”€β”€ user_id (FK)      # User yang mengirim
β”œβ”€β”€ body              # Isi pesan
β”œβ”€β”€ type              # text | image | file
β”œβ”€β”€ encrypted_body    # Pesan terenkripsi (optional)
β”œβ”€β”€ is_encrypted      # Boolean status enkripsi
β”œβ”€β”€ is_ephemeral      # Boolean untuk disappearing message
β”œβ”€β”€ file_path         # Path file jika ada attachment
β”œβ”€β”€ file_size         # Ukuran file
β”œβ”€β”€ mime_type         # MIME type file
β”œβ”€β”€ read_at           # Timestamp ketika dibaca
β”œβ”€β”€ edited_at         # Timestamp ketika diedit
β”œβ”€β”€ deleted_at        # Soft delete timestamp
└── timestamps

Conversation_User Pivot Table

conversation_user
β”œβ”€β”€ conversation_id (FK)
β”œβ”€β”€ user_id (FK)
β”œβ”€β”€ role              # admin | member
β”œβ”€β”€ is_muted          # Mute notifikasi grup
β”œβ”€β”€ is_pinned         # Pin conversation di sidebar
β”œβ”€β”€ joined_at         # Timestamp join
β”œβ”€β”€ last_read_message_id # Track unread messages
└── timestamps

MessageAttachment Table

message_attachments
β”œβ”€β”€ id (PK)
β”œβ”€β”€ message_id (FK)
β”œβ”€β”€ user_id (FK)      # User uploader
β”œβ”€β”€ file_name         # Nama original file
β”œβ”€β”€ path              # Path di storage
β”œβ”€β”€ mime_type         # MIME type
β”œβ”€β”€ type              # image | file | video
β”œβ”€β”€ size              # File size in bytes
└── timestamps

πŸ”Œ API Endpoints

Authentication

POST   /api/login              # Login dengan email & password
POST   /api/register           # Register akun baru
POST   /api/logout             # Logout
POST   /api/refresh-token      # Refresh access token

Chat & Messages

GET    /api/conversations      # List semua conversations
GET    /api/conversations/{id} # Detail conversation & messages
POST   /api/conversations/{id}/messages          # Kirim pesan
PUT    /api/messages/{id}      # Edit pesan
DELETE /api/messages/{id}      # Hapus pesan
GET    /api/messages/starred   # Get starred messages
POST   /api/messages/{id}/star # Toggle star message
GET    /api/search             # Global search conversations & messages

Contacts & User Search

GET    /api/users              # List semua pengguna (non-blocked)
GET    /api/users/search       # Search users (fuzzy matching)
POST   /api/users/find-by-email       # Cari user by exact email
POST   /api/users/nearby       # Nearby users via geolocation
PUT    /api/user/location      # Update user location coordinates

Groups

POST   /api/groups             # Buat grup baru
POST   /api/conversations/{id}/members # Add member ke grup
DELETE /api/conversations/{id}/members/{userId} # Remove member
PUT    /api/conversations/{id} # Update group info

User Management

GET    /api/user               # Get current user profile
PUT    /api/user/settings      # Update user settings
POST   /api/users/{id}/block   # Block user
POST   /api/users/{id}/unblock # Unblock user
GET    /api/users/blocked      # List blocked users

Presence & Status

GET    /api/users/{id}/is-blocked     # Check if user blocked
GET    /api/user/theme                # Get user theme preference
PUT    /api/user/theme                # Update theme preference

⚑ Optimasi Performa

Database Optimization

1. Eager Loading Strategy

// Prevent N+1 queries dengan eager loading
$conversations = $user->conversations()
    ->with([
        'lastMessage.user:id,name,avatar',
        'users:id,name,avatar,phone,bio',
    ])
    ->withCount(['messages as unreadMessages' => function ($query) use ($user) {
        $query->where('user_id', '!=', $user->id)->whereNull('read_at');
    }])
    ->get();

2. Composite Indexes

-- Message pagination
CREATE INDEX idx_message_conversation_created 
ON messages(conversation_id, created_at);

-- Search optimization
CREATE INDEX idx_user_email_lower 
ON users USING gin(lower(email));

3. Selective Column Loading

// Hanya select field yang dibutuhkan
User::select('id', 'name', 'avatar', 'email')->get();

Caching Strategy

1. Redis Cache untuk Online Status

// Cache user online status selama 5 menit
cache()->put("user.{$userId}.online", true, now()->addMinutes(5));

2. Query Result Caching

// Cache conversation list selama 1 jam
$conversations = cache()->remember("conversations.{$userId}", 
    now()->addHour(), 
    fn() => $user->conversations()->with(['users', 'lastMessage'])->get()
);

Frontend Optimization

1. Code Splitting

  • Lazy loading pages dengan React.lazy()
  • Dynamic imports untuk heavy components

2. Memoization

const memoizedConversations = useMemo(() => 
    conversations.filter(c => c.name.includes(search)),
    [conversations, search]
);

3. Pagination

  • Messages: 50 per page
  • Search results: 20 per page
  • User list: 20 per page

πŸ§ͺ Testing

Run Tests

# PHP Unit Tests (Pest)
php artisan test

# TypeScript/React Tests (Vitest)
npm run test

# Coverage Report
npm run test:coverage

# Watch Mode
npm run test:watch

Test Structure

tests/
β”œβ”€β”€ Unit/
β”‚   β”œβ”€β”€ Models/
β”‚   └── Services/
└── Feature/
    β”œβ”€β”€ Auth/
    β”œβ”€β”€ Chat/
    └── Contacts/

πŸ“š Dokumentasi

API Documentation

Dokumentasi API lengkap tersedia di:

Guides


πŸš€ Fitur Coming Soon

  • Video Call Integration (via Jitsi)
  • Voice Messages
  • Message Reactions Customization
  • Chat Backup & Export
  • Message Forwarding
  • Channel Broadcast
  • Mobile App (React Native)
  • Dark Mode Refinements

🀝 Kontribusi

Kami menerima kontribusi dari siapa saja! Silakan ikuti langkah berikut:

  1. Fork repository ini
  2. Create feature branch (git checkout -b feature/AmazingFeature)
  3. Commit changes (git commit -m 'Add some AmazingFeature')
  4. Push ke branch (git push origin feature/AmazingFeature)
  5. Buka Pull Request

Development Guidelines

  • Ikuti PSR-12 untuk PHP code style
  • Gunakan TypeScript untuk semua React components
  • Tulis unit tests untuk features baru
  • Update documentation jika diperlukan

πŸ› Bug Reports

Temukan bug? Buka GitHub Issue dengan:

  • Deskripsi jelas tentang bug
  • Steps untuk reproduce
  • Expected vs actual behavior
  • Screenshots/videos jika applicable

πŸ“„ Lisensi

Proyek ini dilisensikan di bawah MIT License - lihat file LICENSE untuk detail.


πŸ‘¨β€πŸ’Ό Author & Credits

Dibuat dengan ❀️ oleh Dery Supriyadi (Dryex)

Tech Stack Credits


⭐ Jika proyek ini membantu, jangan lupa kasih star!

⬆ Back to Top

About

πŸš€ A modern, high-performance WhatsApp Clone built with the VILT Stack (Vite, Inertia.js, Laravel, Tailwind CSS). Featuring real-time messaging via Laravel Reverb, a sleek "Vercel-style" UI, integrated Meta AI assistant, and location-based Nearby Users discovery.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages