# shopwarelabs/swagadvancedsyncapi architecture

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

- Interactive diagram: https://gitdiagram.com/shopwarelabs/swagadvancedsyncapi
- Repository: https://github.com/shopwarelabs/swagadvancedsyncapi

## Overview

##### Project type and purpose
- This is a Shopware 6 plugin (“SwagAdvancedSyncAPI”) that extends the Shopware backend by exposing two custom REST endpoints for advanced stock‐ and price‐synchronization. It is not a standalone microservice, but a modular extension inside the Shopware monolith.

##### File structure
- Top level:
- composer.json / phpunit.xml.dist / LICENSE / README.md – standard plugin metadata and test configuration
- src/SwagAdvancedSyncAPI.php – plugin bootstrap class that registers the bundle with Shopware
- src/Api – HTTP controllers for each endpoint
- StockUpdateController.php
- PriceUpdateController.php
- src/Service – business logic layer
- StockUpdateService.php – handles stock updates, availability calculation, event dispatch
- PriceUpdateService.php – orchestrates price updates via Shopware’s SyncService
- src/Resources/config – XML configurations
- routes.xml – maps HTTP paths (/api/_action/swag-advanced-sync/…) to the controllers
- services.xml – defines each controller and service as injectable Symfony services
- src/Resources/Schema – JSON schemas for request validation
- tests – unit and integration tests around controllers and services

##### README for additional insights
- Defines two POST endpoints with sample payloads and responses.
- Describes the event system: two custom events (ProductNoLongerAvailableEvent, InvalidateProductCache).
- Installation instructions show how the plugin slots into the Shopware plugin system.

## Diagram (Mermaid)

```mermaid
graph TD
    %% External
    HTTPClient(["HTTP Client"]):::external

    %% Shopware Entry
    Shopware(["Shopware HTTP Kernel / API Router"]):::core

    %% Plugin Bundle
    subgraph "SwagAdvancedSyncAPI Plugin Bundle"
        bootstrap["SwagAdvancedSyncAPI.php"]:::plugin
        subgraph "Configuration"
            routes["routes.xml"]:::config
            servicesCfg["services.xml"]:::config
        end
        subgraph "JSON Schemas"
            stockSchema["stock-update.json"]:::config
            priceSchema["price-update.json"]:::config
        end
        subgraph "API Layer"
            stockCtrl["StockUpdateController"]:::api
            priceCtrl["PriceUpdateController"]:::api
        end
        subgraph "Service Layer"
            stockSrv["StockUpdateService"]:::service
            priceSrv["PriceUpdateService"]:::service
        end
        bootstrap --> routes
        bootstrap --> servicesCfg
        routes --> stockCtrl
        routes --> priceCtrl
        servicesCfg --> stockCtrl
        servicesCfg --> priceCtrl
        stockCtrl --> stockSchema
        priceCtrl --> priceSchema
        stockCtrl --> stockSrv
        priceCtrl --> priceSrv
    end

    %% Shopware Core Services
    subgraph "Shopware Core"
        repo["Repository / SyncService"]:::core
        eventDisp["EventDispatcher"]:::core
        cacheSys["Cache Subsystem"]:::core
    end

    %% Infrastructure
    DB[(Database)]:::infra
    Cache[(Cache)]:::infra

    %% Tests & Metadata
    subgraph "Plugin Metadata & Tests"
        composer["composer.json"]:::tests
        readme["README.md"]:::tests
        phpunitCfg["phpunit.xml.dist"]:::tests
        subgraph "Unit Tests"
            stockCtrlTest["StockUpdateControllerTest"]:::tests
            priceCtrlTest["PriceUpdateControllerTest"]:::tests
        end
        subgraph "Integration Tests"
            stockSrvTest["StockUpdateServiceTest"]:::tests
            priceSrvTest["PriceUpdateServiceTest"]:::tests
        end
    end

    %% Data Flows
    HTTPClient -->|POST /api/_action/swag-advanced-sync/stock| Shopware
    HTTPClient -->|POST /api/_action/swag-advanced-sync/price| Shopware

    Shopware -->|route to| stockCtrl
    Shopware -->|route to| priceCtrl

    stockSrv -->|reads/writes| repo
    priceSrv -->|orchestrates| repo

    stockSrv -->|dispatchProductNoLongerAvailableEvent| eventDisp
    stockSrv -->|dispatchInvalidateProductCache| eventDisp
    priceSrv -->|dispatchInvalidateProductCache| eventDisp

    eventDisp -->|handles event| cacheSys

    repo -->|persist| DB
    cacheSys -->|invalidate| Cache

    %% Click Events
    click bootstrap "https://github.com/shopwarelabs/swagadvancedsyncapi/blob/main/src/SwagAdvancedSyncAPI.php"
    click stockCtrl "https://github.com/shopwarelabs/swagadvancedsyncapi/blob/main/src/Api/StockUpdateController.php"
    click priceCtrl "https://github.com/shopwarelabs/swagadvancedsyncapi/blob/main/src/Api/PriceUpdateController.php"
    click stockSrv "https://github.com/shopwarelabs/swagadvancedsyncapi/blob/main/src/Service/StockUpdateService.php"
    click priceSrv "https://github.com/shopwarelabs/swagadvancedsyncapi/blob/main/src/Service/PriceUpdateService.php"
    click routes "https://github.com/shopwarelabs/swagadvancedsyncapi/blob/main/src/Resources/config/routes.xml"
    click servicesCfg "https://github.com/shopwarelabs/swagadvancedsyncapi/blob/main/src/Resources/config/services.xml"
    click stockSchema "https://github.com/shopwarelabs/swagadvancedsyncapi/blob/main/src/Resources/Schema/AdminApi/stock-update.json"
    click priceSchema "https://github.com/shopwarelabs/swagadvancedsyncapi/blob/main/src/Resources/Schema/AdminApi/price-update.json"
    click composer "https://github.com/shopwarelabs/swagadvancedsyncapi/blob/main/composer.json"
    click readme "https://github.com/shopwarelabs/swagadvancedsyncapi/blob/main/README.md"
    click phpunitCfg "https://github.com/shopwarelabs/swagadvancedsyncapi/blob/main/phpunit.xml.dist"
    click stockCtrlTest "https://github.com/shopwarelabs/swagadvancedsyncapi/blob/main/tests/Unit/Api/StockUpdateControllerTest.php"
    click priceCtrlTest "https://github.com/shopwarelabs/swagadvancedsyncapi/blob/main/tests/Unit/Api/PriceUpdateControllerTest.php"
    click stockSrvTest "https://github.com/shopwarelabs/swagadvancedsyncapi/blob/main/tests/Integration/Service/StockUpdateServiceTest.php"
    click priceSrvTest "https://github.com/shopwarelabs/swagadvancedsyncapi/blob/main/tests/Integration/Service/PriceUpdateServiceTest.php"

    %% Styling
    classDef external fill:#ffa500,stroke:#333;
    classDef api fill:#87ceeb,stroke:#333;
    classDef service fill:#90ee90,stroke:#333;
    classDef core fill:#d3d3d3,stroke:#333;
    classDef infra fill:#cccccc,stroke:#333;
    classDef plugin fill:#f0e68c,stroke:#333;
    classDef config fill:#ffd700,stroke:#333;
    classDef tests fill:#eee8aa,stroke:#333;
```
