hexagonal
Skill15 starsChanged 42 days agoMITView on GitHub
Expert Hexagonal Architecture (Ports and Adapters) assistance covering driving/driven ports, infrastructure adapters, domain core isolation, and test stubbing. Use when decoupling domain logic from databases/HTTP frameworks, improving testability, or modernizing enterprise applications.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- AnyOrgName/php-skillstheir own version, first seen Nov 8, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- AnyOrgName/php-skills★ 4same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository350 other files it gives its agents.
- airflowSkill
- catboostSkill
- claudeSkill
- comfyuiSkill
- cursor-aiSkill
- dalleSkill
- daskSkill
- dbtSkill
- deepseekSkill
- fastaiSkill
- geminiSkill
- github-copilotSkill
- huggingfaceSkill
- jaxSkill
- jupyterSkill
- kerasSkill
- langchainSkill
- lightgbmSkill
- llamaindexSkill
- llamaSkill
- matplotlibSkill
- midjourneySkill
- mistralSkill
- mlflowSkill
- nltkSkill
- numpySkill
- ollamaSkill
- openai-gptSkill
- opencvSkill
- pandasSkill
- perplexitySkill
- plotlySkill
- polarsSkill
- pytorchSkill
- raySkill
- scikit-learnSkill
- seabornSkill
- spacySkill
- sparkSkill
- stable-diffusionSkill
- tensorflowSkill
- vaexSkill
- weights-biasesSkill
- whisperSkill
- xgboostSkill
- api-gatewaySkill
- clean-architectureSkill
- cqrsSkill
- domain-driven-designSkill
- event-drivenSkill
- event-sourcingSkill
- graphqlSkill
- grpcSkill
- microservicesSkill
- modular-monolithSkill
- monolithSkill
- rest-apiSkill
- sagaSkill
- serverlessSkill
- service-meshSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 145
Create In-Memory Adapters for Fast Testing: Implement mock adapters for all driven ports to enable sub-second test suite runs.
- Distinctive: line 146
Keep Domain Core Pure: Disallow any external library imports in the domain core (except language utilities).
- Distinctive: line 147
Use Dependency Injection: Bind ports to concrete adapters at application bootstrap time.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
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
- Core Business Logic Isolation: Keeping domain models completely pure and independent of database choices, web frameworks, and messaging tools.
- Pluggable Architecture: Systems where components (e.g. storage engine, notification providers, payment gateways) must be easily swappable.
- Automated Regression Testing: Running full business scenario tests with fast, zero-dependency in-memory adapters.
- Microservice Reusability: Allowing the exact same business core to be driven by an HTTP REST controller, a gRPC server, and a CLI simultaneously.
Quick Start
// --- 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 and Adapters Topology
The application core sits at the center; Driving Ports receive input from the outside world; Driven Ports communicate with infrastructure:
[ HTTP Controller ] ──(Driving Port)──→ [ APPLICATION CORE ] ──(Driven Port)──→ [ Postgres Adapter ]
[ CLI Command ] ──(Driving Port)──→ [ APPLICATION CORE ] ──(Driven Port)──→ [ Mock DB Adapter ]Driving Port & Primary Adapter
The driving port defines what the application can do:
// core/ports/driving/register-user.port.ts
export interface RegisterUserCommand {
email: string;
fullName: string;
}
export interface RegisterUserUseCase {
execute(command: RegisterUserCommand): Promise<string>;
}// adapters/driving/http/user.controller.ts (Primary Adapter)
export class UserController {
constructor(private readonly registerUserUseCase: RegisterUserUseCase) {}
async handlePost(req: Request, res: Response) {
const userId = await this.registerUserUseCase.execute(req.body);
res.status(201).json({ id: userId });
}
}Driven Port & Secondary Adapter
The driven port defines external capabilities needed by the core:
// core/ports/driven/notification.port.ts
export interface NotificationPort {
sendWelcomeEmail(email: string, name: string): Promise<void>;
}
// adapters/driven/resend-email.adapter.ts (Secondary Adapter)
export class ResendEmailAdapter implements NotificationPort {
async sendWelcomeEmail(email: string, name: string) {
await resend.emails.send({
to: email,
subject: `Welcome, ${name}!`,
from: "app@example.com",
});
}
}Common Patterns
Mock Adapter for Unit Testing Ports
Problem: Testing business core without spinning up actual databases or message brokers.
Solution: Implement an in-memory stub that satisfies the driven port interface.
// test/mocks/in-memory-order.repository.ts
export class InMemoryOrderRepository implements OrderRepositoryPort {
private readonly items = new Map<string, Order>();
async save(order: Order): Promise<void> {
this.items.set(order.id, order);
}
async findById(id: string): Promise<Order | null> {
return this.items.get(id) ?? null;
}
}
// Unit test executes with zero I/O overhead:
const repo = new InMemoryOrderRepository();
const service = new OrderService(repo);Best Practices
Do:
- Define Ports as Interfaces Inside Core: Ensure driven ports are authored by the business domain team, not infrastructure engineers.
- Create In-Memory Adapters for Fast Testing: Implement mock adapters for all driven ports to enable sub-second test suite runs.
- Keep Domain Core Pure: Disallow any external library imports in the domain core (except language utilities).
- Use Dependency Injection: Bind ports to concrete adapters at application bootstrap time.
Don't:
- Let infrastructure types enter the domain: Map incoming database models and HTTP requests to domain types inside adapters.
- Bypass the ports: Never allow driving adapters (controllers) to communicate directly with driven adapters (databases).
- Over-engineer simple utility services: For simple scripts or read-only tools, Hexagonal Architecture adds unnecessary complexity.
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
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

