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 application architecture

1,529 views

Published on

In this workshop we'll take a slice of a pretty standard PHP project and gradually work our way towards an application that has a better architecture. "Better" meaning that:

It will be easy to find out what the uses cases of the application are ("screaming architecture")
It will be easy to find a place for every piece of the application ("layers")
It will be easy to find out how users and other systems can interact with it ("ports & adapters")
It will be easy to provide tests and automated acceptance criteria for it ("the testing pyramid")
I'm sure you would like your project to have these properties! I'll show you all the little steps that will help you transform your application to this new level.

Published in: Software

Advanced application architecture

  1. 1. ADVANCED APPLICATION ARCHITECTURE I - Layers Matthias Noback @matthiasnoback
  2. 2. matthiasnoback/
 layers-ports-and-adapters- workshop Clone from GitHub docker-compose pull bin/composer.sh install docker-compose up -d
  3. 3. ARCHITECTURE Decisions about coupling and cohesion
  4. 4. COUPLING How are things linked to each other?
  5. 5. COHESION Which things belong together?
  6. 6. LAYERED ARCHITECTURE An answer to both questions
  7. 7. LAYERS Help you protect what's in a deeper layer
  8. 8. LAYERS Allow you to define dependency rules
  9. 9. LAYERS Define the right place to put things
  10. 10. TRADITIONAL LAYERING view model data
  11. 11. LAYERS Horizontal division (as opposed to...)
  12. 12. USE CASES Vertical division
  13. 13. LAYERS Rendered as circles
  14. 14. CLEAN ARCHITECTURE Or "union" architecture
  15. 15. COHESION A basic set of layers infrastructure application domain
  16. 16. COUPLING The dependency rule Layers should only depend on deeper layers
  17. 17. COUPLING Dependency inversion principle Classes should always depend on things that are more abstract
  18. 18. COUPLING Dependency inversion principle low-levelconcrete class specific abstract interface generic high-level
  19. 19. COUPLING Dependency inversion principle use
  20. 20. COUPLING Dependency inversion principle use implement
  21. 21. COUPLING Is about dependencies in code Use Dependency Injection
  22. 22. LAYER CONVENTIONS Domain layer Domain model: ➤ Entities ➤ Value objects ➤ Domain services ➤ Factories Business logic Decisions Data State Behavior
  23. 23. LAYER CONVENTIONS Application layer ➤ Find an object ➤ Change something ➤ Notify something ➤ Get some information Use cases Orchestration
  24. 24. LAYER CONVENTIONS Infrastructure layer Communication with: ➤ HTTP client ➤ Database ➤ Filesystem ➤ Email server ➤ Message broker Connecting the application to the world outside
  25. 25. MATTHIASNOBACK/LAYERS- PORTS-AND-ADAPTERS- WORKSHOP Assignments are on GitHub in assignments/
  26. 26. assignment/01.md Layers
  27. 27. ADVANCED APPLICATION ARCHITECTURE II - Ports & adapters
  28. 28. MESSAGING ... is the big idea
  29. 29. PORTS (COHESION) Web, CLI, test client, messages, database queries User interface Persistence
  30. 30. PORTS... AND ADAPTERS Translation HTTP SQL
  31. 31. HEXAGONAL ARCHITECTURE Same thing! User interface Persistence
  32. 32. PORTS... AND ADAPTERS (De)serialization, translation, structural validation HTTP SQL
  33. 33. assignment/02.md Ports
  34. 34. PORT ADAPTERS ...in the Infrastructure layer
  35. 35. APPLICATION SERVICES ... in the Application layer
  36. 36. DOMAIN MODEL in the Domain layer
  37. 37. APPLICATION SERVICES Delivery-mechanism agnostic
  38. 38. assignment/03.md Input adapters
  39. 39. VALIDATION At different levels Structural validation of messages User-friendly input validation Domain invariant protection
  40. 40. assignment/04.md Input validation
  41. 41. APPLICATION SERVICES Transactional consistency
  42. 42. assignment/05.md Output adapter
  43. 43. assignment/06.md A hidden dependency on the persistence mechanism
  44. 44. ADVANTAGES OF USING LAYERS, 
 PORTS & ADAPTERS Offers insight into the application Isolates the low-level details Allows for alternative implementations Helps with testing
  45. 45. ADVANCED APPLICATION ARCHITECTURE III - Testing
  46. 46. UNIT TESTS Testing your units of code One class at a time No IO No setup required Mocking only dependencies "you own"
  47. 47. INTEGRATION TESTS Testing your adapters Maybe multiple classes Including IO Some setup required Mocking no dependencies
  48. 48. ACCEPTANCE TESTS Testing your application services Multiple classes Use cases Infrastructure stand-ins
  49. 49. SYSTEM TESTS Testing your application end-to-end The real deal
  50. 50. TESTING PYRAMID Make it well-balanced Unit Integration System Acceptance
  51. 51. assignment/07.md Different types of tests
  52. 52. ACCEPTANCE TESTS Use infrastructure stand-ins Acceptance test test the application layer
  53. 53. Persistence FileBased InMemory Port Adapters
  54. 54. MeetupRepository FileBasedMeetupRepository InMemoryMeetupRepository Domain Infrastructure implements implements
  55. 55. assignment/08.md A test double for the Persistence port
  56. 56. assignment/09.md An acceptance test for the application layer
  57. 57. A WELL-BALANCED TEST SUITE Adapters can be easily replaced Test suite is fast Feedback is quick Small amount of fragile tests Enables continuous delivery
  58. 58. assignment/10.md Notifications
  59. 59. https://training.matthiasnoback.nl/
  60. 60. https://joind.in/talk/b1763 Feedback?

×