Skip to content
cccskills
FreePublished on GitHub

acc-hexagonal-knowledge

Hexagonal Architecture (Ports & Adapters) knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for Hexagonal Architecture audits.

The English summary is being prepared. Showing the original description.

See how to install

Files included (1)

  • SKILL.md9.4 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

Hexagonal Architecture Knowledge Base

Quick reference for Hexagonal Architecture (Ports & Adapters) patterns and PHP implementation guidelines.

Core Principles

Hexagonal Architecture Overview

                         ┌─────────────────────────────┐
                         │      PRIMARY ACTORS         │
                         │   (Users, External Apps)    │
                         └──────────────┬──────────────┘
                                        │
                         ┌──────────────▼──────────────┐
                         │     DRIVING ADAPTERS        │
                         │  (Controllers, CLI, GUI,    │
                         │   Message Consumers)        │
                         └──────────────┬──────────────┘
                                        │
              ┌─────────────────────────▼─────────────────────────┐
              │                  DRIVING PORTS                     │
              │              (Input Interfaces)                    │
              └─────────────────────────┬─────────────────────────┘
                                        │
              ┌─────────────────────────▼─────────────────────────┐
              │                                                    │
              │              APPLICATION CORE                      │
              │     ┌─────────────────────────────────┐           │
              │     │       APPLICATION LAYER         │           │
              │     │      (Use Cases, Services)      │           │
              │     └─────────────────┬───────────────┘           │
              │                       │                            │
              │     ┌─────────────────▼───────────────┐           │
              │     │         DOMAIN LAYER            │           │
              │     │  (Entities, Value Objects,      │           │
              │     │   Domain Services)              │           │
              │     └─────────────────────────────────┘           │
              │                                                    │
              └─────────────────────────┬─────────────────────────┘
                                        │
              ┌─────────────────────────▼─────────────────────────┐
              │                  DRIVEN PORTS                      │
              │            (Output Interfaces)                     │
              └─────────────────────────┬─────────────────────────┘
                                        │
                         ┌──────────────▼──────────────┐
                         │      DRIVEN ADAPTERS        │
                         │  (Repositories, External    │
                         │   APIs, Message Publishers) │
                         └──────────────┬──────────────┘
                                        │
                         ┌──────────────▼──────────────┐
                         │     SECONDARY ACTORS        │
                         │  (Database, External APIs,  │
                         │   Message Queues)           │
                         └─────────────────────────────┘

Core Rule: Application Core defines Ports. Adapters implement or use them.

Key Concepts

ConceptDescriptionLocation
PortInterface defining how to interact with the coreApplication/Domain
Driving PortInput interface (how to use the application)Application layer
Driven PortOutput interface (what the application needs)Application/Domain
Driving AdapterImplements input mechanism (HTTP, CLI)Infrastructure
Driven AdapterImplements external dependenciesInfrastructure
Application CoreBusiness logic, isolated from I/ODomain + Application

Quick Checklists

Driving Port Checklist

  • Interface in Application layer
  • Defines use case boundary
  • Uses domain/application types
  • No framework types
  • Single responsibility

Driven Port Checklist

  • Interface in Application/Domain layer
  • Abstracts external dependency
  • Uses domain types for return values
  • No implementation details in signature
  • Can have multiple adapters

Driving Adapter Checklist

  • Implements/calls driving port
  • Converts external format to domain format
  • No business logic
  • Framework code contained here
  • One adapter per delivery mechanism

Driven Adapter Checklist

  • Implements driven port interface
  • Converts domain format to external format
  • No business logic
  • Handles external errors
  • Easily replaceable

Common Violations Quick Reference

ViolationWhere to LookSeverity
Core depends on adapterDomain importing InfrastructureCritical
Missing port abstractionDirect external service callCritical
Business logic in adapterif/switch in adapterCritical
Framework in coreSymfony/Laravel in DomainWarning
Port with implementation detailsInterface using DB typesWarning
Adapter without portController calling repository directlyWarning

PHP 8.5 Hexagonal Patterns

Driving Port (Use Case Interface)

<?php

declare(strict_types=1);

namespace Application\Order\Port\Input;

use Application\Order\DTO\CreateOrderRequest;
use Application\Order\DTO\CreateOrderResponse;

interface CreateOrderUseCaseInterface
{
    public function execute(CreateOrderRequest $request): CreateOrderResponse;
}

Driven Port (Repository Interface)

<?php

declare(strict_types=1);

namespace Domain\Order\Port\Output;

use Domain\Order\Entity\Order;
use Domain\Order\ValueObject\OrderId;

interface OrderRepositoryInterface
{
    public function findById(OrderId $id): ?Order;
    public function save(Order $order): void;
    public function nextIdentity(): OrderId;
}

Driving Adapter (HTTP Controller)

<?php

declare(strict_types=1);

namespace Infrastructure\Http\Controller;

use Application\Order\Port\Input\CreateOrderUseCaseInterface;
use Application\Order\DTO\CreateOrderRequest;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;

final readonly class CreateOrderController
{
    public function __construct(
        private CreateOrderUseCaseInterface $createOrder
    ) {}

    public function __invoke(Request $request): JsonResponse
    {
        $dto = CreateOrderRequest::fromArray($request->toArray());

        $response = $this->createOrder->execute($dto);

        return new JsonResponse($response->toArray(), 201);
    }
}

Driven Adapter (Repository Implementation)

<?php

declare(strict_types=1);

namespace Infrastructure\Persistence\Doctrine;

use Domain\Order\Entity\Order;
use Domain\Order\Port\Output\OrderRepositoryInterface;
use Domain\Order\ValueObject\OrderId;
use Doctrine\ORM\EntityManagerInterface;

final readonly class DoctrineOrderRepository implements OrderRepositoryInterface
{
    public function __construct(
        private EntityManagerInterface $em
    ) {}

    public function findById(OrderId $id): ?Order
    {
        return $this->em->find(Order::class, $id->value);
    }

    public function save(Order $order): void
    {
        $this->em->persist($order);
        $this->em->flush();
    }

    public function nextIdentity(): OrderId
    {
        return OrderId::generate();
    }
}

References

For detailed information, load these reference files:

  • references/ports-patterns.md — Driving and Driven Port patterns
  • references/adapters-patterns.md — Adapter implementation patterns
  • references/testing-patterns.md — Testing strategies for hexagonal architecture
  • references/antipatterns.md — Common violations with detection patterns

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

Master backend architectures, REST API design, microservices, and server-side development across multiple languages. Use this as a central index to access specialized sub-skills.

The English summary is being prepared. Showing the original description.

MikeCheng1208/BattleTree2Updated Jul 22, 2026

在每次回复中使用固定前缀并列出本次实际参考的指令/文件,便于校验是否遵循上下文与规则。

The English summary is being prepared. Showing the original description.

MikeCheng1208/BattleTree2Updated Jul 22, 2026

Automate 21risk tasks via Rube MCP (Composio). Always search tools first for current schemas.

The English summary is being prepared. Showing the original description.

MikeCheng1208/BattleTree2Updated Jul 22, 2026

Automate 2chat tasks via Rube MCP (Composio). Always search tools first for current schemas.

The English summary is being prepared. Showing the original description.

MikeCheng1208/BattleTree2Updated Jul 22, 2026

Arquitecto de Soluciones Principal y Consultor Tecnológico de Andru.ia. Diagnostica y traza la hoja de ruta óptima para proyectos de IA en español.

The English summary is being prepared. Showing the original description.

MikeCheng1208/BattleTree2Updated Jul 22, 2026

[00] META. Orchestrate skills into dynamic chains for complex tasks. Analyzes the task, discovers available skills, builds an optimal chain, explains why each skill is needed, and executes step-by-step with user confirmation. Use for any complex task requiring multiple thinking/research/analysis steps. Triggers on "plan this", "how to approach", "what's the strategy", "build a plan", or any multi-step problem requiring skill orchestration.

The English summary is being prepared. Showing the original description.

MikeCheng1208/BattleTree2Updated Jul 22, 2026

See all skills by MikeCheng1208

Report a problem with this skill