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.

Ports & Adapters Architecture - XP Days 2017

278 views

Published on

Presentation on how here at Coolblue we refactored an existing application from a layered architecture to ports & adapters and the benefits we achived by doing so.

Published in: Software
  • Be the first to comment

Ports & Adapters Architecture - XP Days 2017

  1. 1. Ports & Adapters Architecture Inside & Outside Application Thinking Nathan Johnstone - Technical Pathfinder @ Coolblue
  2. 2. Focus
  3. 3. A Bit About Me ...
  4. 4. A Bit About Me ...
  5. 5. Pigs != Pegs
  6. 6. The Starting Point
  7. 7. Joining a Team
  8. 8. Infrastructure Dependencies Web API Message Service Scheduler
  9. 9. Application Assemblies Web API Message Service Scheduler Data Access Domain Common
  10. 10. Application Dependencies Web API Message Service Scheduler Data Access Domain Common
  11. 11. Class Library Dependencies Web API Message Service Scheduler Data Access Domain Common
  12. 12. N-Tier Web API Data Access Domain
  13. 13. Isn't Something Missing ?
  14. 14. Pain
  15. 15. Leakage
  16. 16. DRY - Reuse Reuse Reuse !
  17. 17. Test Coverage Unit Tests Component Tests Acceptance Tests Integration Tests
  18. 18. Implementing Integration Tests
  19. 19. Interfaces Colocated With Implementations Data Access Domain PurchaseOrderSubmitServiceIPurchaseOrderRetriever PurchaseOrderRetriever ?
  20. 20. Who Owns The Interface ?
  21. 21. Colocation Problems Data Access Domain PurchaseOrderSubmitServiceIPurchaseOrderRetriever PurchaseOrderPurchaseOrderDocument
  22. 22. Isolation Violation PurchaseOrderDocument Domain
  23. 23. Reference Direction vs Control Direction Presentation Layer Data Access Layer Business Logic Layer Reference DirectionControl Direction
  24. 24. Ports & Adapters Introduction Allow an application to equally be driven by users, programs, automated test or batch scripts, and to be developed and tested in isolation from its eventual run-time devices and databases.
  25. 25. Hexagonal Architecture
  26. 26. Inside Outside Architecture
  27. 27. First Port - Persistence Web API Message Service Scheduler Data Access Domain Common Persistence Adapter
  28. 28. Mikado Method
  29. 29. Second Port - Commands Web API Message Service Scheduler Data Access Domain Persistence Adapter Command Adapter
  30. 30. Upstream & Downstream Ports
  31. 31. Third Port - Notification Web API Message Service Scheduler Data Access Domain Persistence Adapter Command Adapter Notification Adapter
  32. 32. Clean Up Web API Message Service Scheduler Data Access Domain Persistence Adapter Command Adapter Notification Adapter
  33. 33. Hexagonal - Domain Domain Web API Message Service Scheduler Persistence Adapter Command Adapter Notification Adapter
  34. 34. Hexagonal - Persistence Port Domain Web API Message Service Scheduler Persistence Adapter Command Adapter Notification Adapter Persistence Port
  35. 35. Hexagonal - Command Port Domain Web API Message Service Scheduler Persistence Adapter Command Adapter Notification Adapter Persistence Port CommandPort
  36. 36. Hexagonal - Notification Port Domain Web API Message Service Scheduler Persistence Adapter Command Adapter Notification Adapter Persistence Port CommandPort Notification Port
  37. 37. Hosts Are Types of Adapters Web Service Test Harness Command Line Daemon Windows Service Graphical UI
  38. 38. Hexagonal - Host Port Domain Web API Message Service Scheduler Persistence Adapter Command Adapter Notification Adapter Persistence Port CommandPort Notification Port Host Port
  39. 39. Advantages - Domain Testability Domain Web API Message Service Scheduler Persistence Adapter Command Adapter Notification Adapter Persistence Port CommandPort Notification Port Host Port
  40. 40. Advantages - Boundaries Web API Message Service Scheduler Domain Persistence Adapter Command Adapter Notification Adapter
  41. 41. Advantages - Alternative Adapters Domain Web API Message Service Scheduler Persistence.Adapter Command.Adapter Notification Adapter Persistence Port CommandPort Notification Port Host Port Persistence.Adapter Csv Command.Adapter File
  42. 42. Notification via SMTP Domain Web API Message Service Scheduler Persistence Adapter Command Adapter Notification Adapter Persistence Port CommandPort Notification Port Host Port
  43. 43. Code Examples - Book Ordering Service
  44. 44. Book Ordering Service - Client 1 ● REST endpoints for adding books, approving and submitting ● Notification to supplier to be via SMTP ● Persistence to MySQL
  45. 45. Book Ordering Service - Client 2 ● RabbitMq message for adding books ● REST endpoints for adding approving and submitting ● Notification to supplier to be via RabbitMq message ● Persistence to MySQL
  46. 46. Book Ordering Service - Architecture Domain Host Web API Client 1 Web API Client 2 Persistence MySQL Notification SMTPRabbitMq CommandRabbitMq
  47. 47. Warning Live Code Demo Ahead !
  48. 48. Takeaways ● Ports are just a name given to a common group of abstractions in your domain ● Adapters are a group of specific implementations of a given port ● Onion Architecture, Clean Architecture and Ports & Adapters are essentially the same thing ● Example repository on github for .NET ● Ports & Adapters is an architectural style that will produce applications that are independent of infrastructure details
  49. 49. Links ● http://alistair.cockburn.us/Hexagonal+architecture ● http://blog.ploeh.dk/2013/12/03/layers-onions-ports-adapters-its-all-the-same/ ● https://github.com/nrjohnstone/ports-adapters-examples ● https://www.linkedin.com/in/nrjohnstone ● https://nathanjohnstone.wordpress.com/ ● n.johnstone@coolblue.nl ● locotewz@gmail.com

×