liveBook · Manning

Driven adapter

As explained in Grokking Software Architecture

An implementation outside the application core that translates a secondary port's contract into actions involving an external system.

A driven adapter lives outside the application core and implements a secondary port. It translates the core’s request into actions involving infrastructure, such as saving data or sending an alert. The core depends on the port; the adapter depends inward on the core’s contract. section 5.3.3 section 5.4.1

Keep the boundary useful:

  • Define the port in the core’s language, not with types from an external database or API. section 5.3.5
  • Keep adapters focused on translation; put business rules in the core, not in a controller or repository. section 5.3.5
  • Inject the adapter through the port, then choose and wire the implementation at the application entry point. section 5.5.2

One alert port, several adapters

A server monitor calls an alert port when its temperature is too high. A Twilio adapter sends an SMS, a console adapter prints a development alert, and a Kafka adapter publishes a message. The monitor can use any of them without creating the infrastructure itself. section 5.5.2

Figure 5.11 On the Driven Side, the Domain Logic never talks to the database directly; it simply calls a Secondary Port (Interface). The actual database or email server is hidden inside a Secondary Adapter that implements the interface, allowing you to swap out your infrastructure without changing a single line of business logic.

Shows how the core calls a secondary port while the adapter hides the database or email service behind that interface. section 5.4.1

How Grokking Software Architecture covers it

How deep it goes
Explains the port-adapter boundary, dependency inversion, and injection, then demonstrates several alert implementations.
Examples
Uses SQL repositories and Twilio, console, and Kafka alert adapters as infrastructure examples.
What you can do after
Build it from scratch by implementing an alert port, injecting an adapter, and wiring the choice at the application entry point.
How it connects
Connects secondary ports with dependency inversion, dependency injection, composition roots, and anti-corruption layers.

Also explained in

Compare how 3 books explain driven adapter →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Software Architecture. The section links point to the parts of the book it draws on.