How naiemofficial/laravel-realtime-chat works
1. Application shape
- This is a Laravel monolith for a realtime chat app. The backend is PHP/Laravel; the frontend is server-rendered Blade plus Livewire components, with Vite-built JavaScript and CSS.
2. Primary user-facing surfaces
- The main UI is the chat workspace (resources/views/chat/index.blade.php) and standard auth/profile pages.
- Layout composition is split between guest/auth layouts and reusable Blade components, so the diagram should show a shared presentation layer rather than separate SPA frontends.
3. Chat feature boundary
- The chat domain is concentrated in app/Livewire/Chat/*, app/Http/Controllers/ChatController.php, ConversationController.php, MessageController.php, ParticipantController.php, and the models Conversation, Message, Participant, and Call.
- This is the core subsystem for listing conversations, opening message threads, sending messages, and managing participants.
4. Realtime messaging flow
- Message actions originate in Livewire components such as SendMessage, Messages, Conversations, and related alert/not-available components.
- Those components interact with the Laravel domain models and then broadcast updates so other connected clients receive new messages without a page reload.
- The presence of app/Events/ConversationConnection.php, BroadcastServiceProvider, routes/channels.php, and resources/js/echo.js indicates a classic Laravel broadcasting pipeline.
5. WebSocket/broadcasting boundary
- Realtime delivery is abstracted behind Laravel broadcasting, with the app configured to work with Pusher or Reverb per the README and config/broadcasting.php, config/reverb.php.
- Private channel authorization is part of the architecture, so chat data is not pushed through public channels.
6. Call subsystem
- Audio/video calling is a separate but related feature, implemented through app/Livewire/Chat/Call.php, SendCall.php, and app/Models/Call.php.
- The frontend includes call-specific JavaScript (resources/js/custom/call.js, resources/js/Socket.js) and incoming/outgoing call audio assets in public/audio/.
- The README’s WebRTC mention suggests call setup/signaling is handled in-browser, with Laravel used to coordinate session state and realtime events.
7. Authentication and user management
- Auth is handled with standard Laravel auth controllers under app/Http/Controllers/Auth/*, plus request objects such as LoginRequest.
- User profile editing, password change, email verification, registration, and session management are separate bounded areas from chat.
- app/Http/Middleware/UserAuth.php and Sanctum config indicate additional auth protection for API/session access.
8. Persistence layer
- Data is stored in MySQL via Eloquent models and migrations.
- The schema centers on users, conversations, participants, messages, and calls, with additional Laravel tables for cache, jobs, and personal access tokens.
- database/seeders and factories support bootstrapping and test data.
9. Request handling and controller responsibilities
- Controllers are used for page-level and action-level endpoints, while Livewire handles the interactive parts of the chat UI.
- This creates a split where traditional controllers serve initial pages and account/profile workflows, and Livewire handles in-page chat state transitions.
10. Frontend composition and asset pipeline
- Styling uses Tailwind CSS plus custom CSS, and the build pipeline uses Vite.
- JavaScript is organized into app bootstrap files and feature scripts under resources/js/custom, with Echo/socket wiring for realtime behavior.
- Blade components are heavily used for buttons, form controls, modals, nav, alerts, and message templates.
11. Message rendering and UX states
- There is a dedicated message rendering subsystem under resources/views/message/* with templates for default and text-only variants and states like success, warning, pending, error, and unknown.
- This suggests the app presents structured message/status feedback separate from the core chat data flow.
12. External services and operational dependencies
- Realtime messaging depends on a WebSocket provider (Pusher or Reverb).
- Email verification and password reset imply mail service integration through Laravel’s mail stack.
- Session, cache, queue, and logging configs are standard Laravel support services, but broadcasting and WebRTC are the key architecture drivers here.
Main entry points: Chat Chat Livewire · web.php Web Routes · index.blade.php Chat Workspace · app.blade.php App Layout
Components 26
Presentation
Blade layouts, components, and page views that compose the UI
- Chat Workspace · Primary chat workspace page
resources/views/chat/index.blade.php - App Layout · Authenticated application shell
resources/views/layouts/app.blade.php - Guest Layout · Unauthenticated page shell
resources/views/layouts/guest.blade.php - UI Components · Reusable buttons, nav, modal, inputs, and shared UI fragments
resources/views/components - Message Views · Message rendering and status templates
resources/views/message
Chat Domain
Core conversation, messaging, participant, and call feature boundary
- Chat Controller · Entry controller for the chat workspace
app/Http/Controllers/ChatController.php - Conversation Ctrl · Conversation listing and thread-level actions
app/Http/Controllers/ConversationController.php - Message Ctrl · Message submission and message endpoints
app/Http/Controllers/MessageController.php - Participant Ctrl · Conversation membership and participant management
app/Http/Controllers/ParticipantController.php - Chat Livewire · Conversation list, message thread, alerts, and call orchestration
app/Livewire/Chat
Realtime
Broadcasting, Echo, and browser-side socket wiring
- Channel Rules · Private channel authorization for realtime chat
routes/channels.php - Conversation Event · Broadcastable conversation update event
app/Events/ConversationConnection.php - Broadcast Provider · Bootstraps Laravel broadcasting
app/Providers/BroadcastServiceProvider.php - Echo Client · Frontend Echo setup for listening to broadcasts
resources/js/echo.js - Socket JS · Socket integration and realtime client glue
resources/js/Socket.js - Call JS · Browser-side call handling and media/session behavior
resources/js/custom/call.js
Auth & Profile
Login, registration, password, verification, and profile management
- Auth Routes · Authentication route definitions
routes/auth.php - Auth Views · Login, register, password reset, and verification screens
resources/views/auth - Profile Views · Profile edit and account management screens
resources/views/profile - Auth Controllers · Login, registration, verification, and password workflows
app/Http/Controllers/Auth - Profile Ctrl · Profile edit and account update actions
app/Http/Controllers/ProfileController.php - User Auth MW · Custom user/session protection middleware
app/Http/Middleware/UserAuth.php
Persistence
Eloquent models, migrations, seeders, and factories
- Chat Models · Conversation, message, participant, and call records
app/Models - Schema Migrations · Users, conversations, participants, messages, calls, and support tables
database/migrations - Seeders & Factories · Bootstrap and sample data for local development
database/seeders
Other components
- Web Routes · Main HTTP routes that dispatch pages and chat actions
routes/web.php
Connections 27
- Web Routes → Chat Workspace: serves · Loads the main chat workspace
- Web Routes → Chat Controller: dispatches · Routes page-level chat requests
- Web Routes → Conversation Ctrl: dispatches · Conversation endpoints
- Web Routes → Message Ctrl: dispatches · Message endpoints
- Web Routes → Participant Ctrl: dispatches · Participant management endpoints
- Web Routes → Profile Ctrl: dispatches · Profile and account actions
- Auth Routes → Auth Controllers: maps to · Authentication workflow routes
- Channel Rules → Broadcast Provider: authorizes · Defines private channel access rules
- Chat Workspace → App Layout: uses · Rendered inside the authenticated shell
- Auth Views → Guest Layout: uses · Rendered inside the guest shell
- Profile Views → App Layout: uses · Rendered inside the authenticated shell
- App Layout → UI Components: composes · Shared app chrome and controls
- Guest Layout → UI Components: composes · Shared guest UI pieces
- Chat Workspace → Chat Livewire: mounts · Chat workspace is driven by Livewire components
- Chat Livewire → Chat Models: reads/writes · Loads threads, stores messages, and updates membership
- Chat Livewire → Conversation Event: broadcasts · Emits realtime conversation updates
- Conversation Event → Broadcast Provider: uses · Delivered through Laravel broadcasting
- Broadcast Provider → Echo Client: consumed by · Browser listens to private channels
- Echo Client → Socket JS: wires · Client socket/bootstrap integration
- Socket JS → Chat Livewire: syncs · Keeps chat UI updated in realtime
- Call JS → Chat Livewire: supports · Browser call UI used by Livewire call components
- Chat Livewire → Call JS: coordinates · Call components trigger browser-side call behavior
- Chat Livewire → Message Views: renders · Uses message/status templates for feedback states
- Auth Controllers → User Auth MW: protected by · Session and access protection
- Profile Ctrl → User Auth MW: protected by · Authenticated profile access
- Chat Models → Schema Migrations: persisted by · Underlying database schema
- Seeders & Factories → Chat Models: populate · Bootstraps sample users and chat data