# crishenrique/laravel-realtime architecture

> Architecture diagram of the GitHub repository crishenrique/laravel-realtime, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/crishenrique/laravel-realtime
- Repository: https://github.com/crishenrique/laravel-realtime

## Overview

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

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        Browser("Client Browser"):::frontend
        VueSPA("Vue.js SPA"):::frontend
        EchoClient("Laravel Echo\n(WebSocket Client)"):::frontend
        Store("Vuex Store"):::frontend
    end

    %% HTTP Layer
    subgraph "HTTP Layer"
        direction TB
        HTTPServer("Nginx/Apache"):::infra
        EntryPoint("public/index.php"):::backend
        Kernel("Laravel Kernel"):::backend
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        subgraph "Controllers"
            ChatCtrl("ChatController"):::backend
            AuthCtrls("Auth Controllers"):::backend
            HomeCtrl("HomeController"):::backend
            UserCtrl("UserController"):::backend
        end
        subgraph "Models"
            MsgModel("Message Model"):::backend
            UserModel("User Model"):::backend
        end
        subgraph "Events & Broadcasting"
            MsgCreated("MessageCreated Event"):::backend
            BroadcastProv("BroadcastServiceProvider"):::backend
            Channels("Channel Definitions"):::backend
            ConfigBroadcast("Broadcasting Config"):::backend
        end
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        DB("Relational Database"):::infra
        Migrations("Migrations"):::backend
        CacheQueue("Redis Cache/Queue"):::infra
    end

    %% Real-Time Service
    subgraph "Real-Time Service"
        Pusher("Pusher / WebSockets"):::infra
    end

    %% Asset Pipeline
    subgraph "Asset Build Pipeline"
        MixConfig("webpack.mix.js"):::infra
        Assets("Compiled Assets"):::infra
    end

    %% Interactions
    Browser -->|"loads SPA"| VueSPA
    VueSPA -->|"HTTP GET /chat"| HTTPServer
    VueSPA -->|"Axios POST /chat/message"| HTTPServer
    EchoClient -->|"WebSocket subscribe"| Pusher
    HTTPServer --> EntryPoint
    EntryPoint --> Kernel
    Kernel --> ChatCtrl
    Kernel --> AuthCtrls
    Kernel --> HomeCtrl
    Kernel --> UserCtrl
    ChatCtrl -->|"save()"| MsgModel
    MsgModel --> DB
    ChatCtrl -->|"fires"| MsgCreated
    MsgCreated --> BroadcastProv
    BroadcastProv --> Pusher
    Pusher --> EchoClient
    EchoClient -->|"receives event"| Store
    Store --> VueSPA
    DB --> Migrations
    CacheQueue --> Kernel

    %% Click Events
    click VueSPA "https://github.com/crishenrique/laravel-realtime/blob/master/resources/js/app.js"
    click EchoClient "https://github.com/crishenrique/laravel-realtime/blob/master/resources/js/Echo.js"
    click Store "https://github.com/crishenrique/laravel-realtime/blob/master/resources/js/store/store.js"
    click EntryPoint "https://github.com/crishenrique/laravel-realtime/blob/master/public/index.php"
    click Kernel "https://github.com/crishenrique/laravel-realtime/blob/master/app/Http/Kernel.php"
    click ChatCtrl "https://github.com/crishenrique/laravel-realtime/blob/master/app/Http/Controllers/Chat/ChatController.php"
    click AuthCtrls "https://github.com/crishenrique/laravel-realtime/blob/master/app/Http/Controllers/Auth/LoginController.php"
    click HomeCtrl "https://github.com/crishenrique/laravel-realtime/blob/master/app/Http/Controllers/HomeController.php"
    click UserCtrl "https://github.com/crishenrique/laravel-realtime/blob/master/app/Http/Controllers/User/UserController.php"
    click MsgModel "https://github.com/crishenrique/laravel-realtime/blob/master/app/Models/Chat/Message.php"
    click UserModel "https://github.com/crishenrique/laravel-realtime/blob/master/app/Models/User.php"
    click MsgCreated "https://github.com/crishenrique/laravel-realtime/blob/master/app/Events/Chat/MessageCreated.php"
    click BroadcastProv "https://github.com/crishenrique/laravel-realtime/blob/master/app/Models/Providers/BroadcastServiceProvider.php"
    click Channels "https://github.com/crishenrique/laravel-realtime/blob/master/routes/channels.php"
    click ConfigBroadcast "https://github.com/crishenrique/laravel-realtime/blob/master/config/broadcasting.php"
    click Migrations "https://github.com/crishenrique/laravel-realtime/blob/master/database/migrations/2020_09_03_132921_create_messages_table.php"
    click CacheQueue "https://github.com/crishenrique/laravel-realtime/blob/master/config/cache.php"
    click MixConfig "https://github.com/crishenrique/laravel-realtime/blob/master/webpack.mix.js"
    click Assets "https://github.com/crishenrique/laravel-realtime/blob/master/public/js/app.js"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0066CC;
    classDef backend fill:#E2F7E1,stroke:#28A745;
    classDef infra fill:#FFE4C4,stroke:#FF8C00;
```
