---
title: Development Best Practices | Shopware Community Hub
description: >-
  Internalize the core development best practices for Shopware, including code
  structure, customization principles, and tools for maintaining high-quality,…
canonical_url: >-
  https://hub.shopware.com/learn/unit/solutions-architect-development-best-practices
---

# Development Best Practices

<LearningObjectives>

- Understand **core development best practices** for Shopware.
- Recognize **coding and customization principles** that lead to scalable, maintainable solutions.
- Identify **tools and techniques** for spotting and avoiding common development pitfalls.
- Make recommendations to ensure **code quality, performance, and security**.

</LearningObjectives>

# Introduction to Development Best Practices

This guide provides best practices for developing in Shopware, ensuring that solutions are reliable, scalable, and maintainable. Solutions Architects can use these guidelines to help spot potential bad practices, make informed recommendations, and evaluate the quality of Shopware customizations.

## 1. Code Structure and Readability

Good code structure and readability make development and maintenance easier. Organized code ensures updates are manageable and helps future developers understand the code.

### Recommendations

- **Use the Decorator Pattern**: The decorator pattern allows developers to add functionality without changing the core code, keeping it stable.
    - **Spotting Issues**: If you see functions added directly to core code files, this is a sign that the decorator pattern isn’t being used. Refactoring is recommended to avoid changes to the core.  
      More about decorator pattern in Shopware: [Decorator pattern](https://developer.shopware.com/docs/resources/guidelines/code/core/decorator-pattern.html).
- **Use Final Classes Where Possible**: Final classes prevent unintended inheritance, keeping code more predictable and avoiding unexpected issues.
    - **Spotting Issues**: Classes marked as `final` should be clearly documented. If developers skip marking classes as final, it could indicate they’re leaving the code open to unintended extensions.
- **Document Code with Clear Naming Conventions**: Properly named classes, methods, and variables improve readability. Use inline comments to explain complex sections.
    - **Spotting Issues**: Look for unclear abbreviations in names or missing PHPDoc annotations. These can make the code harder to maintain. A function's name should explain what it does.

### Tools

- **PHPStan** can highlight inconsistent naming conventions or improper code structure. Shopware comes prepackaged [PHPStan parameters](https://github.com/shopware/shopware/blob/trunk/phpstan.neon.dist).
- **PHP_CodeSniffer** is an open source tool that can detect and fix code not adhering to code standards. Shopware comes with [a ruleset](https://github.com/shopware/shopware/blob/trunk/.php-cs-fixer.dist.php) which can be used to apply fixes.
- **SonarQube** is a paid, proprietary solution adapted to analyzing code for its quality.

## 2. Customization Principles

Shopware offers various ways to extend functionality. Following best practices ensures that customizations are maintainable and less likely to conflict with updates.

### Recommendations

- **Plugins vs. Apps**: Use plugins for more integrated customizations, especially those that interact with the core, and apps for simpler, modular enhancements that minimize conflicts.
    - **Spotting Issues**: If customizations require core file changes or lead to frequent issues after updates, it might indicate that plugins or apps were not used properly.
- **Use Shopware Blocks for Template Customization**: Shopware blocks allow template modifications without breaking core functionality.
    - **Spotting Issues**: Direct template modifications outside of Shopware blocks can indicate poor practice. Recommend restructuring to use blocks for safe template overrides.
- **Tools**: **PhpStorm** has a Shopware plugin to guide developers on safe modification points, highlighting blocks and other structural elements.

## 3. Performance Optimization

Performance optimization ensures a smooth user experience and supports scalability.

### Recommendations

- **Reduce HTTP Requests**: Minimize the number of CSS and JavaScript files loaded on each page by combining files where possible.
    - **Spotting Issues**: If each page makes a large number of separate requests, it can signal unoptimized file management. Recommend combining and minimizing files.
- **Caching and Image Optimization**: Leverage Shopware’s built-in caching and use optimized images in modern formats like WebP. Consider a CDN for further optimization.
    - **Spotting Issues**: Check for large, uncompressed images in the theme. This can indicate poor optimization. Recommend converting images and using Shopware’s image handling features.
- **Reduction of Queries**: As with many applications a large amount of queries, especially with a slow execution time, can lead to poor performance.
    - **Spotting Issues**: Use the integrated [Symfony Profiler](https://symfony.com/doc/current/profiler.html) to analyze database queries with long execution times, no indexes, or large `SELECT` statements.

### Tools

- **Google Lighthouse** is helpful in identifying excessive requests and file sizes and providing specific recommendations on optimizing load times.

- **PHP Bench** is an open source tool used to run performance benchmarks. Shopware offers [presets](https://github.com/shopware/shopware/blob/trunk/phpbench.json) in its source code.

#### Profilers

- **Tideways** is a powerful APM (Application Performance Monitoring) tool that provides detailed insights into PHP application performance.

- **Blackfire** offers deep performance profiling capabilities, allowing developers to analyze memory usage, CPU time, and I/O operations to identify and fix performance issues.

- **Datadog** provides comprehensive application performance monitoring with distributed tracing, real-time metrics, and log management, helping teams identify and resolve performance issues across their entire stack.

## 4. Testing and Quality Assurance

Quality assurance is critical to ensuring that code performs as expected across all scenarios.

### Recommendations

- **Unit Testing**: Unit testing should cover both custom project code and third-party extensions that add or augment business logic in any extensive way.
    - **Spotting Issues**: If the project has little or no unit tests, especially for critical functions, recommend increasing test coverage.
- **End-to-End (E2E) Testing**: Shopware offers a [Cypress-based E2E testing suite](https://github.com/shopwareArchive/e2e-testsuite-platform). While this covers basic functionality that comes with Shopware, this should be extended with project-specific functionality.
    - **Spotting Issues**: If user interactions are frequently breaking, it could indicate a lack of comprehensive E2E testing.

## 5. Security Best Practices

Security is essential, especially with the involvement of customer data and payment processes.

### Recommendations

- **Avoid Hardcoding Sensitive Information**: API keys, passwords, and tokens should be stored securely and never hardcoded.
    - **Spotting Issues**: Review the codebase for sensitive information hardcoded into files. Recommend using environment variables for secure storage.
- **Data Validation and Sanitization**: Validate and sanitize all user input to prevent attacks like SQL injection.
    - **Spotting Issues**: If user input handling appears overly simplistic or lacks validation, it could be a security risk. Suggest implementing validation practices.
- **GDPR Compliance**: Follow GDPR guidelines, especially for data retention and user consent.
    - **Spotting Issues**: Customer data stored indefinitely without retention policies might indicate non-compliance. Recommend reviewing data handling policies.

### Tools

- **Stay informed**: familiarize yourself with [Shopware Security recommendations](https://docs.shopware.com/en/shopware-6-en/tutorials-and-faq/security-measures).
- **Sansec**: Leverage Sansec to continuously scan servers for malware.
- **Shopware Security Plugin**: Install and keep up to date the [Shopware Security Plugin](https://store.shopware.com/en/swag136939272659f/shopware-6-security-plugin.html) in any Shopware webshop.

## 6. Backward Compatibility and Stability

Maintaining backward compatibility ensures that updates don’t break existing functionality, reducing maintenance time.

### Recommendations

- **Use Public APIs Only**: Only use stable, public APIs that Shopware supports to ensure that updates do not break functionalities.
    - **Spotting Issues**: If the code relies on private or undocumented APIs, it’s a red flag for stability. Recommend refactoring to use public APIs.
- **Avoid Breaking Changes**: Discourage renaming or deleting methods or classes without fallback mechanisms.
    - **Spotting Issues**: Frequent issues during updates might indicate breaking changes in custom code. For better change management, I suggest reviewing update logs.

## 7. Leveraging No-Code Solutions for Simple Requirements

For common, simple customizations, using Shopware’s built-in no-code solutions (Flow Builder, Rule Builder, Shopping Experiences) can save time and reduce technical debt.

### Recommendations

- **Use No-Code Tools Before Custom Code**: Many requirements like dynamic pricing or simple workflows can be achieved with Rule Builder or Flow Builder, reducing the need for custom code.
    - **Spotting Issues**: If custom code is being used for workflows that could be achieved with Flow Builder or Rule Builder, this could lead to unnecessary complexity. Recommend reviewing built-in tools before opting for development.

## Conclusion

Following best practices in Shopware development ensures the codebase remains stable, secure, and scalable. Solutions Architects can use this guide to help identify areas for improvement, make informed recommendations to development teams, and ensure that solutions align with Shopware’s quality standards.
