hexagonal-architecture

Isolate application core from external infrastructure using ports and adapters.

Updated Apr 14, 2026
One-click install
npx skills add https://github.com/BrunoAMSilva/my-config --skill hexagonal-architecture-brunoamsilva
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: hexagonal-architecture
Source: https://github.com/BrunoAMSilva/my-config/tree/main/coding/skills/hexagonal-architecture
Command: npx skills add https://github.com/BrunoAMSilva/my-config --skill hexagonal-architecture-brunoamsilva

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Separates business logic from external systems so applications remain testable, maintainable, and agnostic to database, network, and framework changes.

Core Features & Use Cases

  • Ports and Adapters: Define primary (driving) and secondary (driven) ports in the application core and implement adapters in infrastructure.
  • Testability: Swap real adapters for mocks to run unit tests without external systems and use console or in-memory adapters for integration tests.
  • Composition Root & DI: Wire concrete adapters to ports at the composition root to enable one-line adapter swaps (e.g., Postgres → Mongo, SendGrid → SES).
  • Use Case Example: Implement RegisterUserUseCase in the core with IUserRepository and IEmailService ports, provide Postgres and SendGrid adapters for production, and inject mock adapters in tests.

Quick Start

Define interfaces for required ports in the application core, implement adapters for your external systems, and wire them together at the composition root so you can run use cases with mock adapters for tests.

Frequently Asked Questions about hexagonal-architecture

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

FAQPage Schema
How do I decouple business logic from databases and external services for unit testing?

Decouple business logic from external services by defining primary and secondary ports as interfaces in the application core, then implementing adapters for databases and providers. Swap real adapters for mocks at the composition root to enable unit testing without external systems.

What is the best way to structure an application so infrastructure components are swappable?

The best way to make infrastructure swappable is using hexagonal architecture, where you wire concrete adapters to ports at the composition root with dependency injection. This enables one-line adapter swaps, such as replacing Postgres with Mongo or SendGrid with SES.

Can I use ports and adapters to isolate frontend business logic from analytics and HTTP entry points?

Yes, ports and adapters apply to both backend and frontend services. You isolate the application core from HTTP and CLI entry points by defining driving ports, allowing business logic to remain testable and decoupled from external analytics and network frameworks.

How do I run integration tests without connecting to a live database or email provider?

Run integration tests without live external systems by injecting console or in-memory adapters into your application ports. This allows use cases to execute against mock infrastructure, verifying behavior without requiring actual database or email provider connections.

When should I use hexagonal architecture for isolating my application core?

Use hexagonal architecture when your application requires high testability and maintainability across changing external systems. It is essential when business logic must be decoupled from databases, network frameworks, and providers to prevent infrastructure changes from affecting the core.