All skills
lexler avatar

/hexagonal-architecture

@83aee6a
by Lada Kesselerlexler/skill-factory238 stars
61

Applies hexagonal (ports & adapters) architecture. Use when designing application structure, separating domain from infrastructure, creating testable boundaries, or when user mentions ports, adapters, hexagonal, or clean architecture.

Use this Skill: https://skilld.dev/gh/lexler/skill-factory/hexagonal-architecture

This session only. Nothing lands on disk.

SKILL.md

β‰ˆ65 tokens always: the name and description. β‰ˆ926 when used: this file. β‰ˆ13 more on demand in 1 file.

Hexagonal Architecture

The Core Decision Rule

To decide if something belongs inside or outside the hexagon, ask:

"Does it do I/O or run out-of-process?"

  • No β†’ Inside the hexagon (domain or application layer)
  • Yes β†’ Outside (adapter)

Critical: Consider ALL dependencies. A component's dependencies disqualify it even if the component itself doesn't do I/O. If it depends on Spring, a database driver, or any frameworkβ€”it's outside.

Layer Responsibilities

Common misconception: The hexagon is NOT just the domain. The hexagon contains both domain AND application layers. Adapters sit outside.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚           ADAPTERS (outside)            β”‚
β”‚  Web, CLI, Database, External APIs      β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚     APPLICATION SERVICES          β”‚  β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚  β”‚
β”‚  β”‚  β”‚         DOMAIN              β”‚  β”‚  β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        Dependencies flow INWARD only

Domain β€” Business constraints (what CAN happen). Contains Entities, Value Objects, Domain Services.

Application β€” Orchestration (HOW things happen). Contains Use Cases, Application Services.

Adapters β€” Translation to/from external world. Contains Controllers, Repositories, API clients.

Domain defines ports (interfaces). Adapters implement them.

Naming Conventions

  • Display/response: *View or *Response β†’ MemberView, OrderResponse
  • Incoming request: *Request β†’ CreateMemberRequest
  • Database entity: *Dbo β†’ MemberDbo
  • Domain β†’ DTO: static from(domain) β†’ MemberView.from(member)
  • DTO β†’ Domain: as*() method β†’ request.asMember()

Anti-Patterns

Brittle Interfaces

register(username, password)  // Breaks when email required

Use wrapper objects that can evolve without breaking signatures.

Domain Scope Pollution

Third-party types (GoogleUser, StripePayment) leaking into domain. Keep external types in adapters; map to domain types at the boundary.

Use-Case Interdependencies

Use cases calling other use cases creates coupling. Each use case should be self-contained, orchestrating domain objects directly.

Anemic Domain

Entities as data bags with logic scattered in services. Business rules belong IN entities and value objects.

Premature Database Design

Designing schema before domain model. Domain model comes first; database adapter maps to it.

Over-Complicated Adapters

Adapters adding logic beyond translation. Adapters should be thinβ€”just implement the port interface.

Testing Strategy

  • Domain: Unit tests, no doubles needed (pure logic)
  • Application: Unit tests with port doubles (fake repositories, stub notifiers)
  • Adapters: Integration tests against real infrastructure (real database, real HTTP)

Ports give clean seams for test doubles. Test the domain exhaustively with fast unit tests; test adapters against real infrastructure sparingly.

When NOT to Use

  • Small/simple projects, especially CRUD-based apps (overhead not worth it)

Source: SKILL.md on GitHub

1 warning13d4 checks Β· Risk SAFE
  • Gen Agent Trust Hub13d

    This skill provides architectural guidance for implementing hexagonal architecture and contains no executable code or security risks.

  • Socket13d

    No alerts

  • Snyk13d

    Risk: LOW Β· No issues

  • Runlayer7mo

    2/2 files flagged

Signed by skilld at 83aee6a. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Steadyupdated 8 months ago

README badge

README badge for lexler/skill-factory/hexagonal-architecture