Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SfDay 2024 - Don't let the framework stand on y...

Samuele
September 25, 2024

SfDay 2024 - Don't let the framework stand on your way

Symfony è uno strumento potente ma comprendere tutte le sue logiche può non essere immediato. Proprio per questo la sua estensiva documentazione mira a semplificare le cose indirizzando però l’utente alla metodologia RAD (Rapid Application Development). Tutti gli utilizzatori di Symfony si saranno – presumibilmente – trovati ad avere componenti/concetti del framework dove non sarebbero dovuti essere: utente, sessione, entità anemiche “forzate” dai form, event dispatcher e così via. In questa sessione, tramite esempi pratici, proveremo a capire sia perché è meglio confinare il codice di terze parti in layer separati rispetto al livello che ospita la logica di business, sia come farlo. Analizzeremo quindi i componenti e concetti più utilizzati formalizzando un approccio paradigmatico da poter applicare anche ai componenti e concetti che non avremo tempo di affrontare in questi trenta minuti.

Samuele

September 25, 2024
Tweet

More Decks by Samuele

Other Decks in Technology

Transcript

  1. Madisoft • tHE subject [AN OVERVIEW] • Why? • Architectural

    Styles AGENDA Sfday󰏢 - 127.0.0.1 / 25.09.2024
  2. Madisoft • tHE subject [AN OVERVIEW] • Why? • Architectural

    Styles • HANDS ON ◦ USER ◦ FORM ◦ EVENT/MESSAGE DISPATCHER AGENDA Sfday󰏢 - 127.0.0.1 / 25.09.2024
  3. Madisoft Samuele lilli DonCallisto Senior Backend Developer @ Madisoft 5

    time speaker @SfDay Unit test enthusiast @SamueleLilli Sfday󰏢 - 127.0.0.1 / 25.09.2024
  4. Madisoft • 20 cluster active relational databases (UP TO 50

    cluster when scaled). • 1.3 billions query / day. • 2.1 Terabyte relational data. • ~ 60 DAILY INSTANCES HOSTING THE APPLICATION. • 500 MILLIONS ATTACHMENTS, 126 Terabyte ON object storage (CLOUD). • ~ 100 Terabyte BANDWIDTH / MONTH. • ~ 600.000 DAILY USERS • ~ 1.3 Milioni DAILY SESSIONS • ~ 8.5 MILLIONS VIEWS / PAGE / DAY. • ~ 1.5 MILLIONS DAILY VISITS ON area-tutore • ~ 800.000 DAILY VISITS ON HOMEWORKS • ~ 350.000 DAILY VISITS ON VOTES • ~ 1.300 CLIENTS, ~ 8.000 SCHOOLS INSTITUTIONS madisoft Sfday󰏢 - 127.0.0.1 / 25.09.2024 Some numbers
  5. Madisoft What we have • 704.423 PHP loc (comments not

    included) • 21.396 unit tests • ~ 1.934 other tests (mainly behat) • Some legacy code Where we're heading • Microservices / modular monolith • Ddd lite madisoft Sfday󰏢 - 127.0.0.1 / 25.09.2024 WHAT WE HAVE, WHERE WE'RE HEADING
  6. Madisoft • Low hanging fruit examples • Your mileage may

    vary • No time for comparisons • Won't take into account all symfony Components • Abstraction = more classes DISCLAIMER Sfday󰏢 - 127.0.0.1 / 25.09.2024
  7. Madisoft We don't want third-party dependencies infiltrate Our application code.

    The infiltration happens when this kind of code is scattered all over the place, leaking in places where it should not be just for the sake of convenience. subject Sfday󰏢 - 127.0.0.1 / 25.09.2024
  8. Madisoft Sfday󰏢 - 127.0.0.1 / 25.09.2024 We don't want third-party

    dependencies infiltrate Our application code.
  9. Madisoft Sfday󰏢 - 127.0.0.1 / 25.09.2024 We don't want framework

    code to be a dependency Of Our business code.
  10. Madisoft • tHE subject [AN OVERVIEW] • Why? • Architectural

    Styles • HANDS ON ◦ USER ◦ FORM ◦ EVENT/MESSAGE DISPATCHER AGENDA Sfday󰏢 - 127.0.0.1 / 25.09.2024
  11. Madisoft We don't want framework code to be a dependency

    Of Our business code. When this happens, the code is harder to be unit tested, you are tied to implementation details (established by someone else), you think implicitly to the code in terms of what third-party provides you WHY Sfday󰏢 - 127.0.0.1 / 25.09.2024
  12. Madisoft We don't want framework code to be a dependency

    Of Our business code. When this happens, the code is harder to be unit tested, you are tied to implementation details (established by someone else), you think implicitly to the code in terms of what third-party provides you WHY Sfday󰏢 - 127.0.0.1 / 25.09.2024
  13. Madisoft We don't want framework code to be a dependency

    Of Our business code. When this happens, the code is harder to be unit tested, you are tied to implementation details (established by someone else), you think implicitly to the code in terms of what third-party provides you WHY Sfday󰏢 - 127.0.0.1 / 25.09.2024 That's not yours: don't mock what you don't own
  14. Madisoft We don't want framework code to be a dependency

    Of Our business code. When this happens, the code is harder to be unit tested, you are tied to implementation details (established by someone else), you think implicitly to the code in terms of what third-party provides you WHY Sfday󰏢 - 127.0.0.1 / 25.09.2024
  15. Madisoft We don't want framework code to be a dependency

    Of Our business code. When this happens, the code is harder to be unit tested, you are tied to implementation details (established by someone else), you think implicitly to the code in terms of what third-party provides you WHY Sfday󰏢 - 127.0.0.1 / 25.09.2024
  16. Madisoft "I suppose it is tempting, if the only tool

    you have is a hammer, to treat everything as if it were a nail" Law of the instrument Sfday󰏢 - 127.0.0.1 / 25.09.2024 Abraham Maslow (psychologist)
  17. Madisoft Sfday󰏢 - 127.0.0.1 / 25.09.2024 public function __construct( private

    readonly EntityManagerInterface $entityManager ) { } public function execute(): User { $user = new User([...]); $this->entityManager->persist($user); $this->entityManager->flush(); // ... } WHY
  18. Madisoft Sfday󰏢 - 127.0.0.1 / 25.09.2024 public function __construct( private

    readonly EntityManagerInterface $entityManager ) { } public function execute(): User { $user = new User([...]); $this->entityManager->persist($user); $this->entityManager->flush(); // ... } WHY
  19. Madisoft Code evolves and so does the framework code… (hopefully

    you want/need to update it) WHY Sfday󰏢 - 127.0.0.1 / 25.09.2024 but...
  20. Madisoft WHY Sfday󰏢 - 127.0.0.1 / 25.09.2024 Consequences of code

    evolution • Amplification/propagation of changes • Version control diff's grown • Cognitive load raise • Test doubles need to be adjusted (no value, time consuming) • Can't pipeline automatic checks
  21. Madisoft • tHE subject [AN OVERVIEW] • Why? • Architectural

    Styles • HANDS ON ◦ USER ◦ FORM ◦ EVENT/MESSAGE DISPATCHER AGENDA Sfday󰏢 - 127.0.0.1 / 25.09.2024
  22. Madisoft • Layered • Hexagonal (ports and adapters) • Onion

    architecture Have something in common… • Clear code separation • Dependency "direction" styles Sfday󰏢 - 127.0.0.1 / 25.09.2024
  23. Madisoft • tHE subject [AN OVERVIEW] • Why? • Architectural

    Styles • HANDS ON ◦ USER ◦ FORM ◦ EVENT/MESSAGE DISPATCHER AGENDA Sfday󰏢 - 127.0.0.1 / 25.09.2024
  24. Madisoft • Logical coupling should be avoided like dependency coupling

    • Don't think in terms of what the framework offers you, use the framework to get what you need. • Segregate framework code inside infrastructure layer/adapter. • There's always a different solution, take time to explore. takeaways Sfday󰏢 - 127.0.0.1 / 25.09.2024
  25. Madisoft resources • Don't mock what you don't own •

    Law of the instrument • Advanced Web Application Architecture (Noback) • Code for this talk
  26. Madisoft CREDITS: This presentation template was created by Slidesgo, including

    icons by Flaticon, and infographics & images by Freepik and illustrations by Stories Thank you! @SamueleLilli labs.madisoft.it