Table of contents : Designing Hexagonal Architecture with Java Contributors About the author About the reviewers Preface Who this book is for What this book covers To get the most out of this book Download the example code files Conventions used Get in touch Share Your Thoughts Download a free PDF copy of this book Part 1: Architecture Fundamentals 1 Why Hexagonal Architecture? Technical requirements Reviewing software architecture Making decisions The invisible things Technical debt Vicious cycle It’s not for everyone Monolithic or distributed Understanding hexagonal architecture Domain hexagon Application hexagon Use cases Output ports Framework hexagon Advantages of the hexagonal approach Summary Questions Further reading Answers 2 Wrapping Business Rules inside Domain Hexagon Technical requirements Modeling a problem domain with entities The purity of domain entities Relevant entities Using UUIDs to define identity Enhancing descriptiveness with value objects Using value objects to compose entities Assuring consistency with aggregates Modeling an aggregate Working with domain services Using policy and specification to deal with business rules Creating specifications Creating policies Defining business rules as POJOs Summary Questions Further reading Answers 3 Handling Behavior with Ports and Use Cases Technical requirements Expressing software behavior with use cases How to create a use case Implementing use cases with input ports Using output ports to deal with external data It’s not only about repositories Where to use output ports Automating behavior with the Application hexagon Summary Questions Further reading Answers 4 Creating Adapters to Interact with the Outside World Technical requirements Understanding adapters Using input adapters to allow driving operations Creating input adapters Using output adapters to speak with different data sources Creating output adapters Summary Questions Answers Further reading 5 Exploring the Nature of Driving and Driven Operations Technical requirements Reaching the hexagonal application with driving operations Integrating web applications with the hexagonal system Creating the Add Network page Creating the Get Router page Running test agents Calling the hexagonal system from other applications Handling external resources with driven operations Data persistence Messaging and events Mock servers Summary Questions Answers Part 2: Using Hexagons to Create a Solid Foundation 6 Building the Domain Hexagon Technical requirements Bootstrapping the Domain hexagon Understanding the problem domain Defining value objects Defining entities and specifications The Equipment and Router abstract entities The core router entity and its specifications Edge router entity and its specifications Switch entity and its specifications Defining domain services Router service Switch service Network service Testing the Domain hexagon Summary Questions Answers 7 Building the Application Hexagon Technical requirements Bootstrapping the Application hexagon Defining use cases Creating written descriptions for router management use cases Defining the use case interface for router management Creating written descriptions for switch management use cases Defining the use case interface for switch management Creating written descriptions for network management use cases Defining the use case interface for network management Implementing use cases with input ports Testing the Application hexagon Summary Questions Answers 8 Building the Framework Hexagon Technical requirements Bootstrapping the Framework hexagon Implementing output adapters The router management output adapter The switch management output adapter Implementing the input adapters The router management input adapter The switch management input adapter The network management input adapter Testing the Framework hexagon Summary Questions Answers 9 Applying Dependency Inversion with Java Modules Technical requirements Introducing the JPMS Inverting dependencies on a hexagonal application Providing services with use cases and input ports Providing services with output ports and output adapters Making the input adapters dependent on abstractions Using the Java platform’s ServiceLoader class to retrieve JPMS provider implementations Initializing RouterManagementGenericAdapter Initializing SwitchManagementGenericAdapter Initializing NetworkManagementGenericAdapter Summary Questions Answers Further reading Part 3: Becoming Cloud-Native 10 Adding Quarkus to a Modularized Hexagonal Application Technical requirements Revisiting the JVM Speeding up runtime performance with JIT compilation Improving startup time with AOT compilation Introducing Quarkus Creating REST endpoints with JAX-RS Employing dependency injection with Quarkus DI Validating objects Configuring a data source and using Hibernate ORM Adding Quarkus to a modularized hexagonal application Summary Questions Answers 11 Leveraging CDI Beans to Manage Ports and Use Cases Technical requirements Learning about Quarkus DI Working with beans Transforming ports, use cases, and adapters into CDI beans Implementing CDI for router management objects Implementing CDI for switch management objects Implementing CDI for network management classes and interfaces Testing use cases with Quarkus and Cucumber Summary Questions Answers 12 Using RESTEasy Reactive to Implement Input Adapters Technical requirements Exploring the approaches to handling server’s requests Imperative Reactive Implementing input adapters with RESTEasy Reactive Implementing the Reactive input adapter for router management Implementing the Reactive input adapter for switch management Implementing the Reactive input adapter for network management Adding OpenAPI and Swagger UI Testing Reactive input adapters Summary Questions Answers 13 Persisting Data with Output Adapters and Hibernate Reactive Technical requirements Introducing Hibernate Reactive and Panache Hibernate Reactive features Panache features Enabling reactive behavior on output adapters Configuring reactive data sources Configuring entities Implementing reactive repository classes Implementing reactive output adapters Reactive router management of the MySQL output adapter Reactive switch management of the MySQL output adapter Testing the reactive output adapters Summary Questions Answers 14 Setting Up Dockerfile and Kubernetes Objects for Cloud Deployment Technical requirements Preparing the Docker image Creating a Docker image with an uber .jar artifact Creating a Docker image with a native executable Creating Kubernetes objects Reviewing Kubernetes' main objects Configuring Kubernetes objects for the hexagonal system Deploying on minikube Summary Questions Answers Part 4: Hexagonal Architecture and Beyond 15 Comparing Hexagonal Architecture with Layered Architecture Technical requirements Reviewing the layered architecture Creating an application using the layered architecture Implementing the data layer Implementing the service layer Implementing the API layer Testing the layered application Refactoring a layered architecture application into a hexagonal one Implementing the Domain hexagon Implementing the Application hexagon Implementing the Framework hexagon Testing the hexagonal application Assessing the benefits and disadvantages of hexagonal and layered architectures Summary Questions Answers 16 Using SOLID Principles with Hexagonal Architecture Technical requirements Understanding SOLID principles Single Responsibility Principle (SRP) Open-Closed Principle (OCP) Liskov Substitution Principle (LSP) Interface Segregation Principle (ISP) Dependency Inversion Principle (DIP) Applying SOLID on a hexagonal architecture system Applying the SRP Applying the OCP Applying the LSP Applying the ISP Applying the DIP Exploring other design patterns Singleton Builder Abstract factory Summary Questions Answers 17 Good Design Practices for Your Hexagonal Application Technical requirements Using Domain-Driven Design to shape the Domain hexagon Understanding the business we are in Promoting collaboration to increase knowledge Applying DDD techniques to build the Domain hexagon Implementing bounded contexts and subdomains in a hexagonal system The need for creating ports and use cases Dealing with multiple adapter categories Conclusion – the hexagonal journey Summary Questions Answers Index Why subscribe? Other Books You May Enjoy Packt is searching for authors like you Share Your Thoughts Download a free PDF copy of this book