# samiaraboglu/pubg-php-api architecture

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

- Interactive diagram: https://gitdiagram.com/samiaraboglu/pubg-php-api
- Repository: https://github.com/samiaraboglu/pubg-php-api

## Overview

##### Project type and purpose
- This is a PHP client library (wrapper) for the PUBG REST API.
- Its goal is to provide PHP services (Player, Season, Match, etc.) that fetch and model PUBG data.

##### File structure
- src/Config.php and src/Api.php form the core configuration and HTTP request engine.
- Service classes at src/Player.php, src/Season.php, src/Lifetime.php, src/Match.php, src/Leaderboard.php, src/Tournament.php, src/Sample.php each encapsulate one REST resource.
- Domain model classes under src/Object/* (Leaderboard.php, Lifetime.php, Match.php, Player.php, Sample.php, Season.php, Tournament.php) represent parsed API responses.

##### README for insights
- Configuration flow: instantiate Pubg\Config → set API key & platform → inject into Pubg\Api.
- Each service (e.g. new Pubg\Player($api)) uses Pubg\Api to make calls.
- Services return model objects or collections of model objects.

##### Main components & their interactions
a. Core Layer
- Config (stores API key, platform, region)
- Api (HTTP client, builds URLs, sets headers, handles responses/exceptions)
b. Service Layer
- PlayerService, SeasonService, LifetimeService, MatchService, LeaderboardService, TournamentService, SampleService
- Dependency: each service holds a reference to Api
c. Domain Model Layer
- Objects in src/Object: classes that map JSON payloads to PHP properties
d. External System
- PUBG REST API endpoints

Relationships & data flow:
1. The application code creates a Config object and populates it.
2. Config is passed to Api, which uses an HTTP client (cURL or Guzzle) to call the external PUBG API.
3. Service classes call Api methods (GET endpoints) based on resource paths (e.g., /players/{id}).
4. Api returns raw JSON; services delegate JSON to the appropriate constructor or factory in the Domain Model layer.
5. Domain objects are returned to the caller.

##### Architectural patterns & design principles
- Dependency Injection: services receive Api via constructor.
- Single Responsibility: each service handles one resource type.
- Layered Architecture: Core → Services → Models.
- Data Mapping: JSON → Domain Objects.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Layer
    subgraph "Core Layer"
        Cfg["Config"]:::core
        Api["Api (HTTP Client)"]:::core
    end

    %% Service Layer
    subgraph "Service Layer"
        PlayerS["PlayerService"]:::service
        SeasonS["SeasonService"]:::service
        LifetimeS["LifetimeService"]:::service
        MatchS["MatchService"]:::service
        LeaderboardS["LeaderboardService"]:::service
        TournamentS["TournamentService"]:::service
        SampleS["SampleService"]:::service
    end

    %% Model Layer
    subgraph "Model Layer"
        PlayerM["Player Model"]:::model
        SeasonM["Season Model"]:::model
        LifetimeM["Lifetime Model"]:::model
        MatchM["Match Model"]:::model
        LeaderboardM["Leaderboard Model"]:::model
        TournamentM["Tournament Model"]:::model
        SampleM["Sample Model"]:::model
    end

    %% External System
    ExternalAPI["PUBG REST API"]:::external

    %% Connections
    Cfg -->|"set API key, platform"| Api
    PlayerS -->|"calls GET/POST"| Api
    SeasonS -->|"calls GET/POST"| Api
    LifetimeS -->|"calls GET/POST"| Api
    MatchS -->|"calls GET/POST"| Api
    LeaderboardS -->|"calls GET/POST"| Api
    TournamentS -->|"calls GET/POST"| Api
    SampleS -->|"calls GET/POST"| Api

    Api -->|"HTTP request/response"| ExternalAPI

    Api -->|"maps JSON→Object"| PlayerM
    Api -->|"maps JSON→Object"| SeasonM
    Api -->|"maps JSON→Object"| LifetimeM
    Api -->|"maps JSON→Object"| MatchM
    Api -->|"maps JSON→Object"| LeaderboardM
    Api -->|"maps JSON→Object"| TournamentM
    Api -->|"maps JSON→Object"| SampleM

    %% Click Events
    click Cfg "https://github.com/samiaraboglu/pubg-php-api/blob/master/src/Config.php"
    click Api "https://github.com/samiaraboglu/pubg-php-api/blob/master/src/Api.php"
    click PlayerS "https://github.com/samiaraboglu/pubg-php-api/blob/master/src/Player.php"
    click SeasonS "https://github.com/samiaraboglu/pubg-php-api/blob/master/src/Season.php"
    click LifetimeS "https://github.com/samiaraboglu/pubg-php-api/blob/master/src/Lifetime.php"
    click MatchS "https://github.com/samiaraboglu/pubg-php-api/blob/master/src/Match.php"
    click LeaderboardS "https://github.com/samiaraboglu/pubg-php-api/blob/master/src/Leaderboard.php"
    click TournamentS "https://github.com/samiaraboglu/pubg-php-api/blob/master/src/Tournament.php"
    click SampleS "https://github.com/samiaraboglu/pubg-php-api/blob/master/src/Sample.php"
    click PlayerM "https://github.com/samiaraboglu/pubg-php-api/blob/master/src/Object/Player.php"
    click SeasonM "https://github.com/samiaraboglu/pubg-php-api/blob/master/src/Object/Season.php"
    click LifetimeM "https://github.com/samiaraboglu/pubg-php-api/blob/master/src/Object/Lifetime.php"
    click MatchM "https://github.com/samiaraboglu/pubg-php-api/blob/master/src/Object/Match.php"
    click LeaderboardM "https://github.com/samiaraboglu/pubg-php-api/blob/master/src/Object/Leaderboard.php"
    click TournamentM "https://github.com/samiaraboglu/pubg-php-api/blob/master/src/Object/Tournament.php"
    click SampleM "https://github.com/samiaraboglu/pubg-php-api/blob/master/src/Object/Sample.php"

    %% Styles
    classDef core fill:#f2f2f2,stroke:#333,stroke-width:1px
    classDef service fill:#d9edf7,stroke:#31708f,stroke-width:1px
    classDef model fill:#dff0d8,stroke:#3c763d,stroke-width:1px
    classDef external fill:#fcf8e3,stroke:#8a6d3b,stroke-width:1px,stroke-dasharray: 5 5
```
