# brokeyourbike/western-union-api-client-php architecture

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

- Interactive diagram: https://gitdiagram.com/brokeyourbike/western-union-api-client-php
- Repository: https://github.com/brokeyourbike/western-union-api-client-php

## Overview

##### Project type and purpose
- This is a PHP client library (SDK) for the Western Union REST API.
- It provides a thin wrapper over HTTP calls (via Guzzle) and maps request/responses into strongly‐typed PHP Models and Enums.

##### File structure
- Top level: configuration files (`composer.json`, `.github/`, CI workflows, testing configs).
- `src/Client.php`: the central orchestration class.
- `src/Interfaces/ConfigInterface.php`: abstraction for supplying API credentials and endpoints.
- `src/Enums`: various request‐ or response‐parameter enumerations.
- `src/Models`: data‐transfer objects mapping the JSON payloads returned by the API.
- `tests/`: PHPUnit tests verifying client behavior and mapping logic.

##### Key insights from the README
- Usage snippet shows dependency injection of a `ConfigInterface` and any `GuzzleHttp\ClientInterface`.
- The library’s sole external dependency is an HTTP client (Guzzle).
- No internal database or UI components—pure server‐side SDK.

a. Main components:
- Config Provider (implements `ConfigInterface`)
- HTTP Client (any `GuzzleHttp\ClientInterface`)
- API Client (`Client.php`)
- Enums (request/query parameter constraints)
- Models (response payload mapping)
- External Western Union REST API
- Supporting CI/CD (GitHub Actions) and Test Harness (PHPUnit)

b. Relationships & interactions:
1. The application implements `ConfigInterface` → supplies base URL, credentials.
2. The application injects a `GuzzleHttp\ClientInterface` → handles HTTP transport.
3. `Client` uses Config + HTTP Client → constructs requests (including Enums) → sends to Western Union API.
4. API returns JSON → `Client` maps JSON to Models → returns Models to caller.
5. PHPUnit tests invoke `Client` with mock HTTP client → assert correct mapping and error‐handling.
6. GitHub Actions workflows run static analysis, tests, and release automation on each commit.

c. Architectural patterns & principles:
- Dependency Injection (ConfigInterface, HTTP Client) for testability & extensibility.
- Single Responsibility: Client only orchestrates calls; Models only hold data; Enums only define constants.
- Layered separation: Configuration → Client orchestration → HTTP transport → Domain Models.

d. Key technologies & libraries:
- PHP 7.4+ (composer metadata in `composer.json`)
- GuzzleHttp for HTTP transport
- PHPUnit for testing
- PHPStan for static analysis
- GitHub Actions for CI/CD

##### Being detailed but not overcomplicated
- Every interaction path (normal calls, error flows, test harness).
- Config‐to‐client and client‐to‐HTTP layers are explicitly drawn.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core SDK Components
    subgraph "Core SDK"
        direction TB
        Config["Config Provider\n(ConfigInterface)"]:::component
        HTTP["HTTP Client\n(GuzzleHttp Interface)"]:::component
        Client["API Client\n(Orchestrator)"]:::component
        Enums["Enums\n(Request/Response Constraints)"]:::component
        Models["Models\n(Data Transfer Objects)"]:::component
    end

    %% External Services
    subgraph "External Services"
        direction TB
        ExternalHTTP["GuzzleHttp Transport"]:::external
        WesternUnion["Western Union\nREST API"]:::external
    end

    %% Testing & CI/CD
    subgraph "Development & CI/CD"
        direction TB
        Tests["PHPUnit Test Harness"]:::test
        CICD["GitHub Actions\nWorkflows"]:::cicd
        PHPStan["PHPStan\nStatic Analysis"]:::config
        PHPUnitCfg["PHPUnit\nConfiguration"]:::config
    end

    %% Interactions
    Config -->|provides config| Client
    HTTP -->|injects HTTP client| Client
    Client -->|constructs requests| ExternalHTTP
    ExternalHTTP -->|sends HTTP calls| WesternUnion
    WesternUnion -->|JSON response| ExternalHTTP
    ExternalHTTP -->|returns response| Client
    Client -->|maps JSON| Models
    Tests -->|invoke with mock HTTP| Client
    Tests -->|use config| Config
    Tests -->|assert mapping| Models
    CICD -->|run tests| Tests
    CICD -->|run static analysis| PHPStan
    CICD -->|use PHPUnit config| PHPUnitCfg

    %% Click Events
    click Config "https://github.com/brokeyourbike/western-union-api-client-php/blob/main/src/Interfaces/ConfigInterface.php"
    click Client "https://github.com/brokeyourbike/western-union-api-client-php/blob/main/src/Client.php"
    click Enums "https://github.com/brokeyourbike/western-union-api-client-php/tree/main/src/Enums/"
    click Models "https://github.com/brokeyourbike/western-union-api-client-php/tree/main/src/Models/"
    click HTTP "https://github.com/brokeyourbike/western-union-api-client-php/blob/main/composer.json"
    click Tests "https://github.com/brokeyourbike/western-union-api-client-php/tree/main/tests/"
    click CICD "https://github.com/brokeyourbike/western-union-api-client-php/tree/main/.github/workflows/"
    click PHPStan "https://github.com/brokeyourbike/western-union-api-client-php/blob/main/phpstan.neon"
    click PHPUnitCfg "https://github.com/brokeyourbike/western-union-api-client-php/blob/main/phpunit.xml"

    %% Styling
    classDef component fill:#B3E5FC,stroke:#0277BD,stroke-width:1px
    classDef external fill:#E0E0E0,stroke:#616161,stroke-width:1px,stroke-dasharray: 5 5
    classDef test fill:#C8E6C9,stroke:#2E7D32,stroke-width:1px
    classDef cicd fill:#F8BBD0,stroke:#C2185B,stroke-width:1px
    classDef config fill:#FFF9C4,stroke:#F9A825,stroke-width:1px
```
