A comprehensive, responsive, secure, and efficient real-time chat application built with Laravel 11, featuring Google OAuth authentication, Pusher WebSocket integration, and a modern Blade UI with Tailwind CSS, and message editing/deletion, and a modern code architecture.
- Secure Authentication with Google OAuth 2.0 + Laravel Breeze +Laravel Sanctum
- Real-time Chat using Pusher WebSockets
- Message Management with edit and delete capabilities
- Pagination (10 messages per page)
- Filtering (filter messages by users)
- Clean architecture with Design patterns (Service Layer, Broadcast, Dependency Injection)
- Comprehensive Security with Middleware and Policies
- Extensive Testing with 80%+ coverage
- Modern Design with Tailwind CSS
- Interactive Chat Interface with real-time updates
- Responsive Design for all devices
- Integrated User Profile with statistics
- Operating System: Windows 10+, macOS Monterey+, or any Linux distro
- Web Browser: Chrome / Firefox / Edge (latest versions)
- πRuntime & Tools:
- PHP 8.1+ or higher
- Composer
- Node.js & NPM (for Vite)
- PostgreSQL 14+ or higher
- Pusher account for WebSocket (real-time chat)
- Google Developer Account (for OAuth)
- CSRF Protection: Protection against Cross-Site Request Forgery attacks
- OAuth Validation: Validation of Google OAuth data
- Rate Limiting: Request rate limiting to prevent abuse
- Input Validation: Validation of all inputs
- Authorization Policies: Authorization policies to control access
- Soft Deletes: Safe deletion of messages with recovery capability
git clone <repository-url>
cd chat-apicomposer install
npm installcp .env.example .env
php artisan key:generate# Create database
sudo -u postgres createdb laravel_db
sudo -u postgres createuser postgres
# Update .env file
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=laravel_db
DB_USERNAME=postgres
DB_PASSWORD=123456- Go to Google Cloud Console
- Create a new project or select existing one
- Enable Google+ API
- Create OAuth 2.0 credentials
- Add credentials to
.env:
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
GOOGLE_REDIRECT_URL=/auth/google/callback- Go to Pusher Dashboard
- Create a new app
- Add credentials to
.env:
BROADCAST_DRIVER=pusher
PUSHER_APP_ID=your_app_id
PUSHER_APP_KEY=your_app_key
PUSHER_APP_SECRET=your_app_secret
PUSHER_APP_CLUSTER=your_app_cluster
### 7. Run Migrations and Seeders
```bash
php artisan migrate --seed# for development
npm run dev# for production
npm run buildphp artisan serve --host=0.0.0.0 --port=8000npm run dev- Frontend: http://localhost:8000
- API: http://localhost:8000/api
- Pusher: Works via cloud service or local server
- Go to http://localhost:8000
- Click "Get Started" "Login" or "Sign up"
- Go to http://localhost:8000/login
- Click "Login with Google"
- Complete the authentication process
- You'll be automatically redirected to the chat page
- Type your message and press Enter to send
- Watch messages appear in real-time
- Click on your email in the top bar
- Select "Profile"
- Manage your profile details
π chat-api/
βββ π app/
β βββ π Events/
β β βββ MessageSent.php # Message sent event
β β βββ MessageUpdated.php # Message updated event
β β βββ MessageDeleted.php # Message deleted event
β βββ π Http/
β β βββ π Controllers/
β β β βββ π Api
β β β β βββ MessageController.php # Message controller
β β β βββ π Auth # Breeze auth controllers
β β β | βββ AuthenticatedSessionController.php
β β β | βββ ConfirmablePasswordController.php
β β β | βββ EmailVerificationNotificationController.php
β β β | βββ EmailVerificationPromptController.php
β β β | βββ NewPasswordController.php
β β β | βββ PasswordController.php
β β β | βββ PasswordResetLinkController.php
β β β | βββ RegisteredUserController.php
β β β | βββ VerifyEmailController.php
β β β βββ Controller.php # Base controller
β β β βββ OAuthController.php # Google OAuthentication controller
β β β βββ ProfileController.php # Profile controller
β β βββ π Requests/ # Breeze form requests
β β βββ π Auth/LoginRequest.php
β β βββ UpdateMessageRequest.php #Message update validation
β β βββ StoreMessageRequest.php #Message creation validation
β β βββ ProfileUpdateRequest.php
| |
β βββ π Models/
β β βββ Message.php # Message model
β β βββ User.php # User model
β βββ π Policies/
β | βββ MessagePolicy.php # Message policies
β βββ π Providers/
β | βββ AppServiceProvider.php
β βββ π Services/
β | βββ MessageService.php # Message service
β βββ π Views/Components/
β βββ AppLayout.php
β βββ GuestLayout.php
βββ π bootstrap/
βββ π config/
βββ π database/
β βββ π factories/
β β βββ UserFactory.php # Uer factory for tests
β β βββ MessageFactory.php # Message factory for tests
β βββ π migrations/ # DB migrations (messages, users)
β βββ π seeders/ # Data seed
βββ π public/ # Web server entry point and static assetsβ
βββ π resources/
β βββ π views/
β β βββ π auth/ # Breeze login/register pages
β β βββ π components/ # Breeze blade components
β β βββ π layouts/ # Laravel Application Layouts
β β βββ π profile/ # Breeze profile pages
β β βββ chat.blade.php # Real-time chat UI
β β βββ home.blade.php # Landing/home page
β βββ π css/, js/ # Frontend assets (Tailwind, Chat setup js)
β
βββ π routes/
β βββ api.php # API routes (messages, etc.)
β βββ auth.php # Breeze authentication routes (loing, register, etc.)
β βββ web.php # Web routes (landing, chat page)
β βββ channels.php # Broadcast channel definitions
β
βββ π storage/ # Logs, cache, sessions β uploads via `php artisan storage:link`
βββ π tests/
β βββ π Feature/ # Feature tests
β βββ π Unit/ # Unit tests
β β βββ MessageApiTest.php # Message API tests
β β βββ MessageTest.php # Message unit tests
β β βββ OauthTest.php # Authentication tests
βββ π README.md # Comprehensive project guide
βββ π QUICK_START_GUIDE.md # Quick Start Guide
βββ π PROJECT_SUMMARY.md # Project summary
GET /auth/google # Start OAuth
GET /auth/google/callback # Handle Google response
POST /api/auth/logout # Logout
GET /api/auth/user # Get user info| Method | Path | Description |
|---|---|---|
| GET | /auth/google/redirect |
Redirect to Google OAuth |
| GET | /auth/google/callback |
Handle Google OAuth response |
| POST | /api/logout |
Logout API User |
| GET | /api/user |
Get authenticated user data |
| Method | Path | Description |
|---|---|---|
| GET | /api/messages |
Get list of messages (with pagination) |
| GET | /api/messages?filter_user=1 |
Get list of messages filtered by user (with pagination) |
| POST | /api/messages |
Send a new message |
| GET | /api/messages/{id} |
Get a specific message |
| PUT | /api/messages/{id} |
Update a message (owner only) |
| DELETE | /api/messages/{id} |
Delete a message (owner only) |
curl -H "Authorization: Bearer YOUR_TOKEN" \
-H "Accept: application/json" \
http://localhost:8000/api/messages?page=1curl -X POST \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"content":"Hello World!"}' \
http://localhost:8000/api/messagesThe project has been updated to use Pusher with Vanilla JavaScript instead of jQuery for better performance and smaller bundle size.
- Direct connection to Pusher cloud servers
- Improved performance with vanilla JavaScript
- Smaller bundle size without jQuery
- Enhanced error handling
# Pusher Configuration
BROADCAST_DRIVER=pusher
PUSHER_APP_ID=2b4e8601a292cbff3019
PUSHER_APP_KEY=2b4e8601a292cbff3019
PUSHER_APP_SECRET=your_app_secret
PUSHER_APP_CLUSTER=ap2
# Vite Environment Variables
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"new.message- New message receivedupdaed.message- Message updateddeleted.message- Message deleted
For more details, see Pusher Documentation.
php artisan test# Run all tests
php artisan test
# Run specific tests
php artisan test --filter=MessageTestphp artisan test --coverageAPP_ENV=production
APP_DEBUG=false
APP_URL=https://your-domain.com
# Database
DB_CONNECTION=pgsql
DB_HOST=your-db-host
DB_DATABASE=your-db-name
DB_USERNAME=your-db-user
DB_PASSWORD=your-db-password
# Pusher (Production)
PUSHER_APP_ID=your_production_app_id
PUSHER_APP_KEY=your_production_app_key
PUSHER_APP_SECRET=your_production_app_secret
PUSHER_APP_CLUSTER=your_production_cluster
# Google OAuth (Production)
GOOGLE_CLIENT_ID=your_production_client_id
GOOGLE_CLIENT_SECRET=your_production_client_secret
GOOGLE_REDIRECT_URL=https://your-domain.com/auth/google/callback# Install dependencies
composer install --optimize-autoloader --no-dev
# Build assets
npm run build
# Optimize Laravel
php artisan config:cache
php artisan route:cache
php artisan view:cache
# Run migrations
php artisan migrate --force- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some 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.
- Laravel Framework
- Pusher Real-time Service
- Tailwind CSS
- Google OAuth
- PostgreSQL Database
- README.md: For basic instructions
- GitHub Issues: Create an issue in the repository
- Developer: Abdulrahman Fadhl
- Email: abdulrahmanfadhl@gmail.com
- Repository: GitHub Repository
The Laravel Chat API project has been successfully completed according to all specified requirements. The project is ready for use in a production environment and includes:
- β Complete Chat API
- β Real-time Message Broadcasting
- β Secure Authentication via Google OAuth
- β Comprehensive Protection against security threats
- β Comprehensive Tests to ensure quality
- β Complete Documentation for use and deployment
This project follows best practices in modern API development and provides a strong foundation for building advanced chat applications.
Note: This project is designed for educational and development purposes. Make sure to implement proper security measures before deploying to production.
Completion Date: July 13, 2025
Developer: Abdulrahman Fadhl
Status: Completed β
Version: 1.0.0
Ready for Deployment: Yes β






