Shopware 6 Best Practices
Comprehensive best practices guide for Shopware 6.6+ development, designed for AI agents and LLMs helping agency developers. Contains 77 rules across 22 categories, prioritized by impact to guide automated refactoring and code generation.
When to Apply
Reference these guidelines when:
- Developing custom Shopware 6 plugins
- Creating or modifying Store API or Admin API endpoints
- Working with the Data Abstraction Layer (DAL)
- Implementing event subscribers and decorators
- Configuring message queue handlers
- Writing database migrations
- Optimizing performance (caching, Elasticsearch)
- Implementing security measures
- Writing unit and integration tests
- Customizing storefront templates and JavaScript
- Building administration modules and components
- Creating Shopware apps with webhooks and actions
- Implementing payment or shipping integrations
- Building CMS elements and blocks
- Creating CLI commands for automation
- Setting up multi-channel or B2B shops
- Configuring development environments and CI/CD
Rule Categories by Priority
| Priority |
Category |
Impact |
Prefix |
| 1 |
Plugin Architecture |
CRITICAL |
plugin- |
| 2 |
Customization & Extension |
CRITICAL |
custom- |
| 3 |
Performance & Caching |
CRITICAL |
perf- |
| 4 |
Security |
CRITICAL |
security- |
| 5 |
Data Abstraction Layer |
HIGH |
dal- |
| 6 |
API Development |
HIGH |
api- |
| 7 |
Testing |
HIGH |
test- |
| 8 |
Event System |
MEDIUM-HIGH |
event- |
| 9 |
Database & Migrations |
MEDIUM-HIGH |
db- |
| 10 |
Message Queue |
MEDIUM |
queue- |
| 11 |
Dependency Injection |
MEDIUM |
di- |
| 12 |
Logging |
MEDIUM |
logging- |
| 13 |
Configuration |
MEDIUM |
config- |
| 14 |
Scheduled Tasks |
MEDIUM |
scheduled- |
| 15 |
Storefront Development |
HIGH |
storefront- |
| 16 |
Administration Development |
HIGH |
admin- |
| 17 |
App System |
HIGH |
app- |
| 18 |
Integration Patterns |
HIGH |
integration- |
| 19 |
CLI Commands |
MEDIUM |
cli- |
| 20 |
Multi-Channel & B2B |
MEDIUM-HIGH |
multichannel- |
| 21 |
DevOps & Tooling |
MEDIUM |
devops- |
| 22 |
Common Patterns |
HIGH |
pattern- |
Quick Reference
1. Plugin Architecture (CRITICAL)
plugin-structure - Follow proper plugin directory structure and composer.json
plugin-services - Register services correctly with proper tags
2. Customization & Extension (CRITICAL)
custom-decorator-pattern - Use decorator pattern for upgrade-safe service customization
custom-event-subscribers - Implement event subscribers correctly with proper priorities
3. Performance & Caching (CRITICAL)
perf-http-cache - Configure HTTP cache correctly with proper invalidation
perf-dal-optimization - Optimize DAL queries to prevent N+1 problems
perf-elasticsearch - Use Elasticsearch correctly for large catalogs
4. Security (CRITICAL)
security-input-validation - Validate all inputs with RequestDataBag and validators
security-authentication - Implement proper route authentication
security-authorization - Use ACL for permission checks
security-csrf-protection - Implement CSRF protection for storefront
security-sql-injection - Use DAL or parameterized queries
5. Data Abstraction Layer (HIGH)
dal-criteria-usage - Use Criteria objects correctly with filters and pagination
dal-associations - Load associations explicitly to avoid N+1 queries
dal-write-operations - Use batch operations and proper sync patterns
dal-entity-extensions - Extend entities without modifying core
dal-custom-entities - Create custom entity definitions properly
6. API Development (HIGH)
api-store-api-routes - Create decoratable Store API routes
api-admin-api-routes - Create Admin API endpoints with proper ACL
api-response-handling - Handle responses and errors consistently
api-rate-limiting - Configure rate limiting for protection
api-versioning - Version APIs for backwards compatibility
7. Testing (HIGH)
test-unit-tests - Write unit tests with proper mocking
test-integration-tests - Use IntegrationTestBehaviour correctly
test-store-api-tests - Test Store API routes with HTTP tests
test-fixtures - Create reusable test fixtures
8. Event System (MEDIUM-HIGH)
event-business-events - Create Flow Builder compatible events
event-flow-actions - Implement configurable flow actions
9. Database & Migrations (MEDIUM-HIGH)
db-migrations - Implement safe database migrations
10. Message Queue (MEDIUM)
queue-message-handlers - Implement async message handling
queue-worker-config - Configure workers for production
queue-low-priority - Separate low-priority background tasks
11. Dependency Injection (MEDIUM)
di-service-container - Use Symfony DI correctly
12. Logging (MEDIUM)
logging-best-practices - Implement structured logging
13. Configuration (MEDIUM)
config-plugin-settings - Implement plugin configuration correctly
14. Scheduled Tasks (MEDIUM)
scheduled-tasks - Implement reliable scheduled tasks
15. Storefront Development (HIGH)
storefront-controller-pattern - Extend StorefrontController with page loaders
storefront-twig-extension - Template inheritance with sw_extends and blocks
storefront-js-plugins - JavaScript plugin registration and lifecycle
storefront-themes - Theme structure, inheritance, and configuration
storefront-scss-variables - SCSS variables and responsive mixins
storefront-http-client - AJAX requests and Store API calls from JS
16. Administration Development (HIGH)
admin-module-structure - Module registration, routes, and navigation
admin-components - Vue component patterns and templates
admin-data-handling - Repository factory and Criteria API in admin
admin-acl-permissions - ACL-based UI visibility and actions
admin-mixins-composables - Mixins, directives, and extensibility
admin-extension-api - App iframe modules and Extension SDK
17. App System (HIGH)
app-manifest - Complete manifest.xml configuration
app-webhooks - Webhook handling and signature verification
app-custom-actions - Action buttons with notifications, modals, redirects
app-payment-methods - App payment handlers for pay/finalize/capture/refund
app-custom-fields - Custom field definitions via manifest
app-scripts - Twig-based app scripts and hook points
18. Integration Patterns (HIGH)
integration-payment-handler - Sync/async payment handler patterns
integration-shipping-method - Shipping calculators and delivery times
integration-cms-elements - CMS element creation with data resolvers
integration-import-export - Import/export profiles and converters
integration-external-api - HTTP client patterns with retry and caching
19. CLI Commands (MEDIUM)
cli-commands - Custom command creation with arguments and options
cli-command-lifecycle - Configure/initialize/interact/execute lifecycle
cli-progress-output - SymfonyStyle, progress bars, and formatting
20. Multi-Channel & B2B (MEDIUM-HIGH)
multichannel-saleschannel - Sales channel awareness and visibility
multichannel-b2b-patterns - Company handling, roles, and budgets
multichannel-pricing - Currency, customer groups, and tax handling
multichannel-context - Context types, scopes, and permissions
21. DevOps & Tooling (MEDIUM)
devops-development-setup - Dockware, docker-compose, Makefile patterns
devops-deployment - Deployment scripts, builds, and rollbacks
devops-static-analysis - PHPStan, PHP-CS-Fixer, Rector configuration
devops-debugging - Profiler, Xdebug, logging, and data collectors
devops-ci-cd - GitHub Actions and GitLab CI workflows
22. Common Patterns (HIGH)
pattern-error-handling - Custom exceptions and error pages
pattern-translations - Snippets and entity translations
pattern-media-handling - Media service, uploads, and thumbnails
pattern-rule-builder - Custom rule conditions for pricing/shipping
pattern-upgrade-migration - Version-aware code and update migrations
Core Principles
The Decorator Pattern is Key
Never modify core files. Always use:
- Decorators for services
- Event subscribers for hooks
- Entity extensions for data
DAL Over Raw SQL
Use Shopware's Data Abstraction Layer instead of raw SQL:
- Type safety and validation
- Automatic association handling
- Built-in versioning and translation
Performance First
Shopware can be slow if misused:
- Enable HTTP cache in production
- Use Elasticsearch for 10K+ products
- Load only needed associations
- Use message queue for heavy tasks
How to Use
Read individual rule files for detailed explanations and code examples:
rules/plugin-structure.md
rules/custom-decorator-pattern.md
rules/perf-http-cache.md
rules/security-input-validation.md
rules/dal-criteria-usage.md
Each rule file contains:
- Brief explanation of why it matters
- Incorrect code example with explanation
- Correct code example with explanation
- Additional context and references
Full Compiled Document
For the complete guide with all rules expanded: AGENTS.md
1---2name: shopware6-best-practices3description: Comprehensive Shopware 6.6+ development best practices for agency developers. Covers backend PHP, storefront Twig/JS, administration Vue.js, app system, integrations, CLI, multi-channel, and DevOps. Triggers on tasks involving plugin development, storefront customization, admin modules, app creation, payment/shipping integrations, or deployment.4license: MIT5---6
7# Shopware 6 Best Practices
8
9Comprehensive best practices guide for Shopware 6.6+ development, designed for AI agents and LLMs helping agency developers. Contains 77 rules across 22 categories, prioritized by impact to guide automated refactoring and code generation.
10
11## When to Apply
12
13Reference these guidelines when:
14- Developing custom Shopware 6 plugins
15- Creating or modifying Store API or Admin API endpoints
16- Working with the Data Abstraction Layer (DAL)
17- Implementing event subscribers and decorators
18- Configuring message queue handlers
19- Writing database migrations
20- Optimizing performance (caching, Elasticsearch)
21- Implementing security measures
22- Writing unit and integration tests
23- Customizing storefront templates and JavaScript
24- Building administration modules and components
25- Creating Shopware apps with webhooks and actions
26- Implementing payment or shipping integrations
27- Building CMS elements and blocks
28- Creating CLI commands for automation
29- Setting up multi-channel or B2B shops
30- Configuring development environments and CI/CD
31
32## Rule Categories by Priority
33
34| Priority | Category | Impact | Prefix |
35|----------|----------|--------|--------|
36| 1 | Plugin Architecture | CRITICAL | `plugin-` |
37| 2 | Customization & Extension | CRITICAL | `custom-` |
38| 3 | Performance & Caching | CRITICAL | `perf-` |
39| 4 | Security | CRITICAL | `security-` |
40| 5 | Data Abstraction Layer | HIGH | `dal-` |
41| 6 | API Development | HIGH | `api-` |
42| 7 | Testing | HIGH | `test-` |
43| 8 | Event System | MEDIUM-HIGH | `event-` |
44| 9 | Database & Migrations | MEDIUM-HIGH | `db-` |
45| 10 | Message Queue | MEDIUM | `queue-` |
46| 11 | Dependency Injection | MEDIUM | `di-` |
47| 12 | Logging | MEDIUM | `logging-` |
48| 13 | Configuration | MEDIUM | `config-` |
49| 14 | Scheduled Tasks | MEDIUM | `scheduled-` |
50| 15 | Storefront Development | HIGH | `storefront-` |
51| 16 | Administration Development | HIGH | `admin-` |
52| 17 | App System | HIGH | `app-` |
53| 18 | Integration Patterns | HIGH | `integration-` |
54| 19 | CLI Commands | MEDIUM | `cli-` |
55| 20 | Multi-Channel & B2B | MEDIUM-HIGH | `multichannel-` |
56| 21 | DevOps & Tooling | MEDIUM | `devops-` |
57| 22 | Common Patterns | HIGH | `pattern-` |
58
59## Quick Reference
60
61### 1. Plugin Architecture (CRITICAL)
62
63- `plugin-structure` - Follow proper plugin directory structure and composer.json
64- `plugin-services` - Register services correctly with proper tags
65
66### 2. Customization & Extension (CRITICAL)
67
68- `custom-decorator-pattern` - Use decorator pattern for upgrade-safe service customization
69- `custom-event-subscribers` - Implement event subscribers correctly with proper priorities
70
71### 3. Performance & Caching (CRITICAL)
72
73- `perf-http-cache` - Configure HTTP cache correctly with proper invalidation
74- `perf-dal-optimization` - Optimize DAL queries to prevent N+1 problems
75- `perf-elasticsearch` - Use Elasticsearch correctly for large catalogs
76
77### 4. Security (CRITICAL)
78
79- `security-input-validation` - Validate all inputs with RequestDataBag and validators
80- `security-authentication` - Implement proper route authentication
81- `security-authorization` - Use ACL for permission checks
82- `security-csrf-protection` - Implement CSRF protection for storefront
83- `security-sql-injection` - Use DAL or parameterized queries
84
85### 5. Data Abstraction Layer (HIGH)
86
87- `dal-criteria-usage` - Use Criteria objects correctly with filters and pagination
88- `dal-associations` - Load associations explicitly to avoid N+1 queries
89- `dal-write-operations` - Use batch operations and proper sync patterns
90- `dal-entity-extensions` - Extend entities without modifying core
91- `dal-custom-entities` - Create custom entity definitions properly
92
93### 6. API Development (HIGH)
94
95- `api-store-api-routes` - Create decoratable Store API routes
96- `api-admin-api-routes` - Create Admin API endpoints with proper ACL
97- `api-response-handling` - Handle responses and errors consistently
98- `api-rate-limiting` - Configure rate limiting for protection
99- `api-versioning` - Version APIs for backwards compatibility
100
101### 7. Testing (HIGH)
102
103- `test-unit-tests` - Write unit tests with proper mocking
104- `test-integration-tests` - Use IntegrationTestBehaviour correctly
105- `test-store-api-tests` - Test Store API routes with HTTP tests
106- `test-fixtures` - Create reusable test fixtures
107
108### 8. Event System (MEDIUM-HIGH)
109
110- `event-business-events` - Create Flow Builder compatible events
111- `event-flow-actions` - Implement configurable flow actions
112
113### 9. Database & Migrations (MEDIUM-HIGH)
114
115- `db-migrations` - Implement safe database migrations
116
117### 10. Message Queue (MEDIUM)
118
119- `queue-message-handlers` - Implement async message handling
120- `queue-worker-config` - Configure workers for production
121- `queue-low-priority` - Separate low-priority background tasks
122
123### 11. Dependency Injection (MEDIUM)
124
125- `di-service-container` - Use Symfony DI correctly
126
127### 12. Logging (MEDIUM)
128
129- `logging-best-practices` - Implement structured logging
130
131### 13. Configuration (MEDIUM)
132
133- `config-plugin-settings` - Implement plugin configuration correctly
134
135### 14. Scheduled Tasks (MEDIUM)
136
137- `scheduled-tasks` - Implement reliable scheduled tasks
138
139### 15. Storefront Development (HIGH)
140
141- `storefront-controller-pattern` - Extend StorefrontController with page loaders
142- `storefront-twig-extension` - Template inheritance with sw_extends and blocks
143- `storefront-js-plugins` - JavaScript plugin registration and lifecycle
144- `storefront-themes` - Theme structure, inheritance, and configuration
145- `storefront-scss-variables` - SCSS variables and responsive mixins
146- `storefront-http-client` - AJAX requests and Store API calls from JS
147
148### 16. Administration Development (HIGH)
149
150- `admin-module-structure` - Module registration, routes, and navigation
151- `admin-components` - Vue component patterns and templates
152- `admin-data-handling` - Repository factory and Criteria API in admin
153- `admin-acl-permissions` - ACL-based UI visibility and actions
154- `admin-mixins-composables` - Mixins, directives, and extensibility
155- `admin-extension-api` - App iframe modules and Extension SDK
156
157### 17. App System (HIGH)
158
159- `app-manifest` - Complete manifest.xml configuration
160- `app-webhooks` - Webhook handling and signature verification
161- `app-custom-actions` - Action buttons with notifications, modals, redirects
162- `app-payment-methods` - App payment handlers for pay/finalize/capture/refund
163- `app-custom-fields` - Custom field definitions via manifest
164- `app-scripts` - Twig-based app scripts and hook points
165
166### 18. Integration Patterns (HIGH)
167
168- `integration-payment-handler` - Sync/async payment handler patterns
169- `integration-shipping-method` - Shipping calculators and delivery times
170- `integration-cms-elements` - CMS element creation with data resolvers
171- `integration-import-export` - Import/export profiles and converters
172- `integration-external-api` - HTTP client patterns with retry and caching
173
174### 19. CLI Commands (MEDIUM)
175
176- `cli-commands` - Custom command creation with arguments and options
177- `cli-command-lifecycle` - Configure/initialize/interact/execute lifecycle
178- `cli-progress-output` - SymfonyStyle, progress bars, and formatting
179
180### 20. Multi-Channel & B2B (MEDIUM-HIGH)
181
182- `multichannel-saleschannel` - Sales channel awareness and visibility
183- `multichannel-b2b-patterns` - Company handling, roles, and budgets
184- `multichannel-pricing` - Currency, customer groups, and tax handling
185- `multichannel-context` - Context types, scopes, and permissions
186
187### 21. DevOps & Tooling (MEDIUM)
188
189- `devops-development-setup` - Dockware, docker-compose, Makefile patterns
190- `devops-deployment` - Deployment scripts, builds, and rollbacks
191- `devops-static-analysis` - PHPStan, PHP-CS-Fixer, Rector configuration
192- `devops-debugging` - Profiler, Xdebug, logging, and data collectors
193- `devops-ci-cd` - GitHub Actions and GitLab CI workflows
194
195### 22. Common Patterns (HIGH)
196
197- `pattern-error-handling` - Custom exceptions and error pages
198- `pattern-translations` - Snippets and entity translations
199- `pattern-media-handling` - Media service, uploads, and thumbnails
200- `pattern-rule-builder` - Custom rule conditions for pricing/shipping
201- `pattern-upgrade-migration` - Version-aware code and update migrations
202
203## Core Principles
204
205### The Decorator Pattern is Key
206
207Never modify core files. Always use:
208- **Decorators** for services
209- **Event subscribers** for hooks
210- **Entity extensions** for data
211
212### DAL Over Raw SQL
213
214Use Shopware's Data Abstraction Layer instead of raw SQL:
215- Type safety and validation
216- Automatic association handling
217- Built-in versioning and translation
218
219### Performance First
220
221Shopware can be slow if misused:
222- Enable HTTP cache in production
223- Use Elasticsearch for 10K+ products
224- Load only needed associations
225- Use message queue for heavy tasks
226
227## How to Use
228
229Read individual rule files for detailed explanations and code examples:
230
231```
232rules/plugin-structure.md
233rules/custom-decorator-pattern.md
234rules/perf-http-cache.md
235rules/security-input-validation.md
236rules/dal-criteria-usage.md
237```
238
239Each rule file contains:
240- Brief explanation of why it matters
241- Incorrect code example with explanation
242- Correct code example with explanation
243- Additional context and references
244
245## Full Compiled Document
246
247For the complete guide with all rules expanded: `AGENTS.md`