# spatie/laravel-health architecture

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

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

## Overview

##### Main Components

a. Core Package Components:
- Health Check Manager (central orchestrator)
- Check Registry
- Result Store System
- Notification System

b. Health Checks Layer:
- System Checks (Disk Space, CPU, etc.)
- Database Checks
- Cache Checks
- Queue Checks
- External Service Checks

c. Storage Options:
- Cache Store
- Database Store
- JSON File Store
- In-Memory Store

d. Notification Channels:
- Mail
- Slack
- Oh Dear Integration

**┌─────────────────────────────────────────────────────────────┐**
- Application Layer                        │
- ┘
- ↓
**┌─────────────────────────────────────────────────────────────┐**
- Health Check Manager                      │
- ┌─────────────┐   ┌──────────────┐   ┌─────────────────┐  │
- Check Registry│   │Result Manager│   │Notification Hub │  │
- ┘   └──────────────┘   └─────────────────┘  │
- ┘
- ↓
**┌─────────────────────────────────────────────────────────────┐**
- Health Checks Layer                      │
- ┌─────────┐ ┌────────┐ ┌────────┐ ┌────────────────────┐  │
- System   │ │Database│ │Cache   │ │External Services    │  │
- Checks   │ │Checks  │ │Checks  │ │Checks              │  │
- ┘ └────────┘ └────────┘ └────────────────────┘  │
- ┘
- ↓
**┌─────────────────────────────────────────────────────────────┐**
- Storage Layer                           │
- ┌─────────┐ ┌────────┐ ┌────────┐ ┌────────────────────┐  │
- Cache    │ │Database│ │JSON    │ │In-Memory           │  │
- Store    │ │Store   │ │Store   │ │Store               │  │
- ┘ └────────┘ └────────┘ └────────────────────┘  │
- ┘
- ↓
**┌─────────────────────────────────────────────────────────────┐**
- Notification Layer                         │
- ┌─────────┐ ┌────────┐ ┌────────────────────┐            │
- Mail     │ │Slack   │ │Oh Dear             │            │
- Integration         │            │
- ┘ └────────┘ └────────────────────┘            │
- ┘

##### Important Elements to Highlight

a. Integration Points:
- Laravel Application Integration
- External Service Connections
- Notification Service Integration

b. Data Flow:
- Check Execution Flow
- Result Storage Flow
- Notification Dispatch Flow

##### Implementation Details

- The facade pattern used (Health facade)
- The observer pattern for events
- The strategy pattern for different storage options
- The factory pattern for check creation

##### Specific Notes

- How the package integrates with Laravel's service provider
- Command line interface options
- Demonstrate the web interface endpoints
- Multi-language support system

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Application
        App[Laravel Application]
    end

    subgraph Core
        HCM["Health Check Manager"]:::core
        CR["Check Registry"]:::core
        RM["Result Manager"]:::core
        NH["Notification Hub"]:::core

        HCM --> CR
        HCM --> RM
        HCM --> NH
    end

    subgraph "Health Checks"
        SC["System Checks"]:::check
        DC["Database Checks"]:::check
        CC["Cache Checks"]:::check
        QC["Queue Checks"]:::check
        EC["External Service Checks"]:::check
    end

    subgraph Storage
        CS["Cache Store"]:::store
        DS["Database Store"]:::store
        JS["JSON File Store"]:::store
        MS["In-Memory Store"]:::store
    end

    subgraph "Notification Channels"
        Mail["Mail Channel"]:::notification
        Slack["Slack Channel"]:::notification
        OhDear["Oh Dear Integration"]:::notification
    end

    subgraph Interface
        WI["Web Interface"]:::interface
        CLI["CLI Interface"]:::interface
    end

    App --> HCM
    CR --> SC
    CR --> DC
    CR --> CC
    CR --> QC
    CR --> EC

    RM --> CS
    RM --> DS
    RM --> JS
    RM --> MS

    NH --> Mail
    NH --> Slack
    NH --> OhDear

    HCM --> WI
    HCM --> CLI

    %% Click events
    click HCM "https://github.com/spatie/laravel-health/blob/main/src/Health.php"
    click CR "https://github.com/spatie/laravel-health/blob/main/src/Support/Checks.php"
    click RM "https://github.com/spatie/laravel-health/blob/main/src/ResultStores/ResultStore.php"
    click NH "https://github.com/spatie/laravel-health/blob/main/src/Notifications/CheckFailedNotification.php"
    
    click SC "https://github.com/spatie/laravel-health/blob/main/src/Checks/Checks/UsedDiskSpaceCheck.php"
    click DC "https://github.com/spatie/laravel-health/blob/main/src/Checks/Checks/DatabaseCheck.php"
    click CC "https://github.com/spatie/laravel-health/blob/main/src/Checks/Checks/CacheCheck.php"
    click QC "https://github.com/spatie/laravel-health/blob/main/src/Checks/Checks/QueueCheck.php"
    click EC "https://github.com/spatie/laravel-health/blob/main/src/Checks/Checks/PingCheck.php"
    
    click CS "https://github.com/spatie/laravel-health/blob/main/src/ResultStores/CacheHealthResultStore.php"
    click DS "https://github.com/spatie/laravel-health/blob/main/src/ResultStores/EloquentHealthResultStore.php"
    click JS "https://github.com/spatie/laravel-health/blob/main/src/ResultStores/JsonFileHealthResultStore.php"
    click MS "https://github.com/spatie/laravel-health/blob/main/src/ResultStores/InMemoryHealthResultStore.php"
    
    click Mail "https://github.com/spatie/laravel-health/blob/main/resources/views/mail/checkFailedNotification.blade.php"
    click Slack "https://github.com/spatie/laravel-health/blob/main/docs/configuring-notifications/via-slack.md"
    click OhDear "https://github.com/spatie/laravel-health/blob/main/docs/configuring-notifications/via-oh-dear.md"
    
    click WI "https://github.com/spatie/laravel-health/blob/main/src/Http/Controllers/HealthCheckResultsController.php"
    click CLI "https://github.com/spatie/laravel-health/blob/main/src/Commands/RunHealthChecksCommand.php"

    %% Styling
    classDef core fill:#2374ab
    classDef check fill:#57a773
    classDef store fill:#484d6d
    classDef notification fill:#f7b32b
    classDef interface fill:#9c92a3

    %% Legend
    subgraph Legend
        Core["Core Components"]:::core
        Checks["Health Checks"]:::check
        Storage["Storage Options"]:::store
        Notifications["Notification Channels"]:::notification
        Interfaces["Interfaces"]:::interface
    end
```
