hexagonal-architecture-layers-java

Enforce hexagonal architecture boundaries across Java Domain, Application, and Infrastructure layers.

618|89|Updated Jan 16, 2026
One-click install
npx skills add https://github.com/Gentleman-Programming/Gentleman-Skills --skill hexagonal-architecture-layers-java
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: hexagonal-architecture-layers-java
Source: https://github.com/Gentleman-Programming/Gentleman-Skills/tree/main/community/hexagonal-architecture-layers-java
Command: npx skills add https://github.com/Gentleman-Programming/Gentleman-Skills --skill hexagonal-architecture-layers-java

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill addresses the challenge of maintaining clean architecture boundaries in Java applications, helping teams keep domain logic decoupled from frameworks and infrastructure.

Core Features & Use Cases

  • Enforces Domain is pure: no framework annotations, no persistence concerns, no I/O in the domain.
  • Defines Application layer use cases and ports that orchestrate domain logic and IO through adapters.
  • Infrastructure wiring: adapters that connect controllers, repositories, and external services while respecting dependency direction.

Quick Start

To apply hexagonal architecture layering to a Java project, begin by identifying Domain, Application, and Infrastructure boundaries and implement sample Domain model and ports as shown in the guide.

Frequently Asked Questions about hexagonal-architecture-layers-java

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I enforce clean architecture boundaries in Java applications?

Enforce clean architecture boundaries by organizing your Java application into three layers: Domain (pure business logic with no framework dependencies), Application (use cases and ports that orchestrate domain logic), and Infrastructure (adapters connecting controllers, repositories, and external services). This separation keeps domain logic decoupled from frameworks and persistence concerns.

What is hexagonal architecture and how does it differ from layered architecture?

Hexagonal architecture, also called ports-and-adapters, structures applications around a pure domain core with clearly defined entry and exit points. Unlike traditional layered architecture, it emphasizes bidirectional dependency flow toward the domain, uses ports as interfaces for domain interactions, and allows multiple adapters per port for flexibility and testability.

How do I structure a Java application with domain-driven design and clean architecture?

Structure your Java application by identifying Domain, Application, and Infrastructure boundaries. Define your Domain model free of framework annotations, create Application layer ports that abstract I/O operations, then implement Infrastructure adapters for Spring components, controllers, and repositories. This ensures domain purity and decoupled dependencies.

Can I apply hexagonal architecture to existing Java services with Spring Framework?

Yes, hexagonal architecture applies to Java services organized with Spring-based components. You can refactor existing applications by extracting domain logic into framework-free classes, defining ports as Spring interfaces, and implementing adapters for controllers and repositories. This approach suits both initial structuring and refactoring for modularity.

What are common mistakes when implementing clean architecture in Java?

Common mistakes include allowing framework annotations in the Domain layer, creating ports that leak infrastructure details, and violating dependency direction by having adapters depend on the domain outward. Ensure domain remains pure, ports define clear contracts, and all dependencies point inward toward the domain core.

How do I handle multiple adapters and I/O operations in hexagonal architecture?

Define ports in the Application layer as interfaces representing specific I/O needs (e.g., repository ports, notification ports). In the Infrastructure layer, implement multiple adapters satisfying each port contract—different database adapters, message queue adapters, or external service clients—allowing you to swap implementations without affecting domain or application logic.