# reateguidiego/mytheresa-promotions architecture

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

- Interactive diagram: https://gitdiagram.com/reateguidiego/mytheresa-promotions
- Repository: https://github.com/reateguidiego/mytheresa-promotions

## Overview

##### Project Type & Purpose
- Type: A backend REST API microservice built on Symfony 6.4
- Purpose: Expose a single endpoint (`GET /products`) that returns up to 5 products with calculated promotions, reading from a JSON dataset.

##### Main Architectural Layers & Components
a. HTTP/API Layer
– public/index.php → Symfony HTTP Kernel initialization
– Routing → resolves `/products` to ProductController
b. Controller Layer
– src/Controller/ProductController: parses query params, calls application service, returns JSON response
c. Application Layer
– src/Application/ProductService: contains promotion logic, filtering, limiting results
d. Domain Layer
– src/Domain/Product: product DTO (SKU, name, category, price data with original/final/discount)
e. Infrastructure Layer
– src/Infrastructure/Data/ProductDataSourceInterface
- JsonFileProductDataSource: reads data/products.json
- InMemoryProductDataSource: used in tests
f. Configuration & Bootstrapping
– config/*: Symfony bundles, services, routes
– .env, .env.dev, .env.test: environment variables (APP_SECRET)
g. CI/CD & Testing
– .github/workflows/ci.yml: GitHub Actions pipeline
– phpunit.xml.dist & tests/: unit tests (ProductServiceTest), functional tests (ProductControllerTest)

##### Interactions & Data Flow
1) Client sends HTTP GET /products?category=…&priceLessThan=…
2) public/index.php → Kernel → Router → ProductController
3) ProductController extracts filters, calls ProductService
4) ProductService asks injected ProductDataSourceInterface for raw product list
5) JSON data source reads data/products.json, returns Product DTOs
6) ProductService applies pre‐discount filter → calculates discount (30%, 15%, etc.) → builds final price DTO → enforces 5‐item limit
7) Controller serializes result to JSON response and returns to client
8) CI pipeline runs on each commit: installs dependencies, runs tests

##### Architectural Patterns & Design Principles
- Clean Architecture / Layered: clear separation between transport (Controller), business logic (Application), domain model (Domain), and data sources (Infrastructure)
- Dependency Injection: Symfony’s service container injects the chosen data source implementation
- Strategy Pattern (future): discount policies could be refactored into interchangeable strategies
- Single Responsibility: each class has a focused purpose (data access, business logic, transport)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Entities
    Client["Client (HTTP Consumer)"]:::external

    %% HTTP/API Layer
    subgraph "HTTP/API Layer"
        publicIndex["public/index.php\n(Front Controller)"]:::http
        Kernel["Symfony Kernel"]:::http
        Router["Router\n(config/routes.yaml)"]:::http
    end

    %% Controller & Application Layer
    subgraph "Controller & Application" 
        ProductController["ProductController"]:::controller
        ProductService["ProductService"]:::controller
    end

    %% Domain Layer
    subgraph "Domain Layer"
        DomainProduct["Product DTO"]:::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        DataInterface["ProductDataSourceInterface"]:::infra
        JsonFileDS["JsonFileProductDataSource"]:::infra
        InMemoryDS["InMemoryProductDataSource"]:::infra
        JSONFile["data/products.json"]:::infra
    end

    %% Configuration & Bootstrapping
    subgraph "Configuration & Bootstrapping"
        ConfigServices["config/services.yaml"]:::config
        ConfigRoutes["config/routes.yaml\nconfig/routes/*.yaml"]:::config
        ConfigEnv[".env\n.env.dev\n.env.test"]:::config
    end

    %% CI/CD & Testing
    subgraph "CI/CD & Testing"
        CI["GitHub Actions CI"]:::external
        PHPUnitCfg["phpunit.xml.dist"]:::external
        UnitTest["tests/Application/ProductServiceTest.php"]:::external
        FuncTest["tests/Controller/ProductControllerTest.php"]:::external
    end

    %% Data Flow
    Client -->|HTTP GET /products| publicIndex
    publicIndex --> Kernel
    Kernel --> Router
    Router --> ProductController
    ProductController -->|calls| ProductService
    ProductService -->|depends on| DataInterface
    DataInterface --> JsonFileDS
    DataInterface --> InMemoryDS
    JsonFileDS --> JSONFile
    ProductService -->|uses| DomainProduct
    ProductService -->|returns DTOs| ProductController
    ProductController -->|JSON Response| Client

    %% Config Relationships
    Kernel --> ConfigServices
    Kernel --> ConfigRoutes
    Kernel --> ConfigEnv

    %% CI/CD & Testing Flow
    CI -->|uses| PHPUnitCfg
    CI -->|runs| UnitTest
    CI -->|runs| FuncTest

    %% Click Events
    click publicIndex "https://github.com/reateguidiego/mytheresa-promotions/blob/main/public/index.php"
    click Kernel "https://github.com/reateguidiego/mytheresa-promotions/blob/main/src/Kernel.php"
    click ConfigRoutes "https://github.com/reateguidiego/mytheresa-promotions/blob/main/config/routes.yaml"
    click ProductController "https://github.com/reateguidiego/mytheresa-promotions/blob/main/src/Controller/ProductController.php"
    click ProductService "https://github.com/reateguidiego/mytheresa-promotions/blob/main/src/Application/ProductService.php"
    click DomainProduct "https://github.com/reateguidiego/mytheresa-promotions/blob/main/src/Domain/Product.php"
    click DataInterface "https://github.com/reateguidiego/mytheresa-promotions/blob/main/src/Infrastructure/Data/ProductDataSourceInterface.php"
    click JsonFileDS "https://github.com/reateguidiego/mytheresa-promotions/blob/main/src/Infrastructure/Data/JsonFileProductDataSource.php"
    click InMemoryDS "https://github.com/reateguidiego/mytheresa-promotions/blob/main/src/Infrastructure/Data/InMemoryProductDataSource.php"
    click JSONFile "https://github.com/reateguidiego/mytheresa-promotions/blob/main/data/products.json"
    click ConfigServices "https://github.com/reateguidiego/mytheresa-promotions/blob/main/config/services.yaml"
    click ConfigEnv "https://github.com/reateguidiego/mytheresa-promotions/blob/main/.env"
    click CI "https://github.com/reateguidiego/mytheresa-promotions/blob/main/.github/workflows/ci.yml"
    click PHPUnitCfg "https://github.com/reateguidiego/mytheresa-promotions/blob/main/phpunit.xml.dist"
    click UnitTest "https://github.com/reateguidiego/mytheresa-promotions/blob/main/tests/Application/ProductServiceTest.php"
    click FuncTest "https://github.com/reateguidiego/mytheresa-promotions/blob/main/tests/Controller/ProductControllerTest.php"

    %% Styles
    classDef http fill:#CCE5FF,stroke:#004080,stroke-width:1px
    classDef controller fill:#DFF5E1,stroke:#2F8F00,stroke-width:1px
    classDef domain fill:#FFE5B4,stroke:#B36B00,stroke-width:1px
    classDef infra fill:#E3D3FF,stroke:#5D3FD3,stroke-width:1px
    classDef config fill:#F0F0F0,stroke:#666666,stroke-width:1px
    classDef external fill:#F5F5F5,stroke:#888888,stroke-width:1px
```
