# friendsofshopware/froshprofiler architecture

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

- Interactive diagram: https://gitdiagram.com/friendsofshopware/froshprofiler
- Repository: https://github.com/friendsofshopware/froshprofiler

## Overview

##### Project type and purpose
- This is a Shopware 5 plugin (“FroshProfiler”) written in PHP. Its goal is to hook into the Shopware request lifecycle, collect profiling data (timings, events, DB queries, cache usage, dumps, etc.), and surface that data via a frontend toolbar, a backend UI, and an optional external var‐dump server.

##### File structure
- Top‐level directories:
- Components – core PHP services (collectors, cache, event manager, Smarty integration, var‐dumper, traceability, block annotation)
- Controller – controllers for frontend toolbar and backend profiling UI
- Models – persistence (Profile entity)
- Resources – DI configuration (services.xml, config.xml, plugin.xml), Smarty plugins, translations, views (frontend toolbar, backend UI)
- Subscriber – event listeners that hook into Shopware events, capture data, and feed the profiler
- Tests – unit and functional tests
- Configuration/metadata files: plugin.xml, composer.json, .php_cs.dist, phpstan.neon
- Build scripts: build.sh, GitHub workflows

##### README for additional insights
- The plugin registers collectors (DB, cache, events, exceptions, forms, Smarty, PHP, user, general, etc.)
- It optionally starts a Symfony var‐dump server for rich dump rendering
- Frontend JavaScript Asset: StateManager for PubSub event logging
- Two UI surfaces: a browser toolbar for storefront users and a backend module accessible via an X-Profiler-URL header

a. Main components
1. Shopware Core Application (PHP MVC + Smarty templating + Event Dispatcher)
2. FroshProfiler Plugin (runs inside Shopware):
– Subscribers (hook into events: controller dispatch, template compilation, var dumps)
– Components (Collectors, CacheFactory, Logger, BlockAnnotator, VarDumper, Traceable wrappers)
– Controllers (Frontend Profiler toolbar endpoint; Backend Profiler module)
– Models (Profile entity stored in Shopware DB)
– Services (defined in Resources/services.xml)
3. Persistence Layer (MySQL/PostgreSQL)
4. Frontend Browser (injects toolbar, loads JS state manager, communicates via AJAX)
5. Backend Admin UI (Shopware backend module for performance analysis)
6. Optional VarDump Server (Symfony dump server running externally on console)
b. Relationships and interactions
- Incoming HTTP Request → Shopware Front Controller → Event Dispatcher
- Profiler Subscribers intercept various events (DB query, cache access, form render, exceptions, Smarty compile) → push data into Collectors
- At end of request, Frontend Controller returns HTML with injected toolbar (Smarty view)
- Toolbar JS records client‐side events and requests detail endpoints asynchronously
- Backend Controller pulls Profile data from DB and renders backend UI via Smarty templates
- If var‐dump server enabled, dump() calls forward data to external Symfony server → HTML file in browser
c. Architectural patterns/design principles
- Plugin modularity via Symfony-style service container (DI configuration in XML)
- Event‐driven collection using Shopware’s event dispatcher
- Separation of concerns: Collectors only gather data, Controllers only present it, Subscribers wire everything together
- Traceable wrapper classes allow decorating core services for timing
- Smarty template plugins and block annotation to inject toolbar markup
d. Key technologies/frameworks
- PHP 7+ / Symfony components (EventDispatcher, VarDumper)
- Shopware plugin system, Smarty templating engine
- JavaScript (StateManager, Chart.js) for frontend profiling
- MySQL (Shopware database)

##### Detail
- How the BlockAnnotator and Smarty resources inject toolbar blocks
- Configuration entry point (Resources/config.xml and services.xml) that wires the services
- Two execution contexts (frontend vs backend) and their distinct controllers and views

## Diagram (Mermaid)

```mermaid
flowchart TD
    direction TB

    subgraph "Browser"
        BROWSER("Frontend Browser"):::client
    end

    subgraph "Shopware Core" 
        direction TB
        FrontController("Front Controller"):::core
        EventDispatcher("Event Dispatcher"):::core
    end

    subgraph "FroshProfiler Plugin"
        direction TB

        subgraph "Subscribers"
            BlockAnnotationSub("BlockAnnotationSubscriber"):::plugin
            CacheSub("CacheSubscriber"):::plugin
            CollectorSub("CollectorSubscriber"):::plugin
            DatabaseProfilerSub("DatabaseProfilerSubscriber"):::plugin
            JavascriptSub("JavascriptSubscriber"):::plugin
            ProfilerControllerSub("ProfilerControllerSubscriber"):::plugin
            SmartyProfilerSub("SmartyProfilerSubscriber"):::plugin
            VarDumpCollectorSub("VarDumpCollectorSubscriber"):::plugin
            VarDumpServerSub("VarDumpServerSubscriber"):::plugin
        end

        subgraph "Components"
            Collector("Collector"):::plugin
            DBCollector("DBCollector"):::plugin
            CacheCollector("CacheCollector"):::plugin
            EventCollector("EventCollector"):::plugin
            Logger("Logger"):::plugin
            CacheFactory("CacheFactory"):::plugin
            BlockAnnotatorComp("BlockAnnotator"):::plugin
            EventManager("EventManager"):::plugin
            ClonerFactory("ClonerFactory"):::plugin
            RequestContextProvider("RequestContextProvider"):::plugin
            VarDumperCaster("VarDumperCaster"):::plugin
            TraceableGenerator("TraceableGenerator"):::plugin
        end

        subgraph "Controllers"
            FrontendProfilerController("Frontend Profiler Controller"):::plugin
        end

        subgraph "Models"
            ProfileEntity(("Profile Entity")):::plugin
        end

        subgraph "Configuration"
            ConfigXML("config.xml"):::config
            ServicesXML("services.xml"):::config
            CollectorsXML("collectors.xml"):::config
            LoggerXML("logger.xml"):::config
            VarDumpXML("var_dump.xml"):::config
        end

        subgraph "Smarty Integration"
            CompilerFetch("compiler.fetchFile.php"):::plugin
            ModifierConvert("modifier.convertMemory.php"):::plugin
            ModifierDump("modifier.dump.php"):::plugin
            ModifierSQL("modifier.sqlFormat.php"):::plugin
        end

        subgraph "Views & Assets"
            ToolbarViews("Toolbar Views"):::view
            ProfilerFEViews("Frontend Profiler Views & JS"):::view
            BackendUIViews("Backend Profiler UI"):::view
        end
    end

    DB(("Shopware Database")):::db
    VarDumpServer(("VarDump Server")):::external

    %% Data flows
    BROWSER -->|"HTTP Request"| FrontController
    FrontController -->|"dispatch"| EventDispatcher
    EventDispatcher -->|"hook events"| BlockAnnotationSub & CacheSub & CollectorSub & DatabaseProfilerSub & JavascriptSub & ProfilerControllerSub & SmartyProfilerSub & VarDumpCollectorSub & VarDumpServerSub
    BlockAnnotationSub & CacheSub & CollectorSub & DatabaseProfilerSub & JavascriptSub & ProfilerControllerSub & SmartyProfilerSub & VarDumpCollectorSub & VarDumpServerSub -->|"collect data"| Collector & DBCollector & CacheCollector & EventCollector & Logger & CacheFactory & BlockAnnotatorComp & EventManager & ClonerFactory & RequestContextProvider & VarDumperCaster & TraceableGenerator
    DBCollector & CacheCollector & EventCollector & Logger --> ProfileEntity
    ProfileEntity -->|"DB write/read"| DB
    FrontendProfilerController --> ToolbarViews
    ToolbarViews --> BROWSER
    ProfilerFEViews --> BROWSER
    FrontendProfilerController --> ProfileEntity
    BackendUIViews -.-> ProfileEntity
    VarDumpCollectorSub -->|"dump()"| VarDumpServer
    VarDumpServer -->|"dump.html"| BROWSER
    ConfigXML & ServicesXML & CollectorsXML & LoggerXML & VarDumpXML --> Collector & DBCollector & CacheCollector & EventCollector & Logger & FrontendProfilerController & ProfileEntity & Subscribers

    %% Click Events
    click FroshProfiler.php "https://github.com/friendsofshopware/froshprofiler/blob/main/FroshProfiler.php"
    click ConfigXML "https://github.com/friendsofshopware/froshprofiler/blob/main/Resources/config.xml"
    click ServicesXML "https://github.com/friendsofshopware/froshprofiler/blob/main/Resources/services.xml"
    click CollectorsXML "https://github.com/friendsofshopware/froshprofiler/blob/main/Resources/services/collectors.xml"
    click LoggerXML "https://github.com/friendsofshopware/froshprofiler/blob/main/Resources/services/logger.xml"
    click VarDumpXML "https://github.com/friendsofshopware/froshprofiler/blob/main/Resources/services/var_dump.xml"
    click BlockAnnotationSub "https://github.com/friendsofshopware/froshprofiler/blob/main/Subscriber/BlockAnnotation.php"
    click CacheSub "https://github.com/friendsofshopware/froshprofiler/blob/main/Subscriber/CacheSubscriber.php"
    click CollectorSub "https://github.com/friendsofshopware/froshprofiler/blob/main/Subscriber/Collector.php"
    click DatabaseProfilerSub "https://github.com/friendsofshopware/froshprofiler/blob/main/Subscriber/DatabaseProfiler.php"
    click JavascriptSub "https://github.com/friendsofshopware/froshprofiler/blob/main/Subscriber/JavascriptSubscriber.php"
    click ProfilerControllerSub "https://github.com/friendsofshopware/froshprofiler/blob/main/Subscriber/ProfilerController.php"
    click SmartyProfilerSub "https://github.com/friendsofshopware/froshprofiler/blob/main/Subscriber/SmartyProfiler.php"
    click VarDumpCollectorSub "https://github.com/friendsofshopware/froshprofiler/blob/main/Subscriber/VarDumpCollectorSubscriber.php"
    click VarDumpServerSub "https://github.com/friendsofshopware/froshprofiler/blob/main/Subscriber/VarDumpServerSubscriber.php"
    click Collector "https://github.com/friendsofshopware/froshprofiler/blob/main/Components/Collector.php"
    click DBCollector "https://github.com/friendsofshopware/froshprofiler/blob/main/Components/Collectors/DBCollector.php"
    click CacheCollector "https://github.com/friendsofshopware/froshprofiler/blob/main/Components/Collectors/CacheCollector.php"
    click EventCollector "https://github.com/friendsofshopware/froshprofiler/blob/main/Components/Collectors/EventCollector.php"
    click Logger "https://github.com/friendsofshopware/froshprofiler/blob/main/Components/Logger.php"
    click CacheFactory "https://github.com/friendsofshopware/froshprofiler/blob/main/Components/Cache/CacheFactory.php"
    click BlockAnnotatorComp "https://github.com/friendsofshopware/froshprofiler/blob/main/Components/BlockAnnotation/BlockAnnotator.php"
    click EventManager "https://github.com/friendsofshopware/froshprofiler/blob/main/Components/Event/EventManager.php"
    click ClonerFactory "https://github.com/friendsofshopware/froshprofiler/blob/main/Components/VarDumper/ClonerFactory.php"
    click RequestContextProvider "https://github.com/friendsofshopware/froshprofiler/blob/main/Components/VarDumper/RequestContextProvider.php"
    click VarDumperCaster "https://github.com/friendsofshopware/froshprofiler/blob/main/Components/VarDumper/VarDumperCaster.php"
    click TraceableGenerator "https://github.com/friendsofshopware/froshprofiler/blob/main/Components/Tracleable/TraceableGenerator.php"
    click FrontendProfilerController "https://github.com/friendsofshopware/froshprofiler/blob/main/Controller/Frontend/Profiler.php"
    click ProfileEntity "https://github.com/friendsofshopware/froshprofiler/blob/main/Models/Profile.php"
    click CompilerFetch "https://github.com/friendsofshopware/froshprofiler/blob/main/Resources/smarty/compiler.fetchFile.php"
    click ModifierConvert "https://github.com/friendsofshopware/froshprofiler/blob/main/Resources/smarty/modifier.convertMemory.php"
    click ModifierDump "https://github.com/friendsofshopware/froshprofiler/blob/main/Resources/smarty/modifier.dump.php"
    click ModifierSQL "https://github.com/friendsofshopware/froshprofiler/blob/main/Resources/smarty/modifier.sqlFormat.php"
    click ToolbarViews "https://github.com/friendsofshopware/froshprofiler/blob/main/Resources/views/@Toolbar/index.tpl"
    click ProfilerFEViews "https://github.com/friendsofshopware/froshprofiler/blob/main/Resources/views/frontend/profiler/index.tpl"
    click BackendUIViews "https://github.com/friendsofshopware/froshprofiler/blob/main/Resources/views/backend/FroshProfiler/performance/view/*.tpl"

    %% Styles
    classDef plugin fill:#e0f7e9,stroke:#2d9c63,color:#000
    classDef core fill:#ebf5fb,stroke:#2980b9,color:#000
    classDef client fill:#fdebd0,stroke:#d35400,color:#000
    classDef db fill:#d5dbdb,stroke:#7f8c8d,color:#000
    classDef external fill:#fdebd0,stroke:#d35400,color:#000
    classDef config fill:#f4ecf7,stroke:#8e44ad,color:#000
    classDef view fill:#fcf3cf,stroke:#b7950b,color:#000
```
