# laravel/horizon architecture

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

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

## Overview

##### Main Components

a. Frontend Layer:
- Vue.js based dashboard (resources/js/screens/*)
- Real-time metrics visualization (resources/js/components/LineChart.vue)
- Job monitoring interfaces
- Batch processing views
- Dark/Light theme support (resources/sass/styles-*.scss)

b. Backend Layer:
- Laravel application core
- Redis integration layer
- Queue management system
- Supervisor management
- Metrics collection system
- Job processing pipeline

c. Core Services:
- Master Supervisor (src/MasterSupervisor.php)
- Worker Processes (src/WorkerProcess.php)
- Auto Scaler (src/AutoScaler.php)
- Process Pool (src/ProcessPool.php)
- Metrics Repository
- Job Repository

##### Relationship Flow

**[Frontend Dashboard] ←→ [HTTP Controllers]**
- ↑                      ↑

**[WebSocket/Events] ←→ [Event System]**
- ↑                      ↑

**[Redis Storage] ←→ [Core Services]**
- ↑                      ↑

**[Queue Workers] ←→ [Supervisors]**

##### Important Elements to Highlight

a. Supervision Hierarchy:
**MasterSupervisor**
- ↓
**Supervisors**
- ↓
**Worker Processes**
- ↓
**Queue Jobs**

b. Monitoring Flow:
**Jobs → Metrics Collection → Redis Storage → Real-time Dashboard**

##### Key Interactions

- Job lifecycle (pushed → reserved → completed/failed)
- Metrics collection points
- Supervisor scaling operations
- Real-time monitoring data flow
- Authentication and authorization flow

##### Technical Details

- Redis connections for different purposes (queues, metrics, job storage)
- Event broadcasting system
- API endpoints for dashboard data
- Worker process management
- Auto-scaling decision flow

##### Implementation Notes

- Annotations for critical configuration points
- Scaling boundaries

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Frontend
        Dashboard["Frontend Dashboard"]
        MetricsViz["Metrics Visualization"]
        JobMonitor["Job Monitoring Interface"]
        FailedJobs["Failed Jobs Interface"]
        RecentJobs["Recent Jobs Interface"]
        MetricsDash["Metrics Dashboard"]
        ThemeSupport["Theme Support"]
    end

    subgraph Backend
        HTTPCtrl["HTTP Controllers"]
        EventSys["Event System"]
        RedisInt["Redis Integration"]
        QueueMgmt["Queue Management"]
    end

    subgraph CoreServices
        MasterSup["Master Supervisor"]
        WorkerProc["Worker Process"]
        AutoScale["Auto Scaler"]
        ProcPool["Process Pool"]
        SupervisorMgmt["Supervisor Management"]
    end

    subgraph Repositories
        JobRepo["Job Repository"]
        MetricsRepo["Metrics Repository"]
    end

    %% Frontend Connections
    Dashboard --> HTTPCtrl
    Dashboard --> MetricsViz
    Dashboard --> JobMonitor
    Dashboard --> FailedJobs
    Dashboard --> RecentJobs
    Dashboard --> MetricsDash

    %% Backend Connections
    HTTPCtrl --> EventSys
    EventSys --> RedisInt
    RedisInt --> QueueMgmt

    %% Core Services Connections
    MasterSup --> WorkerProc
    MasterSup --> AutoScale
    MasterSup --> ProcPool
    MasterSup --> SupervisorMgmt

    %% Repository Connections
    QueueMgmt --> JobRepo
    QueueMgmt --> MetricsRepo
    EventSys --> MetricsRepo

    %% Cross-layer Connections
    HTTPCtrl --> JobRepo
    HTTPCtrl --> MetricsRepo
    EventSys --> Dashboard

    %% Styling
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef core fill:#e67e22,stroke:#d35400,color:white
    classDef repo fill:#9b59b6,stroke:#8e44ad,color:white

    class Dashboard,MetricsViz,JobMonitor,FailedJobs,RecentJobs,MetricsDash,ThemeSupport frontend
    class HTTPCtrl,EventSys,RedisInt,QueueMgmt backend
    class MasterSup,WorkerProc,AutoScale,ProcPool,SupervisorMgmt core
    class JobRepo,MetricsRepo repo

    %% Click Events
    click Dashboard "https://github.com/laravel/horizon/tree/5.x/resources/js/screens/"
    click MetricsViz "https://github.com/laravel/horizon/blob/5.x/resources/js/components/LineChart.vue"
    click JobMonitor "https://github.com/laravel/horizon/tree/5.x/resources/js/screens/monitoring/"
    click FailedJobs "https://github.com/laravel/horizon/tree/5.x/resources/js/screens/failedJobs/"
    click RecentJobs "https://github.com/laravel/horizon/tree/5.x/resources/js/screens/recentJobs/"
    click MetricsDash "https://github.com/laravel/horizon/tree/5.x/resources/js/screens/metrics/"
    click ThemeSupport "https://github.com/laravel/horizon/blob/5.x/resources/sass/styles-dark.scss"
    click MasterSup "https://github.com/laravel/horizon/blob/5.x/src/MasterSupervisor.php"
    click WorkerProc "https://github.com/laravel/horizon/blob/5.x/src/WorkerProcess.php"
    click AutoScale "https://github.com/laravel/horizon/blob/5.x/src/AutoScaler.php"
    click ProcPool "https://github.com/laravel/horizon/blob/5.x/src/ProcessPool.php"
    click RedisInt "https://github.com/laravel/horizon/blob/5.x/src/Connectors/RedisConnector.php"
    click JobRepo "https://github.com/laravel/horizon/blob/5.x/src/Repositories/RedisJobRepository.php"
    click MetricsRepo "https://github.com/laravel/horizon/blob/5.x/src/Repositories/RedisMetricsRepository.php"
    click QueueMgmt "https://github.com/laravel/horizon/blob/5.x/src/RedisQueue.php"
    click HTTPCtrl "https://github.com/laravel/horizon/tree/5.x/src/Http/Controllers/"
    click EventSys "https://github.com/laravel/horizon/tree/5.x/src/Events/"
    click SupervisorMgmt "https://github.com/laravel/horizon/tree/5.x/src/SupervisorCommands/"
```
