# 365werk/etagconditionals architecture

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

- Interactive diagram: https://gitdiagram.com/365werk/etagconditionals
- Repository: https://github.com/365werk/etagconditionals

## Overview

##### Project type and purpose
- This is a Laravel package (PHP library) that provides HTTP middleware for setting ETags and handling conditional requests (`If-Match`, `If-None-Match`) in any Laravel-based API. It plugs into the Laravel HTTP pipeline.

##### File structure
- Top‐level files:
- composer.json, LICENSE, readme.md, changelog.md, phpunit.xml – standard package configuration.
- config/etagconditionals.php – package default config.
- src/… – package source code.
- src/EtagConditionalsServiceProvider.php – Laravel service provider, registers config merge and middleware.
- src/Facades/EtagConditionals.php – Laravel façade to expose static API.
- src/Middleware/SetEtag.php, IfMatch.php, IfNoneMatch.php, Middleware.php – actual middleware classes and base.
- tests/… – PHPUnit tests for each middleware and the façade.

##### README for additional insights
- Describes three middleware and how they behave.
- Shows how the service provider publishes config.
- Allows customization of ETag algorithm via a callback.

##### Detail is key
– Show all three middleware individually rather than lumping into one “ETag Middleware.”
– Call out the ServiceProvider registration step (on boot: mergeConfig, register middleware aliases).

## Diagram (Mermaid)

```mermaid
flowchart TD 
    %% External Client
    Client["HTTP Client"]:::external

    subgraph "Laravel Application"
        SP["ServiceProvider"]:::service
        Config["Config<br/>(etagconditionals.php)"]:::config
        Facade["Facade: EtagConditionals"]:::facade
        CoreClass["EtagConditionals Main"]:::service
        Kernel["HTTP Kernel"]:::core

        subgraph "Middleware Layer"
            BaseMW["Base Middleware"]:::middleware
            IF_NONE["IfNoneMatch Middleware"]:::middleware
            IF_MATCH["IfMatch Middleware"]:::middleware
            SET["SetEtag Middleware"]:::middleware
        end

        Controller["Application Controller"]:::controller
    end

    Cache["Optional Cache/Storage"]:::storage

    %% Request Flow
    Client -->|Request| Kernel
    Kernel -->|execute If-None-Match| IF_NONE
    IF_NONE -->|then| SET
    SET -->|then| Controller
    Controller -->|response| SET
    SET -->|response| Kernel
    Kernel -->|response| Client

    %% IfMatch sub-request
    IF_MATCH -.->|sub-request GET| Controller

    %% ServiceProvider interactions
    SP -->|registers middleware & config| Kernel
    SP -->|merges config| Config

    %% Facade and Core Class
    Facade -->|accesses| CoreClass
    SET -->|uses| Facade
    IF_NONE -->|uses| Facade
    IF_MATCH -->|uses| Facade

    %% Config usage
    CoreClass -->|reads| Config
    SET -->|reads| Config
    IF_NONE -->|reads| Config
    IF_MATCH -->|reads| Config

    %% Optional cache
    SET -->|optional storage| Cache
    IF_NONE -->|optional storage| Cache

    %% Tests
    subgraph "Tests"
        EtagTest["EtagConditionalsTest"]:::tests
        SetTest["SetEtagTest"]:::tests
        NoneTest["IfNoneMatchTest"]:::tests
        MatchTest["IfMatchTest"]:::tests
    end

    %% Click Events
    click Config "https://github.com/365werk/etagconditionals/blob/master/config/etagconditionals.php"
    click SP "https://github.com/365werk/etagconditionals/blob/master/src/EtagConditionalsServiceProvider.php"
    click Facade "https://github.com/365werk/etagconditionals/blob/master/src/Facades/EtagConditionals.php"
    click CoreClass "https://github.com/365werk/etagconditionals/blob/master/src/EtagConditionals.php"
    click BaseMW "https://github.com/365werk/etagconditionals/blob/master/src/Middleware/Middleware.php"
    click SET "https://github.com/365werk/etagconditionals/blob/master/src/Middleware/SetEtag.php"
    click IF_NONE "https://github.com/365werk/etagconditionals/blob/master/src/Middleware/IfNoneMatch.php"
    click IF_MATCH "https://github.com/365werk/etagconditionals/blob/master/src/Middleware/IfMatch.php"
    click EtagTest "https://github.com/365werk/etagconditionals/blob/master/tests/EtagConditionalsTest.php"
    click SetTest "https://github.com/365werk/etagconditionals/blob/master/tests/SetEtagTest.php"
    click NoneTest "https://github.com/365werk/etagconditionals/blob/master/tests/IfNoneMatchTest.php"
    click MatchTest "https://github.com/365werk/etagconditionals/blob/master/tests/IfMatchTest.php"

    %% Styles
    classDef external fill:#f9f,stroke:#333,stroke-width:1px
    classDef middleware fill:#ff9,stroke:#333,stroke-width:1px
    classDef service fill:#9ff,stroke:#333,stroke-width:1px
    classDef core fill:#9f9,stroke:#333,stroke-width:1px
    classDef controller fill:#99f,stroke:#333,stroke-width:1px
    classDef config fill:#fc9,stroke:#333,stroke-width:1px
    classDef facade fill:#9cf,stroke:#333,stroke-width:1px
    classDef storage fill:#ccf,stroke:#333,stroke-width:1px
    classDef tests fill:#f99,stroke:#333,stroke-width:1px
```
