Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Advanced web application architecture - PHP Barcelona

880 views

Published on

-

Published in: Software
  • Be the first to comment

Advanced web application architecture - PHP Barcelona

  1. 1. Advanced Web Application Architecture @matthiasnoback info@matthiasnoback.nl Slides are onTwitter Questions via the website please :)
  2. 2. Somebody's wrong in the internet
  3. 3. I'm one of them
  4. 4. This is not to say that we shouldn't listen to any advice!
  5. 5. Where does advice come from?
  6. 6. Experience ● You look back on a recent project that went well ● You look at your choices and consider them the cause of the project's success ● You tell other people to make the same choices.
  7. 7. People will copy your choices
  8. 8. They fail
  9. 9. "They got it all wrong, just do this!"
  10. 10. Don't follow anyone
  11. 11. Listen to your code Listen to its design
  12. 12. Collect and share heuristics
  13. 13. Heuristics?
  14. 14. What worked well In which situation And what's a good rule of thumb for it
  15. 15. Should you... Call façades? Use Yaml? Write methods you can call with 0, 1 or 2 arguments? Use middlewares? Over-engineer your project using hexagonal architecture?
  16. 16. Write about what your experience
  17. 17. Change is really hard for most software projects I've encountered
  18. 18. Reasons for change Framework integration code
  19. 19. Reasons for change Remote service calls
  20. 20. Reasons for change Domain model
  21. 21. Single responsibility principle for architecture What changes for the same reason should be grouped together
  22. 22. Examples ● All the things related to your framework ● All the things related to your domain model ● All the things related to your database ● ...
  23. 23. The most important distinction is... Not too many groups
  24. 24. Domain vs Infrastructure ● Model (entities, value objects) ● Use cases (application services) ● Interfaces for boundary objects ● Framework-specific code ● Implementations for boundary objects ● Web controllers, CLI controllers, etc.
  25. 25. Step 1 Introduce layers
  26. 26. Step 1: Introduce layers Web framework Domain logic Database integration
  27. 27. Introduce layers Web framework Domain logic Database integration InfrastructureDomain
  28. 28. Step 2 Define ports and adapters (Hexagonal architecture; Alistair Cockburn)
  29. 29. Determine actors Application Primary actor: User Secondary actor: Database Primary actor: User Secondary actor: Remote webservice Primary actor: Cronjob
  30. 30. Make a distinction... Between the intention for communication, and the supporting implementation
  31. 31. Examples The user can buy a ticket
  32. 32. Examples We have a TicketsController with a buyTicket action. It gets the logged in user from the session and gets the user's address from the submitted form data.
  33. 33. Examples We need to persist an order
  34. 34. Examples We store order data in an orders table in our MySQL database. We use Doctrine DBAL to talk with that database.
  35. 35. Ports Buyaticket Persistanorder
  36. 36. Adapters Buyaticket Persistanorder HTTPadapter SQLadapter
  37. 37. Advantages By separating domain from infrastructure code you automatically increase testablity
  38. 38. Advantages You can replace an adapter without affecting the ports
  39. 39. Advantages You can postpone the choice for database vendor, framework, ORM, etc.
  40. 40. Advantages You can more easily keep up with the change rate of framework-specific code
  41. 41. Advantages Or replace the framework altogether...
  42. 42. Sources ● Alistair in the "Hexagone": https://www.youtube.com/watch?v=th4AgBcrEHA ● My upcoming book "Advanced Web Application Architecture" https://leanpub.com/web-application-architecture/ ● Nat Pryce, Steve Freeman - Growing Object-Oriented Software, Guided by Tests ● Vaughn Vernon - Implementing Domain-Driven Design (see the chapter about Architecture)
  43. 43. Q & A
  44. 44. Thank you! @matthiasnoback info@matthiasnoback.nl

×