When business logic depends directly on a database, framework, or transport model, an infrastructure change can ripple through the core. Dependency inversion protects that core by making both the business logic and external implementations depend on abstractions rather than concrete details. section 1.0 section 1.1.2
In hexagonal architecture, the core owns its port interfaces. A handler uses an output port to express what it needs; an external adapter implements that port. The adapter depends inward on the core’s contract, not the other way around. The same boundary applies to input ports: a REST adapter can call a use-case interface without depending on its handler implementation. section 1.1.2 section 9.3.2
Listing 1.2 The core never knows about the specific details of the adapters
public class ArticleService { // #A
private final JpaArticleRepository repo; // can leak concrete class
}
package application.core.domain; // #B
public interface ArticleRepository { // #C
Either<Error, Void> save(Article article);
Either<Error, ArticleDTO> findById(ArticleId id);
}
package application.core.handler;
public class CreateArticleHandler { // #D
private final ArticleRepository repo; // interface defined by domain
}
Compare a service coupled to a concrete JPA repository with a handler that depends on a core-defined repository interface. section 1.1.2
A replaceable repository adapter
CreateArticleHandler depends on the core’s ArticleRepository interface. JpaArticleRepositoryAdapter implements that interface and contains the JPA details. A test can inject a mock repository; a different adapter can replace the JPA implementation without changing the handler’s business logic. section 1.1.2 section 2.3.1
Design ports around domain needs, not infrastructure methods, and keep business logic out of adapters. Enforce the dependency boundary with architectural tests such as ArchUnit so that framework and infrastructure dependencies do not creep back into the core. section 2.5 section 1.2.3







