Best use case
hexagonal is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Hexagonal architecture ports and adapters. Use for testable systems.
Teams using hexagonal should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/hexagonal/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How hexagonal Compares
| Feature / Agent | hexagonal | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Hexagonal architecture ports and adapters. Use for testable systems.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Hexagonal Architecture (Ports and Adapters)
Hexagonal Architecture aims to create a loosely coupled application component that can easily connect to their software environment by "ports" and "adapters". It treats the database, the web UI, and external APIs as interchangeable "details" (infrastructure).
## When to Use
- When you need to support multiple input channels (e.g., REST API, GraphQL, CLI, Message Queue) for the same business logic.
- When you want to be able to swap "driven" actors (e.g., verify logic with a Mock DB, then swap to Postgres).
- Developing standard microservices.
## Quick Start
```go
// --- CORE (Inside the Hexagon) ---
// Port (Driver Port - Input)
type UserService interface {
Register(name string) error
}
// Port (Driven Port - Output)
type UserRepository interface {
Save(user User) error
}
// Application Service (Implementation)
type UserServiceImpl struct {
repo UserRepository
}
func (s *UserServiceImpl) Register(name string) error {
return s.repo.Save(User{Name: name})
}
// --- ADAPTERS (Outside the Hexagon) ---
// Driving Adapter (REST API)
func HandleRegister(w http.ResponseWriter, r *http.Request, svc UserService) {
svc.Register(r.FormValue("name"))
}
// Driven Adapter (Postgres)
type PostgresRepo struct { db *sql.DB }
func (r *PostgresRepo) Save(u User) error { ... }
```
## Core Concepts
### Ports
Interfaces that define the entry and exit points of the application.
- **Driving Ports (In)**: API surfaces (what the app _can do_).
- **Driven Ports (Out)**: Infrastructure dependencies (what the app _needs_).
### Adapters
Concrete implementations that bridge the gap between the Ports and the outside world.
- **Driving Adapters**: REST Controller, gRPC Handler, CLI Command.
- **Driven Adapters**: SQL Repository, SMTP Client, Redis Cache.
## Common Patterns
### Testing with Fake Adapters
Because the core depends on interfaces (Ports), you can implement "Fake" adapters (e.g., `InMemoryRepository`) to test complex business logic without spinning up Docker containers.
## Best Practices
**Do**:
- Keep the **Core** free of any framework dependencies (no HTTP, no SQL, no JSON tags).
- Define **Ports** in the Core, not in the adapters.
- Use **Hexagonal** for the domain layer of a microservice.
**Don't**:
- Don't leak implementation details (like `sql.Rows`) into the Core.
- Don't create an Adapter for every single class; focus on architectural boundaries.
## Troubleshooting
| Error | Cause | Solution |
| :----------- | :--------------------------------------- | :------------------------------------------------------- |
| `Leakage` | Logic depends on specific library types. | Wrap external types in domain-specific DTOs/Interfaces. |
| `Complexity` | Too many interfaces for simple logic. | Start with a simple Service/Repository split and evolve. |
## References
- [Alistair Cockburn's Original Paper](https://alistair.cockburn.us/hexagonal-architecture/)
- [Hexagonal Architecture in Go](https://medium.com/@matiasvarela/hexagonal-architecture-in-go-cfd4e436bd57)Related Skills
template
Expert [skill-name] assistance covering [feature 1], [feature 2], and [feature 3]. Use when [working with X], [debugging Y], or [implementing Z].
zsh
Zsh shell with oh-my-zsh. Use for terminal shell.
zed
Zed high-performance collaborative editor. Use for fast editing.
xcode
Xcode Apple development IDE with simulators. Use for iOS/macOS development.
webstorm
WebStorm JavaScript IDE with debugging. Use for web development.
webpack
Webpack module bundler with loaders and plugins. Use for bundling.
warp
Warp modern terminal with AI. Use for terminal work.
vscode
Visual Studio Code editor with extensions and debugging. Use for code editing.
vite
Vite fast build tool with HMR. Use for modern frontend builds.
visual-studio
Visual Studio IDE for Windows with debugging and profiling. Use for .NET development.
vim
Vim text editor with motions, macros, and plugins. Use for terminal editing.
turbopack
Turbopack Rust-powered bundler. Use for fast builds.