hexagonal-architecture
Skill35 starsChanged 5 months agoMITView on GitHub
Use when structuring a Symfony app with ports & adapters / clean architecture — keeping the domain framework-free, defining interfaces (ports) in the domain and implementations (adapters) in infrastructure. Use when the task mentions hexagonal, ports/adapters, or "keep the domain pure".
24 other projects use a version of this.
Adopted by
Most recently taken up by
- Rojios/everything-claude-codetheir own version, first seen Nov 8, 2026
- Lukk17/agent-standardstheir own version, first seen Nov 7, 2026
- pankaj-mahaur/Agent-Daemontheir own version, first seen Nov 6, 2026
- nledford/engineering-review-boardtheir own version, first seen Nov 3, 2026
- zernie/vigilestheir own version, first seen Nov 1, 2026
- sandlada/skill-hexagonal-architecturetheir own version, first seen Oct 25, 2026
Used with
Projects with it also use clean-architecture, improve-codebase-architecture and 1 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
harrissohail6Skillclean-architecture
Clean architecture and SOLID principles. Auto-activates when designing systems or refactoring code structure.
Also in 3 projects that use this
GoogleSkillimprove-codebase-architecture
Scan a codebase for deepening opportunities, present them as a visual HTML report, then grill through whichever one you pick.
Also in 3 projects that use this
GoogleSkillgrill-me
A relentless interview to sharpen a plan or design.
Also in 3 projects that use this
Other versions24 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 24
- rrezartprebreza/spring-boot-skills★ 344same name
- yamcodes/arkenv★ 151same name
- Fmarzochi/EGC★ 61same name
- zernie/vigiles★ 15same name
- nledford/engineering-review-board★ 11same name
- gongyijie85/dsh-ecc★ 8same name
- kayaman/skills★ 3same name
- ankhorage/devtools★ 2same name
- ffsshhttiikk/opencode-agents-skills★ 2same name
- ronmkr/PromptBook★ 2same name
14 more not listed
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 repository16 other files it gives its agents.
- api-platform-resourcesSkill
- bundle-organizationSkill
- console-commandsSkill
- doctrine-migrationsSkill
- doctrine-ormSkill
- doctrine-query-optimizationSkill
- domain-driven-designSkill
- dto-and-validationSkill
- jwt-authenticationSkill
- layered-architectureSkill
- messenger-asyncSkill
- problem-details-rfc9457Skill
- rest-controller-conventionsSkill
- security-authenticationSkill
- testing-pyramidSkill
- transactional-patternsSkill
The file
We split this skill into the rules it gives an agent
1 rule. 0 are common, 0 are distinctive, and 1 is very specific to this project.
0
Common
Most of the 23 edited versions we read keep these.
0
Distinctive
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 108
Strict: keep the domain class pure and map it with XML mapping in Infrastructure/Persistence/Doctrine/Mapping/.
“Common” is measured: kept by at least 6 in 10 of the 23 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Hexagonal Architecture (Ports & Adapters)
When to reach for this. Hexagonal is for complex, long-lived domains where isolating business logic from the framework pays off — rich invariants, multiple delivery mechanisms, logic you expect to outlive the current stack. For typical CRUD and feature work (the ~80% of most apps), use
layered-architectureinstead; strict ports/adapters there is just overhead. Apply this to the gnarly 20% that earns it, not as a blanket rule.
The dependency rule
┌─────────────────────────────────────────┐
│ Infrastructure │ ← Symfony, Doctrine, HTTP, Messenger
│ (driving + driven adapters) │
│ ┌───────────────────────────────────┐ │
│ │ Application │ │ ← use cases / handlers
│ │ ┌───────────────────────────┐ │ │
│ │ │ Domain │ │ │ ← entities, value objects, ports
│ │ │ (no framework imports) │ │ │
│ │ └───────────────────────────┘ │ │
│ └───────────────────────────────────┘ │
└─────────────────────────────────────────┘Source code dependencies point inward. The domain knows nothing about Symfony, Doctrine, or HTTP. Outer layers depend on inner-layer interfaces, never the reverse.
Suggested package layout
src/
├── Domain/ # pure PHP — no Symfony/Doctrine "use" statements
│ ├── Order/
│ │ ├── Order.php # aggregate root (plain object, no #[ORM\...])
│ │ ├── OrderId.php # value object
│ │ ├── OrderStatus.php # enum
│ │ └── OrderRepository.php # PORT (interface)
├── Application/ # use cases — orchestrates domain via ports
│ └── Order/
│ ├── CreateOrderHandler.php
│ └── CreateOrderCommand.php
└── Infrastructure/ # adapters — implement ports using Symfony/Doctrine
├── Persistence/Doctrine/
│ ├── DoctrineOrderRepository.php # ADAPTER implements Domain\Order\OrderRepository
│ └── Mapping/Order.orm.xml # ORM mapping kept OUT of the domain class
└── Http/
└── CreateOrderController.php # driving adapterPorts live in the domain
A port is an interface the domain owns and the infrastructure implements.
// ✅ src/Domain/Order/OrderRepository.php — no framework imports
namespace App\Domain\Order;
interface OrderRepository
{
public function save(Order $order): void;
public function ofId(OrderId $id): ?Order;
}// ✅ src/Infrastructure/Persistence/Doctrine/DoctrineOrderRepository.php
namespace App\Infrastructure\Persistence\Doctrine;
use App\Domain\Order\Order;
use App\Domain\Order\OrderId;
use App\Domain\Order\OrderRepository;
use Doctrine\ORM\EntityManagerInterface;
final class DoctrineOrderRepository implements OrderRepository
{
public function __construct(private readonly EntityManagerInterface $em) {}
public function save(Order $order): void
{
$this->em->persist($order);
$this->em->flush();
}
public function ofId(OrderId $id): ?Order
{
return $this->em->find(Order::class, $id->toString());
}
}Wire the interface to the implementation in config/services.yaml:
services:
App\Domain\Order\OrderRepository: '@App\Infrastructure\Persistence\Doctrine\DoctrineOrderRepository'Keeping the domain framework-free
The hard part in Symfony is that Doctrine attribute mapping (#[ORM\Entity]) couples the entity to the ORM. Two acceptable strategies:
- Pragmatic (default): allow Doctrine attributes on the aggregate. You lose "zero framework imports" but keep one class. Fine for most teams.
- Strict: keep the domain class pure and map it with XML mapping in
Infrastructure/Persistence/Doctrine/Mapping/. The domain never imports Doctrine.
// ✅ STRICT — pure aggregate, mapped externally via XML
namespace App\Domain\Order;
final class Order
{
/** @var Collection<int, OrderLine>|OrderLine[] */
private array $lines = [];
private function __construct(
private readonly OrderId $id,
private OrderStatus $status,
) {}
public static function place(OrderId $id): self
{
return new self($id, OrderStatus::Pending); // invariant: new orders start Pending
}
}State the chosen strategy in the project README so the agent stays consistent.
Application layer = use cases
One handler per use case. It depends only on ports, never on adapters.
// ✅ src/Application/Order/CreateOrderHandler.php
namespace App\Application\Order;
use App\Domain\Order\Order;
use App\Domain\Order\OrderId;
use App\Domain\Order\OrderRepository;
final readonly class CreateOrderHandler
{
public function __construct(private OrderRepository $orders) {}
public function __invoke(CreateOrderCommand $command): OrderId
{
$order = Order::place(OrderId::generate());
$this->orders->save($order);
return $order->id();
}
}Driving adapters
Controllers, console commands, and Messenger handlers are driving adapters. They translate a delivery mechanism into an application call and translate the result back out. They contain no business logic.
Gotchas
- Agent puts
EntityManagerInterfaceinto the application/domain layer — depend on a repository port instead. - Agent imports
Symfony\…orDoctrine\…insrc/Domain/— the domain must stay framework-free (or use the agreed pragmatic exception for ORM attributes only). - Agent makes the application layer depend on the concrete
DoctrineOrderRepository— depend on the interface; wire it inservices.yaml. - Agent returns a Symfony
Responsefrom a use-case handler — return a domain value (ID, DTO); the controller builds the HTTP response. - Agent puts validation/HTTP concerns in the domain — those belong in adapters.
- Agent generates
#[ORM\Entity]on a "pure" domain class when the project chose the strict XML-mapping strategy — check the README's stated strategy first.
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.

