How crishenrique/laravel-realtime works
Project type and purpose
• This is a full-stack real-time chat application built with Laravel (PHP) as the backend and Vue.js as the frontend.
• Key features: user authentication, message persistence, event broadcasting for real-time updates.
File structure to find core components
• “app/” contains Laravel’s HTTP controllers, event classes (MessageCreated), models (Message, User), and service providers.
• “routes/” holds web.php (serves Blade views and API endpoints), api.php (if used for JSON APIs), and channels.php (WebSocket channel definitions).
• “resources/js/” contains the Vue.js SPA, components (Chat.vue, Message.vue, Users.vue), Vuex store (chat.js), and Echo.js (WebSocket client).
• “public/” is the web root—serving index.php, built JS/CSS assets, and mixing manifest.
• “config/broadcasting.php” and “.env.example” point to external real-time services (e.g., Pusher or a self-hosted WebSocket).
• Database migrations under “database/migrations/” create users, messages, and other tables.
README
• Confirms real-time chat using Laravel + Vue.js.
• Implies use of Laravel’s broadcast system and Vue frontend listening with Echo.
Main system components
a. Client (Browser):
• Vue.js SPA
• Axios (HTTP) & Laravel Echo (WebSocket)
b. Web Server / HTTP Layer:
• Nginx/Apache → public/index.php → Laravel Kernel → Controllers
c. Application Layer (Laravel):
• Controllers (ChatController, Auth Controllers)
• Models (User, Message)
• Events (MessageCreated) & Listeners
• Broadcasting subsystem (config/broadcasting)
• Queue worker (if using asynchronous broadcast)
d. Data Layer:
• Relational Database (MySQL/PostgreSQL)
• Cache/Queue store (Redis or database driver)
e. Real-Time Messaging:
• Broadcasting service (Pusher or laravel-websockets)
f. Asset Build Pipeline:
• Webpack (mix) compiles Vue components to public/js/app.js
Relationships and interactions
1) User opens chat UI → HTTP GET /chat → Laravel returns Blade or SPA shell
2) Vue app initializes → establishes WebSocket connection via Echo to broadcasting server
3) User sends a message → Vue dispatches Vuex action → Axios POST /chat/message → ChatController@store
4) Controller saves Message to DB → fires MessageCreated event → pushed to broadcast channel (sync or via queue)
5) Broadcasting server (Pusher/websockets) pushes event → Laravel Echo client receives → Vuex commits new message → UI updates
6) Persistent storage: DB for messages, Redis (optional) for queue/cache
Architectural patterns
• MVC on the server: Models ↔ Controllers ↔ Views (Blade + JSON APIs)
• Component-based SPA on the client with Vue + Vuex
• Event-driven architecture for real-time updates
• Optional queue workers for asynchronous broadcasting