How friendsofshopware/froshprofiler works
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