# chimeraphp/foundation architecture

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

- Interactive diagram: https://gitdiagram.com/chimeraphp/foundation
- Repository: https://github.com/chimeraphp/foundation

## Overview

- Message Processing Components:
- “ExecuteCommand” and “ExecuteQuery”: These represent the entry points for commands and queries, respectively.
- “MessageCreator”: This component (with its submodules such as “InputExtractor” and its strategies like “AppendGeneratedIdentifier” and “UseInputData”) is responsible for constructing messages.
- “NamedConstructor” and “MessageCannotBeCreated”: These indicate patterns for robust object creation and error handling.
- Identifier Generation:
- “IdentifierGenerator”: Its submodule “RamseyUuid” indicates that the library plugs into an external UUID generator to create unique identifiers.
- Service Bus Functionality:
- “ServiceBus”: This component abstracts the dispatch and conversion of messages.
- “ReadModelConverter”: With its submodules (“Callback”, “Query”, etc.), it shows the mechanism for converting messages into read models or DTOs.
- Exception Handling:
- The “Exception.php” file clarifies that error-handling strategies are unified in the foundation.

##### Relationships and Data Flow
- Connection between the MessageCreator and IdentifierGenerator—indicate that unique IDs are generated (via the RamseyUuid implementation) and appended to messages.
- How the constructed message is then passed to the ServiceBus, which manages its further processing.
- Under the ServiceBus umbrella, capture the role of the ReadModelConverter: one branch shows how it converts messages for queries (using Callback, Query implementations) and possibly transforms or fetches domain-specific objects.

##### Architectural Patterns
- Abstraction: The library is built on abstractions rather than concrete business logic, which means each module should be displayed as a clearly defined interface or service.
- Separation of Concerns: Separate the components (e.g., command handling vs. query handling) and indicate clear responsibilities.

##### Incorporate Relevant Technologies (as noted in the README and file names)
- That the project uses Composer for dependency management.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input Layer
    subgraph "Input Layer"
        EC["ExecuteCommand"]:::command
        EQ["ExecuteQuery"]:::command
    end

    %% Message Construction Layer
    subgraph "Message Construction Layer"
        MC["MessageCreator"]:::message
        IE["InputExtractor"]:::message
        NC["NamedConstructor"]:::message
        MCNE["MessageCannotBeCreated"]:::error
        AGI["AppendGeneratedIdentifier"]:::strategy
        UID["UseInputData"]:::strategy
    end

    %% Identifier Generation Layer
    subgraph "Identifier Generation Layer"
        IG["IdentifierGenerator"]:::utility
        RU["RamseyUuid"]:::utility
    end

    %% Dispatch/Processing Layer
    subgraph "Dispatch/Processing Layer"
        SB["ServiceBus"]:::service
        RMC["ReadModelConverter"]:::converter
        CB["Callback"]:::converter
        RQ["Query"]:::converter
    end

    %% Exception Handling
    EH["Exception Handling"]:::error

    %% Connections - Input to Message Construction
    EC -->|"sends command"| MC
    EQ -->|"sends query"| MC

    %% Within Message Construction Layer
    MC -->|"extracts input"| IE
    IE -->|"uses strategy"| AGI
    IE -->|"uses strategy"| UID
    MC -->|"creates message via"| NC
    MC -- "creation failure" --> MCNE
    MCNE -->|"triggers"| EH

    %% MessageCreator uses Identifier Generation
    MC -->|"generates ID via"| IG
    RU -->|"implementation"| IG

    %% Message flow to Service Bus
    MC -->|"dispatches message"| SB

    %% Service Bus processing to Read Model conversion
    SB -->|"converts message"| RMC
    RMC -->|"conversion strategy"| CB
    RMC -->|"conversion strategy"| RQ

    %% Click Events
    click EC "https://github.com/chimeraphp/foundation/blob/1.0.x/src/ExecuteCommand.php"
    click EQ "https://github.com/chimeraphp/foundation/blob/1.0.x/src/ExecuteQuery.php"
    click MC "https://github.com/chimeraphp/foundation/blob/1.0.x/src/MessageCreator.php"
    click IE "https://github.com/chimeraphp/foundation/tree/1.0.x/src/MessageCreator/InputExtractor"
    click AGI "https://github.com/chimeraphp/foundation/blob/1.0.x/src/MessageCreator/InputExtractor/AppendGeneratedIdentifier.php"
    click UID "https://github.com/chimeraphp/foundation/blob/1.0.x/src/MessageCreator/InputExtractor/UseInputData.php"
    click NC "https://github.com/chimeraphp/foundation/blob/1.0.x/src/MessageCreator/NamedConstructor.php"
    click MCNE "https://github.com/chimeraphp/foundation/blob/1.0.x/src/MessageCreator/MessageCannotBeCreated.php"
    click IG "https://github.com/chimeraphp/foundation/blob/1.0.x/src/IdentifierGenerator.php"
    click RU "https://github.com/chimeraphp/foundation/blob/1.0.x/src/IdentifierGenerator/RamseyUuid.php"
    click SB "https://github.com/chimeraphp/foundation/blob/1.0.x/src/ServiceBus.php"
    click RMC "https://github.com/chimeraphp/foundation/blob/1.0.x/src/ServiceBus/ReadModelConverter.php"
    click CB "https://github.com/chimeraphp/foundation/blob/1.0.x/src/ServiceBus/ReadModelConverter/Callback.php"
    click RQ "https://github.com/chimeraphp/foundation/blob/1.0.x/src/ServiceBus/ReadModelConverter/Query.php"
    click EH "https://github.com/chimeraphp/foundation/blob/1.0.x/src/Exception.php"

    %% Styles
    classDef command fill:#fef3c7,stroke:#d97706,stroke-width:2px;
    classDef message fill:#bfdbfe,stroke:#1e40af,stroke-width:2px;
    classDef error fill:#fecaca,stroke:#dc2626,stroke-width:2px;
    classDef utility fill:#bbf7d0,stroke:#166534,stroke-width:2px;
    classDef service fill:#fde68a,stroke:#b45309,stroke-width:2px;
    classDef converter fill:#e0f2fe,stroke:#0284c7,stroke-width:2px;
    classDef strategy fill:#ede9fe,stroke:#6d28d9,stroke-width:2px;
```
