$30 off During Our Annual Pro Sale. View Details »

Meine ehrliche Symfony-Anwendung

Meine ehrliche Symfony-Anwendung

Du hast die letzten Jahre bei verschiedenen Talks viel über Architektur, Testing, Komponenten und Pattern gehört. Natürlich hast du auch viel über Symfony gelernt und die Buzzwords sind in Schwärmen an dir vorbei in ferne Länder gezogen. Aber was bleibt übrig, wenn man wieder im Büro ohne Hypes und gestylte Slides eine Symfony-Anwendung hochziehen muss? Über die letzten Jahre habe ich viele Projekte und Teams kennengelernt und unterschiedlichste Ansätze, Probleme und Lösungen gesehen. In diesem Talk will ich euch meinen Weg Symfony-Anwendungen zu bauen zeigen. Es wird leider nicht so shiny und fancy, sondern realistisch und pragmatisch. Nehmt die Sonnenbrille ab und holt den Notizblock raus.

Christopher Hertel

September 26, 2019
Tweet

More Decks by Christopher Hertel

Other Decks in Programming

Transcript

  1. @el_stoffel
    SymfonyLive Berlin 2019
    Meine ehrliche
    Symfony Anwendung

    View Slide

  2. @el_stoffel
    SymfonyLive Berlin 2019
    Was bedeutet
    "ehrliche Anwendung"?
    Realismus
    Hype-Driven-Development
    Komplexität
    Pragmatismus
    Flexibilität
    Stabilität
    Wartbarkeit
    vermeiden
    maßvolle

    View Slide

  3. @el_stoffel
    SymfonyLive Berlin 2019
    Wer bin ich?

    View Slide

  4. @el_stoffel
    SymfonyLive Berlin 2019
    Christopher Hertel
    Consultant & Trainer @ SensioLabs in Berlin
    Symfony & Twig Certified Developer
    iSAQB Certified Software Architect
    @el_stoffel
    Symfony User Group Berlin

    View Slide

  5. @el_stoffel
    SymfonyLive Berlin 2019
    • 4 Jahre
    • 10 PHP-/Symfony-Projekte
    • 800.000 LLOC
    • 40 Trainings & Workshops
    • 75 + 300 Entwickler*innen

    View Slide

  6. @el_stoffel
    SymfonyLive Berlin 2019
    Konzept
    Umsetzung
    Prozess
    Team
    Software
    Entwicklung
    Software Architektur
    Workshops
    OOP & Clean Code
    Best Practices
    Pair Programming
    Testing
    Dokumentation
    Code Review
    Trainings
    Wissenstransfer
    Continuous
    Deployment
    Turnover
    Onboarding

    View Slide

  7. @el_stoffel
    SymfonyLive Berlin 2019
    Was bedeutet
    "ehrliche Anwendung"?
    Realismus
    Hype-Driven-Development
    Komplexität
    Pragmatismus
    Flexibilität
    Stabilität
    Wartbarkeit
    vermeiden
    maßvolle

    View Slide

  8. @el_stoffel
    SymfonyLive Berlin 2019
    Agenda
    • Struktur der Anwendung
    • Software Architektur
    • Testing
    • Prozess
    Typische Fallstricke
    Best Practices

    View Slide

  9. @el_stoffel
    SymfonyLive Berlin 2019
    Struktur der Anwendung

    View Slide

  10. @el_stoffel
    SymfonyLive Berlin 2019
    Konzept
    Umsetzung
    Prozess
    Team
    Software
    Entwicklung
    Software Architektur
    Workshops
    OOP & Clean Code
    Best Practices
    Pair Programming
    Testing
    Dokumentation
    Code Review
    Trainings
    Wissenstransfer
    Continuous
    Deployment
    Turnover
    Onboarding

    View Slide

  11. @el_stoffel
    SymfonyLive Berlin 2019
    Struktur der Anwendung
    $ git clone ...
    Repositories

    View Slide

  12. @el_stoffel
    SymfonyLive Berlin 2019
    Struktur der Anwendung
    application
    docker
    project
    Repository
    Repository
    Repositories

    View Slide

  13. @el_stoffel
    SymfonyLive Berlin 2019
    Struktur der Anwendung
    application
    docker
    lib-x
    lib-y
    project
    Repository
    Repository
    Repository
    Repository
    Repositories

    View Slide

  14. @el_stoffel
    SymfonyLive Berlin 2019
    Struktur der Anwendung
    application
    docker
    lib-x
    lib-y
    project Repository
    Go Monorepo.org
    Repositories

    View Slide

  15. @el_stoffel
    SymfonyLive Berlin 2019
    Struktur der Anwendung
    • Versionierung & Autorisierung
    • keine Trennung von Anwendungsteilen
    • vermeidet Git-Puzzles
    • Go Monorepo
    Developer Experience
    Repositories

    View Slide

  16. @el_stoffel
    SymfonyLive Berlin 2019
    Struktur der Anwendung
    $ bin/console generate:bundle
    DEPRECATED
    Bundles

    View Slide

  17. @el_stoffel
    SymfonyLive Berlin 2019
    Struktur der Anwendung
    ApiBundle
    CoreBundle
    ExportBundle
    InfrastructureBundle
    src
    PaymentBundle
    • Symfony Extension Point
    • keine Domain-Trennung
    benutzt Namespaces
    Go Mono-Bundle
    oder Bundleless
    Bundles

    View Slide

  18. @el_stoffel
    SymfonyLive Berlin 2019
    Struktur der Anwendung
    ApiBundle
    CoreBundle
    ExportBundle
    InfrastructureBundle
    src
    PaymentBundle
    CoreBundle
    Api
    Export
    Infrastructure
    src
    Payment
    ApiBundle
    CoreBundle
    ExportBundle
    InfrastructureBundle
    PaymentBundle
    Bundles
    Mono-Bundle

    View Slide

  19. @el_stoffel
    SymfonyLive Berlin 2019
    Struktur der Anwendung
    ApiBundle
    CoreBundle
    ExportBundle
    InfrastructureBundle
    src
    PaymentBundle
    Api
    Export
    Infrastructure
    src
    Payment
    ApiBundle
    CoreBundle
    ExportBundle
    InfrastructureBundle
    PaymentBundle Kernel.php
    Bundles
    Bundleless

    View Slide

  20. @el_stoffel
    SymfonyLive Berlin 2019
    Struktur der Anwendung
    ApiBundle
    CoreBundle
    ExportBundle
    InfrastructureBundle
    src
    PaymentBundle
    Command
    Export
    Controller
    src
    Api

    Bundles
    Controller & Commands

    View Slide

  21. @el_stoffel
    SymfonyLive Berlin 2019
    Struktur der Anwendung
    namespace App;
    Namespaces

    View Slide

  22. @el_stoffel
    SymfonyLive Berlin 2019
    Struktur der Anwendung
    Namespaces
    src
    Command
    Controller
    Entity
    Form
    Helper
    Service
    Twig
    Utils
    Symfony
    Acme Service
    CartService.php
    ImportService.php
    ProductService.php
    UserService.php
    10K LLOC

    View Slide

  23. @el_stoffel
    SymfonyLive Berlin 2019
    Struktur der Anwendung
    Namespaces
    src
    Command
    Controller
    Entity
    Form
    Helper
    Service
    Twig
    Utils
    Symfony
    Acme
    Service
    CartService.php
    ImportService.php
    ProductService.php
    UserService.php

    View Slide

  24. @el_stoffel
    SymfonyLive Berlin 2019
    Struktur der Anwendung
    Namespaces
    src
    Command
    Controller
    Entity
    Form
    Helper
    Service
    Twig
    Utils
    Symfony
    Acme
    Service
    User
    Product
    Import
    Cart

    View Slide

  25. @el_stoffel
    SymfonyLive Berlin 2019
    Struktur der Anwendung
    Namespaces
    src
    Command
    Controller
    Entity
    Form
    Helper
    Service
    Twig
    Utils
    Symfony
    Acme
    Service
    User
    Factory.php
    Registration.php
    Removal.php
    Product
    Import
    Cart

    View Slide

  26. @el_stoffel
    SymfonyLive Berlin 2019
    Struktur der Anwendung
    Namespaces
    src
    Command
    Controller
    Domain
    Entity
    Form
    Helper
    Twig
    Utils
    Symfony
    Acme
    Domain
    User
    Factory.php
    Registration.php
    Removal.php
    Product
    Import
    Cart

    View Slide

  27. @el_stoffel
    SymfonyLive Berlin 2019
    Struktur der Anwendung
    • prominente Symfony Namespaces 1st-Level
    • splittet mächtige Service-Klassen
    • vermeidet generische strukturelle Namespaces
    Namespaces
    bessere Wartbarkeit
    bessere Orientierung

    View Slide

  28. @el_stoffel
    SymfonyLive Berlin 2019
    Software Architektur

    View Slide

  29. @el_stoffel
    SymfonyLive Berlin 2019
    Konzept
    Umsetzung
    Prozess
    Team
    Software
    Entwicklung
    Software Architektur
    Workshops
    OOP & Clean Code
    Best Practices
    Pair Programming
    Testing
    Dokumentation
    Code Review
    Trainings
    Wissenstransfer
    Continuous
    Deployment
    Turnover
    Onboarding

    View Slide

  30. @el_stoffel
    SymfonyLive Berlin 2019
    OLTP vs. OLAP
    Software Architektur

    View Slide

  31. @el_stoffel
    SymfonyLive Berlin 2019
    Software Architektur
    • Online Transactional Processing
    • abgeschlossene kleine Transaktionen
    • Transaktion / Request
    • viele Requests & viele Nutzer
    OLTP
    Häufiger Usecase bei Webseiten

    View Slide

  32. @el_stoffel
    SymfonyLive Berlin 2019
    Software Architektur
    • Online Analytical Processing
    • aufwändigere Queries über viele Datensätze
    • Reporting
    • wenige Nutzer
    OLAP
    Meistens nachgelagert

    View Slide

  33. @el_stoffel
    SymfonyLive Berlin 2019
    OLTP
    Software Architektur

    View Slide

  34. @el_stoffel
    SymfonyLive Berlin 2019
    Transaktionen
    Software Architektur

    View Slide

  35. @el_stoffel
    SymfonyLive Berlin 2019
    Use Cases
    Software Architektur

    View Slide

  36. @el_stoffel
    SymfonyLive Berlin 2019
    HTTP-Request
    View
    Controller
    Model
    Software Architektur

    View Slide

  37. @el_stoffel
    SymfonyLive Berlin 2019
    HTTP-Request
    View
    Controller
    Model
    Software Architektur

    View Slide

  38. @el_stoffel
    SymfonyLive Berlin 2019
    HTTP-Request
    View
    Controller
    Model
    Software Architektur

    View Slide

  39. @el_stoffel
    SymfonyLive Berlin 2019
    HTTP-Request
    View
    Controller
    Domain
    Use Case
    Entity
    Services
    Services
    Software Architektur

    View Slide

  40. @el_stoffel
    SymfonyLive Berlin 2019
    HTTP-Request
    View
    Controller
    Domain
    Use Case
    Entity
    Services
    Services
    Persistence
    Transaktion
    Software Architektur

    View Slide

  41. @el_stoffel
    SymfonyLive Berlin 2019
    Beispiel
    Checkout Submit
    Software Architektur

    View Slide

  42. @el_stoffel
    SymfonyLive Berlin 2019
    HTTP-Request
    View
    Controller
    Domain
    Use Case
    Entity
    Services
    Services
    Persistence
    Software Architektur

    View Slide

  43. @el_stoffel
    SymfonyLive Berlin 2019
    POST-Request
    Domain Services
    Services
    Persistence
    Controller
    Use Case
    Entity
    Software Architektur

    View Slide

  44. @el_stoffel
    SymfonyLive Berlin 2019
    POST-Request
    CheckoutController::submit
    Domain
    Checkout::submit
    Services
    Services
    Persistence
    Cart Order Confirmation
    Software Architektur

    View Slide

  45. @el_stoffel
    SymfonyLive Berlin 2019
    POST-Request
    CheckoutController::submit
    Domain
    Checkout::submit
    Services
    Services
    Persistence
    Cart Order Confirmation
    Software Architektur

    View Slide

  46. @el_stoffel
    SymfonyLive Berlin 2019
    Software Architektur
    Controller
    OrderCreatedEvent
    SubmitCheckoutHandler
    SubmitCheckoutCommand
    OrderCreatedListener
    ClaimStockCommand
    ClaimStockHandler StockClaimedEvent
    StockClaimedListener
    ChargePaymentCommand
    ChargePaymentHandler …

    View Slide

  47. @el_stoffel
    SymfonyLive Berlin 2019
    Flexibilität vs. Stabilität
    Software Architektur

    View Slide

  48. @el_stoffel
    SymfonyLive Berlin 2019
    Flexibilität vs. Wartbarkeit
    Software Architektur

    View Slide

  49. @el_stoffel
    SymfonyLive Berlin 2019
    Software Architektur
    • 1-zu-1-Kopplung an Controller / Command
    • zentralisiert Ausführung der Operationen
    • Integration-Layer
    • Transaktionssteuerung
    Use Case

    View Slide

  50. @el_stoffel
    SymfonyLive Berlin 2019
    POST-Request
    CheckoutController::submit
    Domain
    Checkout::submit
    Services
    Services
    Persistence
    Cart Order Confirmation
    Software Architektur

    View Slide

  51. @el_stoffel
    SymfonyLive Berlin 2019
    Rich vs. Anemic
    Software Architektur

    View Slide

  52. @el_stoffel
    SymfonyLive Berlin 2019
    Software Architektur
    • Fokus auf strukturierten Daten
    • einfach implementiert oder generiert
    • keine (kaum) Logik
    • potentiell invalide
    Anemic Domain Models

    View Slide

  53. @el_stoffel
    SymfonyLive Berlin 2019
    Software Architektur
    • Fokus auf strukturierten Daten
    • einfach implementiert oder generiert
    • keine (kaum) Logik
    • potentiell invalide
    Anemic Domain Models

    View Slide

  54. @el_stoffel
    SymfonyLive Berlin 2019
    Software Architektur
    • strukturierten Daten und Logik
    • immer valider Zustand
    • definieren State-Transitionen
    • sehr gut testbar
    Rich Domain Models

    View Slide

  55. @el_stoffel
    SymfonyLive Berlin 2019
    Software Architektur
    • strukturierten Daten und Logik
    • immer valider Zustand
    • definieren State-Transitionen
    • sehr gut testbar
    Rich Domain Models

    View Slide

  56. @el_stoffel
    SymfonyLive Berlin 2019
    Testing

    View Slide

  57. @el_stoffel
    SymfonyLive Berlin 2019
    Konzept
    Umsetzung
    Prozess
    Team
    Software
    Entwicklung
    Software Architektur
    Workshops
    OOP & Clean Code
    Best Practices
    Pair Programming
    Testing
    Dokumentation
    Code Review
    Trainings
    Wissenstransfer
    Continuous
    Deployment
    Turnover
    Onboarding

    View Slide

  58. @el_stoffel
    SymfonyLive Berlin 2019
    Testing Pyramide
    Testing

    View Slide

  59. @el_stoffel
    SymfonyLive Berlin 2019
    Testing
    Unit Tests
    Service Tests
    UI
    Tests
    billig & schnell
    langsam & teuer
    Isolation
    Integration

    View Slide

  60. @el_stoffel
    SymfonyLive Berlin 2019
    Testing
    Unit Tests
    Service Tests
    UI
    Tests
    Domain Services
    Services
    Persistence
    Controller
    Use Case
    Entity
    Logik möglichst tief in Domain + Unit Tests

    View Slide

  61. @el_stoffel
    SymfonyLive Berlin 2019
    Testing

    View Slide

  62. @el_stoffel
    SymfonyLive Berlin 2019
    Testing
    BEWARE OF
    THE MOCK

    View Slide

  63. @el_stoffel
    SymfonyLive Berlin 2019
    Prozess

    View Slide

  64. @el_stoffel
    SymfonyLive Berlin 2019
    Konzept
    Umsetzung
    Prozess
    Team
    Software
    Entwicklung
    Software Architektur
    Workshops
    OOP & Clean Code
    Best Practices
    Pair Programming
    Testing
    Dokumentation
    Code Review
    Trainings
    Wissenstransfer
    Continuous
    Deployment
    Turnover
    Onboarding

    View Slide

  65. @el_stoffel
    SymfonyLive Berlin 2019
    Prozess
    Entwicklung
    • Klar definierter Scope
    • Abgestimmte Umsetzung
    • Pair Programming
    • Boy-Scout-Rule

    View Slide

  66. @el_stoffel
    SymfonyLive Berlin 2019
    Prozess
    Entwicklung Pull Request
    • Zuerst selbst reviewen
    • reviewbare PRs – klein oder Commit-Splittung
    • gebt Kontext

    View Slide

  67. @el_stoffel
    SymfonyLive Berlin 2019
    Prozess
    Entwicklung Pull Request Pipeline
    • Linting & Validation
    • Code Style
    • Statische Analysen
    • Tests

    View Slide

  68. @el_stoffel
    SymfonyLive Berlin 2019
    Prozess
    Entwicklung Pull Request Pipeline
    • Linting & Validation
    • Code Style
    • Statische Analysen
    • Tests

    View Slide

  69. @el_stoffel
    SymfonyLive Berlin 2019
    Prozess
    Entwicklung Pull Request Pipeline Review
    • ihr seid ein Team
    • Software-Qualität im Fokus
    • redet drüber
    • lernt voneinander

    View Slide

  70. @el_stoffel
    SymfonyLive Berlin 2019
    Prozess
    Entwicklung Pull Request Pipeline Review
    • schneller Durchfluss muss möglich sein
    • Vorbedingung für Continuous [D|I]
    • Kopplung von Prozess, Produktivität und Frustration

    View Slide

  71. @el_stoffel
    SymfonyLive Berlin 2019
    Recap

    View Slide

  72. @el_stoffel
    SymfonyLive Berlin 2019
    Struktur der Anwendung
    • erkennbare Symfony-Struktur
    • Kapselung der Domain nach Use Cases
    • Logik möglichst tief in Domain-Objekten
    • Unit-Testing der Domain-Objekte
    • Pipeline und Reviews im Entwicklungsprozess
    Recap

    View Slide

  73. @el_stoffel
    SymfonyLive Berlin 2019
    Ende

    View Slide

  74. @el_stoffel
    SymfonyLive Berlin 2019
    Vielen Dank!

    View Slide

  75. @el_stoffel
    SymfonyLive Berlin 2019
    joind.in/talk/387e8

    View Slide

  76. @el_stoffel
    SymfonyLive Berlin 2019
    joind.in/talk/387e8

    View Slide

  77. @el_stoffel
    SymfonyLive Berlin 2019
    Fragen?

    View Slide