clean-arch-knowledge

Clean Architecture knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for Clean Architecture and Hexagonal Architecture audits.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "clean-arch-knowledge" with this command: npx skills add dykyi-roman/awesome-claude-code/dykyi-roman-awesome-claude-code-clean-arch-knowledge

Clean Architecture Knowledge Base

Quick reference for Clean Architecture / Hexagonal Architecture patterns and PHP implementation guidelines.

Core Principles

The Dependency Rule

┌────────────────────────────────────────────────────────────────┐
│                    FRAMEWORKS & DRIVERS                        │
│  (Web, UI, DB, External Services, Devices)                     │
├────────────────────────────────────────────────────────────────┤
│                    INTERFACE ADAPTERS                          │
│  (Controllers, Gateways, Presenters, Repositories)             │
├────────────────────────────────────────────────────────────────┤
│                    APPLICATION BUSINESS RULES                  │
│  (Use Cases, Application Services)                             │
├────────────────────────────────────────────────────────────────┤
│                    ENTERPRISE BUSINESS RULES                   │
│  (Entities, Value Objects, Domain Services)                    │
└────────────────────────────────────────────────────────────────┘
                              ▲
                              │
              Dependencies point INWARD only

Rule: Source code dependencies must point INWARD. Inner layers know nothing about outer layers.

Hexagonal Architecture (Ports & Adapters)

                    ┌─────────────────┐
                    │   Primary       │
                    │   Adapters      │
                    │  (Controllers)  │
                    └────────┬────────┘
                             │
                             ▼
                    ┌─────────────────┐
        ┌──────────►│     PORTS       │◄──────────┐
        │           │  (Interfaces)   │           │
        │           └────────┬────────┘           │
        │                    │                    │
        │                    ▼                    │
        │           ┌─────────────────┐           │
        │           │   APPLICATION   │           │
        │           │    (Use Cases)  │           │
        │           └────────┬────────┘           │
        │                    │                    │
        │                    ▼                    │
        │           ┌─────────────────┐           │
        │           │     DOMAIN      │           │
        │           │   (Entities)    │           │
        │           └─────────────────┘           │
        │                                         │
        │           ┌─────────────────┐           │
        └───────────│   Secondary     │───────────┘
                    │   Adapters      │
                    │ (Repositories,  │
                    │  External APIs) │
                    └─────────────────┘

Rule: Application core defines Ports (interfaces). Adapters implement them.

Quick Checklists

Domain Layer Checklist

  • No imports from outer layers
  • No framework dependencies
  • Pure business logic
  • Value Objects for concepts
  • Entities with behavior
  • Repository interfaces only

Application Layer Checklist

  • Use Cases orchestrate domain
  • Defines Ports (interfaces) for external services
  • DTOs for input/output
  • No infrastructure details
  • No framework dependencies

Interface Adapters Checklist

  • Implements domain/application interfaces
  • Controllers call Use Cases
  • Presenters format output
  • No business logic

Frameworks & Drivers Checklist

  • Configuration only
  • Wiring/DI setup
  • Framework-specific code isolated

Common Violations Quick Reference

ViolationWhere to LookSeverity
Inner layer imports outerDomain/Application importing InfrastructureCritical
Framework in coreDoctrine/Symfony in DomainCritical
Use Case with HTTP detailsRequest/Response in ApplicationCritical
Business logic in Controllerif/switch on domain stateWarning
Missing PortDirect external service callWarning
Adapter with logicRepository doing validationWarning

PHP 8.4 Clean Architecture Patterns

Port (Driven Port)

// Application layer - defines the contract
namespace Application\Order\Port;

interface PaymentGatewayInterface
{
    public function charge(PaymentRequest $request): PaymentResponse;
    public function refund(string $transactionId, Money $amount): RefundResponse;
}

Adapter (Driven Adapter)

// Infrastructure layer - implements the contract
namespace Infrastructure\Payment;

final readonly class StripePaymentGateway implements PaymentGatewayInterface
{
    public function __construct(
        private StripeClient $stripe
    ) {}

    public function charge(PaymentRequest $request): PaymentResponse
    {
        $charge = $this->stripe->charges->create([
            'amount' => $request->amount->cents(),
            'currency' => $request->currency->value,
            'source' => $request->token,
        ]);

        return new PaymentResponse(
            transactionId: $charge->id,
            status: PaymentStatus::from($charge->status)
        );
    }
}

Use Case (Application Service)

namespace Application\Order\UseCase;

final readonly class ProcessPaymentUseCase
{
    public function __construct(
        private OrderRepositoryInterface $orders,
        private PaymentGatewayInterface $paymentGateway,  // Port
        private EventDispatcherInterface $events
    ) {}

    public function execute(ProcessPaymentCommand $command): PaymentResult
    {
        $order = $this->orders->findById($command->orderId);

        $payment = $this->paymentGateway->charge(
            new PaymentRequest($order->total(), $command->paymentToken)
        );

        if ($payment->isSuccessful()) {
            $order->markAsPaid($payment->transactionId());
            $this->orders->save($order);
        }

        return new PaymentResult($payment->transactionId(), $payment->status());
    }
}

Controller (Driving Adapter)

namespace Presentation\Api\Order;

final readonly class PaymentController
{
    public function __construct(
        private ProcessPaymentUseCase $processPayment
    ) {}

    public function process(Request $request): JsonResponse
    {
        $command = new ProcessPaymentCommand(
            orderId: new OrderId($request->get('order_id')),
            paymentToken: $request->get('payment_token')
        );

        $result = $this->processPayment->execute($command);

        return new JsonResponse([
            'transaction_id' => $result->transactionId,
            'status' => $result->status->value,
        ]);
    }
}

References

For detailed information, load these reference files:

  • references/dependency-rule.md — The Dependency Rule explained
  • references/layer-boundaries.md — Layer responsibilities and boundaries
  • references/port-adapter-patterns.md — Hexagonal Architecture patterns
  • references/antipatterns.md — Common violations with detection patterns

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Coding

detect-code-smells

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

ddd-knowledge

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

testing-knowledge

No summary provided by upstream source.

Repository SourceNeeds Review