liveBook · Manning

Application core

As explained in Clean Applications with Hexagonal Architecture

The central part of an application containing its domain and application logic while remaining independent of external technologies.

When database choices or HTTP response shapes enter business logic, a change at the edge can ripple through the application. The application core contains the domain and application logic while keeping those external technologies outside its boundary. section 1.0 section 1.1.1

The domain core is the innermost part: entities, value objects, domain services, and rules that protect invariants. Around it, application handlers implement use cases, coordinate domain objects, and call output ports. Both remain independent of framework and infrastructure details. section 1.1.1 section 2.3 section 9.2

Make the boundary explicit through ports and adapters:

  • Input ports declare what the application can do. Driving adapters translate external requests into calls to those ports; handlers implement them. section 1.1.1 section 2.3
  • Output ports declare what the core needs in domain language. Driven adapters implement those contracts using databases, services, or other technologies. section 1.1.1 section 2.3.2
  • Dependencies point inward: the core owns the interfaces, and adapters conform to them. Runtime calls can flow outward through an output port without making the core depend on its implementation. section 1.1.2 section 1.3.1
Listing 1.1 Relating these pieces in code
public interface CreateArticleUseCase {  // #A
    Either<Error, Void> execute(CreateArticleCommand command);
}
 
public interface ArticleRepository {
    Either<Error, Void> save(Article article); // #B
}
 
public interface GetAuthorBiblioOutputPort { // #C
    Either<Error, BiblioDTO> biblioForAuthor(String author);
}
 
public class CreateArticleHandler implements
➥ CreateArticleUseCase { // #D
    private final ArticleRepository repository;
    // ... orchestration logic
}
public class JpaArticleRepositoryAdapter 
➥ implements ArticleRepository { // #E
    // ... JPA/database details hidden here
}
 
public class AuthorBiblioAdapter implements 
➥ GetAuthorBiblioOutputPort { // #F
    // ... call external API/service
}
 

The Java interfaces and classes show a use-case handler depending on a core repository contract while database and external-service details stay in adapters. section 1.1.1

Article creation through two delivery channels

A REST adapter and a Kafka consumer can both call the same CreateArticleUseCase. The delivery adapter changes; the use-case port does not. Likewise, a handler can be tested with a mock ArticleRepository instead of starting a database. section 2.3 section 1.1.2

Put business decisions in entities or handlers, HTTP and message translation in driving adapters, and SQL or external API details in driven adapters. An interface alone is not enough: a core model that mirrors a REST response or assumes a persistence technology still leaks external decisions. section 2.3.2 section 1.2.4

Cross-cutting concerns can attach at the handler boundary without importing a runtime framework into the core. Technology-agnostic annotations express intent; the adapter supplies the runtime implementation. The Spring Boot bootstrap belongs in the assembly module, so the core can compile and run its tests independently. section 4.4.3 section 6.2.1

A practical boundary check is whether an adapter can be replaced without changing the logic that uses its port. Test handlers with mocked ports, and enforce dependency boundaries with automated architecture checks such as ArchUnit. section 2.3.2 section 2.5 section 1.1.2

How Clean Applications with Hexagonal Architecture covers it

How deep it goes
Explains core-owned ports and dependency direction, then builds and tests a framework-free domain core.
Examples
Uses article creation through REST and Kafka adapters and a handler tested with a mocked repository.
What you can do after
Builds a framework-free domain core with value objects and an aggregate, and tests its behavior without outer-layer imports.
How it connects
Connects the application core to hexagonal architecture, dependency inversion, ports and adapters, and domain invariants.

Also explained in

Compare how 2 books explain application core →

Related concepts

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