From design-architecture
Guides the design and analysis of hexagonal architecture (Ports & Adapters) for backend systems. Use when structuring modular applications with clean separation between business logic and infrastructure.
npx claudepluginhub aucun6352/project-cheat-sheet --plugin design-architectureThis skill uses the workspace's default tool permissions.
Hexagonal Architecture, also known as Ports & Adapters pattern, is an architectural pattern proposed by Alistair Cockburn that aims to separate the core business logic of an application from external infrastructure. The philosophy centers on creating a flexible, testable, and maintainable system by inverting dependencies and isolating the domain from technical concerns.
Guides implementation of hexagonal (ports and adapters) architecture for domain isolation, dependency inversion, and structuring apps with domain-defined ports and external adapters.
Designs, implements, and refactors hexagonal (Ports & Adapters) architecture in TypeScript, Java, Kotlin, and Go services for domain isolation, dependency inversion, and testable use cases.
Applies Clean Architecture, Hexagonal (Ports & Adapters), and DDD fundamentals to design systems, define layer boundaries, tactical patterns (entities, aggregates, repositories), enforce dependency rules.
Share bugs, ideas, or general feedback.
Hexagonal Architecture, also known as Ports & Adapters pattern, is an architectural pattern proposed by Alistair Cockburn that aims to separate the core business logic of an application from external infrastructure. The philosophy centers on creating a flexible, testable, and maintainable system by inverting dependencies and isolating the domain from technical concerns.
The hexagonal shape represents the idea that the application has multiple "sides" where it interacts with the outside world, and each side is interchangeable. This approach enables:
This skill is particularly valuable when building enterprise applications, microservices, or any system where long-term maintainability and testability are priorities.
Hexagonal Architecture is built on several fundamental principles that work together to create a robust, maintainable system.
The application is organized into distinct layers, each with specific responsibilities:
The dependency direction flows from outer layers toward the domain at the center.
Ports define the boundaries between the domain and the outside world. They are interfaces that express what the business logic needs without specifying how it's implemented.
Characteristics of Ports:
Adapters are concrete implementations of Port interfaces. They handle the actual communication with external systems and infrastructure.
Types of Adapters:
Adapters translate between the domain's language and the technical protocols of external systems.
One of the most critical principles: dependencies point inward, toward the domain.
Dependency Flow:
External → Infrastructure → Application → Domain
Key Rules:
Hexagonal Architecture naturally aligns with SOLID principles:
Each domain module operates independently with minimal coupling:
Begin by understanding your business domains and their relationships. Map out:
For each domain module, identify what it needs from the outside world and what it provides to others:
Build the core business logic without any infrastructure concerns:
Implement concrete adapters for each port:
Wire everything together using a DI container:
Hexagonal Architecture can be implemented in various programming languages and frameworks. We provide detailed examples for:
Each example demonstrates:
Choose the example that matches your technology stack to see concrete implementations of the concepts discussed in this skill.
Maintain strict separation between layers with consistent dependency direction. Each layer should have a single, well-defined responsibility. Never allow business logic to leak into presentation or infrastructure layers.
Guidelines:
Design ports to expose only the methods needed by the domain. Follow the Interface Segregation Principle by creating focused, role-specific interfaces rather than large, monolithic ones.
Guidelines:
Organize code by business domain rather than technical layers. Each domain module should be cohesive and loosely coupled from other domains.
Guidelines:
Circular dependencies between modules indicate design issues. While forwardRef provides a technical solution, it's important to analyze the root cause.
Warning Signs:
Solutions:
Architecture should facilitate testing, not hinder it. Ports enable easy mocking, but only if designed properly.
Common Issues:
Solutions:
Not every interaction needs a port-adapter pair. Over-engineering leads to unnecessary complexity.
When to Avoid:
Balance:
Layer separation and indirection can introduce overhead. Monitor and optimize where necessary.
Considerations:
Optimization Strategies: