# pestphp/pest architecture

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

- Interactive diagram: https://gitdiagram.com/pestphp/pest
- Repository: https://github.com/pestphp/pest

## Overview

##### Main Components
- CLI Entry Points – Represented in the “bin” folder (e.g., bin/pest and worker.php). These are the command-line executables that launch the testing process.
- Plugin and Extension Architecture – Under src/Plugins and src/Contracts/Plugins you have the framework’s plugin system that allows customization (for example, Plugins for Coverage, Environment, Parallel, Retry, etc.). Also, the “overrides” directory shows how native behavior can be replaced.
- Test Case and Expectation Factories – Located in src/Factories and src/Expectations, these components create and manage test cases and assertions.
- Logging and Output System – With directories like src/Logging (including support for TeamCity and other logging mechanisms) and src/Console, this component deals with rendering results, handling progress printers, and formatting output.
- Architect Presets and Configuration – The src/ArchPresets and src/Configuration directories indicate pre-configured “presets” (like Laravel, Php, Security) that tailor the testing environment.
- Supporting Components – Various support modules (e.g., src/Support for helper methods, Arr, ChainableClosure) and contracts (src/Contracts) that enforce design and provide a base for extension.

##### Relationships and Interactions
- During bootstrapping, configuration files (in src/Configuration) and architectural presets (src/ArchPresets) are loaded, and plugin bootstrappers (e.g., BootOverrides, BootSubscribers) are triggered.
- As tests execute, the Logging system (src/Logging and submodules like TeamCity) receives events from multiple parts (from both the core and the Plugins) to output formatted results. Represent these interactions with directional flows from the test runner to the Logging and Console output components.
- The Plugin system is central: it both extends and hooks into many areas (handling arguments, configuration, output, etc.). Represent Plugins as a flexible, integrative layer linking into nearly every major module (Kernel, Factories, Logging, etc.).

##### Architectural Patterns and Key Principles
- The design follows a modular and extensible architecture incorporating Dependency Injection (via the Container in src/Support/Container), Plugin Hooks, and clearly defined Contracts/Interfaces.
- The system is layered: the front layer (CLI entry) communicates with a well-defined core (Kernel and Bootstrappers), which then coordinates test execution, logging, and plugin interactions.
- The use of presets (in src/ArchPresets) and configuration abstraction facilitates separation of concerns and a flexible testing setup.

##### Putting It All Together
- Next, detail the logging and output sequence—capture how test execution events are sent to Logging, which then informs the Console.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% CLI Entry Points
    subgraph "CLI Entry Points"
        CLI1["CLI: pest"]:::cli
        CLI2["CLI: worker"]:::cli
    end

    %% Core Kernel and Bootstrap System
    subgraph "Core Kernel"
        PEST["Pest (Core)"]:::kernel
        KERNEL["Kernel"]:::kernel
    end

    %% Bootstrappers
    subgraph "Bootstrappers"
        BOOT1["BootOverrides"]:::bootstrap
        BOOT2["BootSubscribers"]:::bootstrap
    end

    %% Configuration & Architect Presets
    subgraph "Configuration & Presets"
        CONFIG["Configuration"]:::bootstrap
        PRESETS["ArchPresets"]:::bootstrap
    end

    %% Test Execution
    subgraph "Test Execution"
        FACT["Factories"]:::execution
        EVAL["Evaluators"]:::execution
        EXP["Expectations"]:::execution
    end

    %% Logging and Output System
    subgraph "Logging & Output"
        LOG["Logging"]:::logging
        TEAMCITY["TeamCity Logging"]:::logging
        CONSOLE["Console"]:::logging
        CUST_LOG["Custom Logging"]:::logging
    end

    %% Plugin and Extension Architecture
    subgraph "Plugin System"
        PLUG["Plugins"]:::plugins
        CPLUG["Contracts/Plugins"]:::plugins
        CUST_RUN["Custom Runner"]:::plugins
    end

    %% Supporting Components
    subgraph "Supporting Components"
        SUPPORT["Support"]:::support
        CCONTRACT["Contracts"]:::support
        COLLISION["Collision"]:::support
    end

    %% Flows
    %% CLI triggers Core Kernel
    CLI1 -->|"triggers"| PEST
    CLI2 -->|"triggers"| KERNEL

    %% Kernel calls Bootstrappers
    PEST -->|"initializes"| KERNEL
    KERNEL -->|"invokes"| BOOT1
    KERNEL -->|"invokes"| BOOT2

    %% Bootstrappers load configuration and presets
    BOOT1 -->|"loads"| CONFIG
    BOOT2 -->|"loads"| PRESETS

    %% Bootstrappers lead to test execution flow
    BOOT1 -->|"starts"| FACT
    BOOT2 -->|"starts"| FACT

    FACT -->|"processes"| EVAL
    EVAL -->|"ensures"| EXP

    %% Test execution outputs results to Logging system
    EXP -->|"sends events"| LOG
    LOG -->|"reports"| TEAMCITY
    LOG -->|"outputs to"| CONSOLE

    %% Plugin system integration (dotted lines represent flexible integration)
    KERNEL ---|"hooks"| PLUG
    FACT ---|"extends"| PLUG
    LOG ---|"receives plugins"| PLUG
    PLUG ---|"implements"| CPLUG
    PLUG ---|"overrides"| CUST_RUN
    LOG ---|"overridden by"| CUST_LOG

    %% Supporting Components as foundational modules
    KERNEL ---|"uses"| SUPPORT
    FACT ---|"follows"| CCONTRACT
    BOOT2 ---|"notifies"| COLLISION

    %% Click Events
    click CLI1 "https://github.com/pestphp/pest/tree/3.x/bin/pest"
    click CLI2 "https://github.com/pestphp/pest/blob/3.x/bin/worker.php"
    click PEST "https://github.com/pestphp/pest/blob/3.x/src/Pest.php"
    click KERNEL "https://github.com/pestphp/pest/blob/3.x/src/Kernel.php"
    click BOOT1 "https://github.com/pestphp/pest/blob/3.x/src/Bootstrappers/BootOverrides.php"
    click BOOT2 "https://github.com/pestphp/pest/blob/3.x/src/Bootstrappers/BootSubscribers.php"
    click CONFIG "https://github.com/pestphp/pest/tree/3.x/src/Configuration"
    click PRESETS "https://github.com/pestphp/pest/tree/3.x/src/ArchPresets"
    click FACT "https://github.com/pestphp/pest/tree/3.x/src/Factories"
    click EXP "https://github.com/pestphp/pest/tree/3.x/src/Expectations"
    click LOG "https://github.com/pestphp/pest/tree/3.x/src/Logging"
    click TEAMCITY "https://github.com/pestphp/pest/tree/3.x/src/Logging/TeamCity"
    click CONSOLE "https://github.com/pestphp/pest/tree/3.x/src/Console"
    click PLUG "https://github.com/pestphp/pest/tree/3.x/src/Plugins"
    click CPLUG "https://github.com/pestphp/pest/tree/3.x/src/Contracts/Plugins"
    click CUST_LOG "https://github.com/pestphp/pest/tree/3.x/overrides/Logging"
    click CUST_RUN "https://github.com/pestphp/pest/tree/3.x/overrides/Runner"
    click SUPPORT "https://github.com/pestphp/pest/tree/3.x/src/Support"
    click CCONTRACT "https://github.com/pestphp/pest/tree/3.x/src/Contracts"
    click COLLISION "https://github.com/pestphp/pest/tree/3.x/src/Collision"

    %% Styles
    classDef cli fill:#cfe2f3,stroke:#0b5394,stroke-width:2px;
    classDef kernel fill:#d9ead3,stroke:#274e13,stroke-width:2px;
    classDef bootstrap fill:#fff2cc,stroke:#bf9000,stroke-width:2px;
    classDef execution fill:#f9cb9c,stroke:#e69138,stroke-width:2px;
    classDef logging fill:#f4cccc,stroke:#cc0000,stroke-width:2px;
    classDef plugins fill:#ead1dc,stroke:#8e7cc3,stroke-width:2px;
    classDef support fill:#d0e0e3,stroke:#115740,stroke-width:2px;
```
