# tochix/smetrics architecture

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

- Interactive diagram: https://gitdiagram.com/tochix/smetrics
- Repository: https://github.com/tochix/smetrics

## Overview

##### Project type and purpose
- This is an open-source CLI tool (PHP 7.1+) installed and run via Composer.
- It generates “SMetrics” statistics based on users’ posts by calling an external HTTP API, processing the JSON response, mapping it into domain models, and presenting summary stats.

##### File structure
- Top-level
- index.php – CLI entry point
- composer.json/lock, LICENSE, README.md
- src/Config – configuration loader (AbstractConfig, SMetricsConfig)
- src/Api
- Api/SMetrics – core SMetrics client classes (SMetricsApi, SMetricsFacade, SMetricsStats, Locator)
- Api/Http – HTTP-layer abstractions (RequestInterface, Request, ResponseInterface, ResponseFactory) and exceptions
- Api/SMetrics/Model – domain model factory, Post model & interface
- Exceptions are namespaced per subsystem (Config, Http, SMetrics).
- No UI or database—just CLI, config file, HTTP calls, in-memory objects.

##### README for additional insights
- Usage: php index.php
- Config file under src/Config/smetrics.php

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CLI Entry
    index["index.php (CLI Entrypoint)"]:::infrastructure

    %% Config Layer
    subgraph "Config Layer"
        absConfig["AbstractConfig"]:::infrastructure
        configIntf["SMetricsConfigInterface"]:::infrastructure
        smConfig["SMetricsConfig"]:::infrastructure
        defaultConfig["smetrics.php (Default Config)"]:::infrastructure
    end

    %% SMetrics API Layer
    subgraph "SMetrics API Layer"
        locator["SMetricsLocator"]:::core
        facade["SMetricsFacade"]:::core
        abstractApi["AbstractApi"]:::core
        apiClient["SMetricsApi"]:::core
        stats["SMetricsStats"]:::core
    end

    %% HTTP Layer
    subgraph "HTTP Layer"
        reqIntf["RequestInterface"]:::infrastructure
        req["Request"]:::infrastructure
        respIntf["ResponseInterface"]:::infrastructure
        resp["Response"]:::infrastructure
        respFactory["ResponseFactory"]:::infrastructure
    end

    %% Model Layer
    subgraph "Model Layer"
        modelFactory["ModelFactory"]:::core
        postIntf["PostInterface"]:::core
        post["Post"]:::core
    end

    %% External Service
    external["External HTTP API"]:::external

    %% Exception Subsystems
    subgraph "Exception Handling"
        subgraph "Config Exceptions"
            cfgExc1["AbstractConfigException"]:::exception
            cfgExc2["ConfigFileNotFoundException"]:::exception
            cfgExc3["ConfigKeyNotFoundException"]:::exception
        end
        subgraph "HTTP Exceptions"
            httpExc1["AbstractHttpException"]:::exception
            httpExc2["FailedRequestException"]:::exception
        end
        subgraph "SMetrics Exceptions"
            smExc1["AbstractSMetricsException"]:::exception
            smExc2["FailedToWriteTokenToFileCacheException"]:::exception
            smExc3["InvalidPostsResponseDataException"]:::exception
            smExc4["MissingRequiredResponseFieldsException"]:::exception
            smExc5["MissingResponseParameterException"]:::exception
        end
    end

    %% Flow
    index -->|"invokes"| facade
    facade -->|"loads config via"| smConfig
    smConfig --> absConfig
    smConfig --> configIntf
    smConfig --> defaultConfig

    facade -->|"uses locator"| locator
    facade -->|"calls"| apiClient
    apiClient --> abstractApi

    apiClient -->|"builds request"| req
    req --> reqIntf
    req --> external
    external --> resp
    resp --> respIntf
    resp --> respFactory
    respFactory --> resp

    apiClient -->|"uses factory"| modelFactory
    modelFactory --> postIntf
    modelFactory --> post

    apiClient -->|"processes posts"| stats
    stats --> index

    %% Exceptions edges
    smConfig --- cfgExc1
    smConfig --- cfgExc2
    smConfig --- cfgExc3

    req --- httpExc1
    req --- httpExc2

    apiClient --- smExc1
    apiClient --- smExc2
    apiClient --- smExc3
    apiClient --- smExc4
    apiClient --- smExc5

    %% Click Events
    click index "https://github.com/tochix/smetrics/blob/master/index.php"
    click absConfig "https://github.com/tochix/smetrics/blob/master/src/Config/AbstractConfig.php"
    click configIntf "https://github.com/tochix/smetrics/blob/master/src/Config/SMetricsConfigInterface.php"
    click smConfig "https://github.com/tochix/smetrics/blob/master/src/Config/SMetricsConfig.php"
    click defaultConfig "https://github.com/tochix/smetrics/blob/master/src/Config/smetrics.php"
    click facade "https://github.com/tochix/smetrics/blob/master/src/Api/SMetrics/SMetricsFacade.php"
    click apiClient "https://github.com/tochix/smetrics/blob/master/src/Api/SMetrics/SMetricsApi.php"
    click reqIntf "https://github.com/tochix/smetrics/blob/master/src/Api/Http/RequestInterface.php"
    click req "https://github.com/tochix/smetrics/blob/master/src/Api/Http/Request.php"
    click respIntf "https://github.com/tochix/smetrics/blob/master/src/Api/Http/ResponseInterface.php"
    click resp "https://github.com/tochix/smetrics/blob/master/src/Api/Http/Response.php"
    click respFactory "https://github.com/tochix/smetrics/blob/master/src/Api/Http/ResponseFactory.php"
    click httpExc1 "https://github.com/tochix/smetrics/blob/master/src/Api/Http/Exception/AbstractHttpException.php"
    click httpExc2 "https://github.com/tochix/smetrics/blob/master/src/Api/Http/Exception/FailedRequestException.php"
    click modelFactory "https://github.com/tochix/smetrics/blob/master/src/Api/SMetrics/Model/ModelFactory.php"
    click postIntf "https://github.com/tochix/smetrics/blob/master/src/Api/SMetrics/Model/PostInterface.php"
    click post "https://github.com/tochix/smetrics/blob/master/src/Api/SMetrics/Model/Post.php"
    click stats "https://github.com/tochix/smetrics/blob/master/src/Api/SMetrics/SMetricsStats.php"
    click locator "https://github.com/tochix/smetrics/blob/master/src/Api/SMetrics/SMetricsLocator.php"
    click cfgExc1 "https://github.com/tochix/smetrics/blob/master/src/Config/Exception/AbstractConfigException.php"
    click cfgExc2 "https://github.com/tochix/smetrics/blob/master/src/Config/Exception/ConfigFileNotFoundException.php"
    click cfgExc3 "https://github.com/tochix/smetrics/blob/master/src/Config/Exception/ConfigKeyNotFoundException.php"
    click smExc1 "https://github.com/tochix/smetrics/blob/master/src/Api/SMetrics/Exception/AbstractSMetricsException.php"
    click smExc2 "https://github.com/tochix/smetrics/blob/master/src/Api/SMetrics/Exception/FailedToWriteTokenToFileCacheException.php"
    click smExc3 "https://github.com/tochix/smetrics/blob/master/src/Api/SMetrics/Exception/InvalidPostsResponseDataException.php"
    click smExc4 "https://github.com/tochix/smetrics/blob/master/src/Api/SMetrics/Exception/MissingRequiredResponseFieldsException.php"
    click smExc5 "https://github.com/tochix/smetrics/blob/master/src/Api/SMetrics/Exception/MissingResponseParameterException.php"
    click abstractApi "https://github.com/tochix/smetrics/blob/master/src/Api/AbstractApi.php"

    %% Styles
    classDef core fill:#e1f5fe,stroke:#0288d1,color:#000
    classDef infrastructure fill:#e8f5e9,stroke:#2e7d32,color:#000
    classDef external fill:#fff3e0,stroke:#fb8c00,color:#000
    classDef exception fill:#ffebee,stroke:#c62828,color:#000
```
