[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6H9W9BS4218HB62WXR2DFFD":3,"skill-same:01M6H9W9BS4218HB62WXR2DFFD":55},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":26,"linkOnly":27,"markdownContent":28,"markdownBody":29,"frontMatter":30,"refName":33,"commitSha":34,"skillDirectory":35,"forksCount":14,"repositoryHtmlUrl":36,"repositoryHomepageUrl":6,"ownerHtmlUrl":37,"ownerBlogUrl":38,"ownerDescription":39,"updatedAt":40,"install":41,"resources":54},"01M6H9W9BS4218HB62WXR2DFFD","hexagonal-architecture",null,"Hexagonal architecture patterns and implementation","NeuralBlitz\u002FMito","NeuralBlitz","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F79354388?v=4","01M6H8T2TFH477HRS0KTSTKR2E","David Riggs","01M6H8T2YQQDXPYM092P670Z21",0,"MIT","https:\u002F\u002Fgithub.com\u002FNeuralBlitz\u002FMito\u002Fblob\u002Fmain\u002F.opencode\u002Fskills\u002Fhexagonal-architecture\u002FSKILL.md",[],[19,20,21,22,23,24,25],"architecture","hexagonal architecture","hexagonal","architecture patterns","opencode","implementation","patterns","2026-11-10 10:12:30",false,"---\nname: hexagonal-architecture\ndescription: Hexagonal architecture patterns and implementation\nlicense: MIT\ncompatibility: opencode\nmetadata:\n  audience: developers\n  category: architecture\n---\n## What I do\n- Design ports and adapters architecture\n- Implement domain-driven design\n- Create dependency inversion layers\n- Structure applications for testability\n- Handle external dependencies\n- Design clear boundaries\n- Implement application services\n- Manage domain models\n\n## When to use me\nWhen designing application architecture or refactoring to hexagonal architecture.\n\n## Hexagonal Architecture Overview\n```\n┌─────────────────────────────────────────────────────────────────┐\n│                     External Layers                              │\n│                                                                  │\n│  ┌─────────────┐  ┌─────────────┐  ┌─────────────┐            │\n│  │   Web\u002FAPI   │  │   CLI       │  │   Tests     │            │\n│  │  Adapters   │  │  Adapter    │  │  Adapters   │            │\n│  └──────┬──────┘  └──────┬──────┘  └──────┬──────┘            │\n│         │                │                │                     │\n│         └────────────────┼────────────────┘                     │\n│                          │                                      │\n│              ┌───────────▼───────────┐                          │\n│              │      Adapters          │                          │\n│              │  (Infrastructure)      │                          │\n│              └───────────┬───────────┘                          │\n│                          │                                       │\n├──────────────────────────┼──────────────────────────────────────┤\n│           Application    │    Domain Layer                       │\n│                          │                                       │\n│  ┌───────────────────────▼───────────────────────┐              │\n│  │              Ports (Interfaces)               │              │\n│  │                                              │              │\n│  │  Inbound Ports:     │    Outbound Ports:      │              │\n│  │  - Use Cases       │    - Repositories       │              │\n│  │  - Services       │    - External Services   │              │\n│  │                   │    - Event Publishers   │              │\n│  └───────────────────┼─────────────────────────┘              │\n│                      │                                          │\n│       ┌──────────────▼──────────────┐                           │\n│       │      Domain Models         │                            │\n│       │                            │                            │\n│       │  - Entities                │                            │\n│       │  - Value Objects           │                            │\n│       │  - Aggregates              │                            │\n│       │  - Domain Events           │                            │\n│       │  - Domain Services         │                            │\n│       └────────────────────────────┘                            │\n│                                                                  │\n├────────────────────────────────────────────────────────────────┤\n│                     External Systems                             │\n│  ┌─────────────┐  ┌─────────────┐  ┌─────────────┐            │\n│  │  Database   │  │   Cache     │  │   APIs      │            │\n│  └─────────────┘  └─────────────┘  └─────────────┘            │\n└────────────────────────────────────────────────────────────────┘\n```\n\n## Domain Layer\n```python\nfrom dataclasses import dataclass\nfrom datetime import datetime\nfrom typing import List, Optional\nfrom abc import ABC, abstractmethod\nimport uuid\n\n\n# Value Objects\n@dataclass(frozen=True)\nclass Email:\n    \"\"\"Email value object.\"\"\"\n    value: str\n    \n    def __post_init__(self):\n        if '@' not in self.value:\n            raise ValueError(f\"Invalid email: {self.value}\")\n\n\n@dataclass(frozen=True)\nclass Money:\n    \"\"\"Money value object with currency.\"\"\"\n    amount: float\n    currency: str\n    \n    def __post_init__(self):\n        if self.amount \u003C 0:\n            raise ValueError(\"Amount cannot be negative\")\n    \n    def add(self, other: 'Money') -> 'Money':\n        if self.currency != other.currency:\n            raise ValueError(\"Cannot add different currencies\")\n        return Money(self.amount + other.amount, self.currency)\n\n\n# Entities\nclass User:\n    \"\"\"User entity with identity and behavior.\"\"\"\n    \n    def __init__(\n        self,\n        email: Email,\n        name: str,\n        id: str = None,\n        created_at: datetime = None,\n    ):\n        self.id = id or str(uuid.uuid4())\n        self._email = email\n        self.name = name\n        self.created_at = created_at or datetime.utcnow()\n        self._events: List[DomainEvent] = []\n    \n    @property\n    def email(self) -> Email:\n        return self._email\n    \n    def change_email(self, new_email: Email) -> None:\n        \"\"\"Change email with validation.\"\"\"\n        if new_email == self._email:\n            return\n        \n        self._email = new_email\n        self._events.append(UserEmailChanged(self.id, new_email))\n    \n    def pull_events(self) -> List[DomainEvent]:\n        \"\"\"Get domain events.\"\"\"\n        events = self._events.copy()\n        self._events.clear()\n        return events\n\n\n# Domain Events\nclass DomainEvent:\n    \"\"\"Base domain event.\"\"\"\n    \n    def __init__(self, aggregate_id: str):\n        self.aggregate_id = aggregate_id\n        self.occurred_at = datetime.utcnow()\n\n\nclass UserCreated(DomainEvent):\n    \"\"\"User was created.\"\"\"\n    \n    def __init__(self, user_id: str, email: Email, name: str):\n        super().__init__(user_id)\n        self.email = email\n        self.name = name\n\n\nclass UserEmailChanged(DomainEvent):\n    \"\"\"User email was changed.\"\"\"\n    \n    def __init__(self, user_id: str, new_email: Email):\n        super().__init__(user_id)\n        self.new_email = new_email\n\n\n# Aggregates\nclass Order:\n    \"\"\"Order aggregate root.\"\"\"\n    \n    def __init__(\n        self,\n        user: User,\n        items: List['OrderItem'],\n        id: str = None,\n    ):\n        self.id = id or str(uuid.uuid4())\n        self.user = user\n        self.items = items\n        self.status = OrderStatus.DRAFT\n        self.created_at = datetime.utcnow()\n        self._events: List[DomainEvent] = []\n    \n    @property\n    def total(self) -> Money:\n        \"\"\"Calculate order total.\"\"\"\n        total = sum(item.price.amount for item in self.items)\n        return Money(total, 'USD')\n    \n    def submit(self) -> None:\n        \"\"\"Submit order.\"\"\"\n        if not self.items:\n            raise ValueError(\"Cannot submit empty order\")\n        \n        self.status = OrderStatus.SUBMITTED\n        self._events.append(OrderSubmitted(self.id))\n    \n    def pull_events(self) -> List[DomainEvent]:\n        events = self._events.copy()\n        self._events.clear()\n        return events\n\n\n@dataclass\nclass OrderItem:\n    \"\"\"Order item value object.\"\"\"\n    product_id: str\n    name: str\n    quantity: int\n    price: Money\n\n\nclass OrderStatus:\n    \"\"\"Order status enum.\"\"\"\n    DRAFT = \"draft\"\n    SUBMITTED = \"submitted\"\n    PAID = \"paid\"\n    SHIPPED = \"shipped\"\n    DELIVERED = \"delivered\"\n    CANCELLED = \"cancelled\"\n```\n\n## Ports (Interfaces)\n```python\nfrom abc import ABC\nfrom typing import List, Optional\n\n\n# Inbound Ports (Application Services)\nclass UserServicePort(ABC):\n    \"\"\"Inbound port for user operations.\"\"\"\n    \n    @abstractmethod\n    def create_user(self, email: str, name: str) -> User:\n        \"\"\"Create a new user.\"\"\"\n        pass\n    \n    @abstractmethod\n    def get_user(self, user_id: str) -> Optional[User]:\n        \"\"\"Get user by ID.\"\"\"\n        pass\n    \n    @abstractmethod\n    def change_user_email(\n        self,\n        user_id: str,\n        new_email: str\n    ) -> User:\n        \"\"\"Change user email.\"\"\"\n        pass\n\n\n# Outbound Ports (Repositories)\nclass UserRepositoryPort(ABC):\n    \"\"\"Outbound port for user persistence.\"\"\"\n    \n    @abstractmethod\n    def save(self, user: User) -> User:\n        \"\"\"Save user.\"\"\"\n        pass\n    \n    @abstractmethod\n    def find_by_id(self, user_id: str) -> Optional[User]:\n        \"\"\"Find user by ID.\"\"\"\n        pass\n    \n    @abstractmethod\n    def exists_by_email(self, email: Email) -> bool:\n        \"\"\"Check if email exists.\"\"\"\n        pass\n\n\n# Outbound Ports (External Services)\nclass EmailServicePort(ABC):\n    \"\"\"Outbound port for sending emails.\"\"\"\n    \n    @abstractmethod\n    def send_email(\n        self,\n        to: Email,\n        subject: str,\n        body: str\n    ) -> None:\n        \"\"\"Send email.\"\"\"\n        pass\n\n\n# Outbound Ports (Event Publishing)\nclass EventPublisherPort(ABC):\n    \"\"\"Outbound port for publishing domain events.\"\"\"\n    \n    @abstractmethod\n    def publish(self, event: DomainEvent) -> None:\n        \"\"\"Publish domain event.\"\"\"\n        pass\n    \n    @abstractmethod\n    def publish_all(self, events: List[DomainEvent]) -> None:\n        \"\"\"Publish multiple events.\"\"\"\n        pass\n```\n\n## Application Service\n```python\nfrom dataclasses import dataclass\n\n\n@dataclass\nclass CreateUserInput:\n    \"\"\"Input for creating a user.\"\"\"\n    email: str\n    name: str\n\n\n@dataclass\nclass ChangeEmailInput:\n    \"\"\"Input for changing email.\"\"\"\n    user_id: str\n    new_email: str\n\n\nclass UserApplicationService:\n    \"\"\"\n    Application service implementing UserServicePort.\n    \n    Coordinates between inbound ports (use cases) and \n    outbound ports (infrastructure).\n    \"\"\"\n    \n    def __init__(\n        self,\n        user_repository: UserRepositoryPort,\n        email_service: EmailServicePort,\n        event_publisher: EventPublisherPort,\n    ):\n        self.user_repository = user_repository\n        self.email_service = email_service\n        self.event_publisher = event_publisher\n    \n    def create_user(self, input: CreateUserInput) -> User:\n        \"\"\"Create a new user.\"\"\"\n        # Validate email doesn't exist\n        email = Email(input.email)\n        if self.user_repository.exists_by_email(email):\n            raise ValueError(f\"Email already exists: {input.email}\")\n        \n        # Create user (domain logic)\n        user = User(\n            email=email,\n            name=input.name,\n        )\n        \n        # Save to persistence (through port)\n        saved_user = self.user_repository.save(user)\n        \n        # Get domain events\n        events = saved_user.pull_events()\n        \n        # Publish events (through port)\n        self.event_publisher.publish_all(events)\n        \n        # Send welcome email (through port)\n        self.email_service.send_email(\n            to=email,\n            subject=\"Welcome!\",\n            body=f\"Hi {input.name}, welcome to our platform!\"\n        )\n        \n        return saved_user\n    \n    def change_user_email(\n        self,\n        input: ChangeEmailInput\n    ) -> User:\n        \"\"\"Change user email.\"\"\"\n        # Get user\n        user = self.user_repository.find_by_id(input.user_id)\n        if not user:\n            raise ValueError(f\"User not found: {input.user_id}\")\n        \n        # Validate new email\n        new_email = Email(input.new_email)\n        if self.user_repository.exists_by_email(new_email):\n            raise ValueError(f\"Email already exists: {input.new_email}\")\n        \n        # Change email (domain logic)\n        user.change_email(new_email)\n        \n        # Save\n        saved_user = self.user_repository.save(user)\n        \n        # Publish events\n        events = saved_user.pull_events()\n        self.event_publisher.publish_all(events)\n        \n        return saved_user\n    \n    def get_user(self, user_id: str) -> Optional[User]:\n        \"\"\"Get user by ID.\"\"\"\n        return self.user_repository.find_by_id(user_id)\n```\n\n## Adapters\n```python\nfrom sqlalchemy.orm import Session\n\n\n# Database Adapter (Implements UserRepositoryPort)\nclass SQLUserRepository(UserRepositoryPort):\n    \"\"\"SQLAlchemy implementation of user repository.\"\"\"\n    \n    def __init__(self, session: Session):\n        self.session = session\n    \n    def save(self, user: User) -> User:\n        \"\"\"Save user to database.\"\"\"\n        from infrastructure.persistence.user_entity import UserEntity\n        \n        # Convert domain to entity\n        entity = UserEntity.from_domain(user)\n        \n        self.session.add(entity)\n        self.session.commit()\n        self.session.refresh(entity)\n        \n        return entity.to_domain()\n    \n    def find_by_id(self, user_id: str) -> Optional[User]:\n        \"\"\"Find user by ID.\"\"\"\n        from infrastructure.persistence.user_entity import UserEntity\n        \n        entity = self.session.query(UserEntity).filter(\n            UserEntity.id == user_id\n        ).first()\n        \n        return entity.to_domain() if entity else None\n    \n    def exists_by_email(self, email: Email) -> bool:\n        \"\"\"Check if email exists.\"\"\"\n        from infrastructure.persistence.user_entity import UserEntity\n        \n        count = self.session.query(UserEntity).filter(\n            UserEntity.email == email.value\n        ).count()\n        \n        return count > 0\n\n\n# Email Adapter (Implements EmailServicePort)\nclass SMTPEmailService(EmailServicePort):\n    \"\"\"SMTP implementation of email service.\"\"\"\n    \n    def __init__(self, smtp_host: str, smtp_port: int):\n        self.smtp_host = smtp_host\n        self.smtp_port = smtp_port\n    \n    def send_email(\n        self,\n        to: Email,\n        subject: str,\n        body: str\n    ) -> None:\n        \"\"\"Send email via SMTP.\"\"\"\n        import smtplib\n        from email.mime.text import MIMEText\n        \n        msg = MIMEText(body)\n        msg['Subject'] = subject\n        msg['From'] = \"noreply@example.com\"\n        msg['To'] = to.value\n        \n        with smtplib.SMTP(self.smtp_host, self.smtp_port) as server:\n            server.send_message(msg)\n\n\n# HTTP Adapter (Inbound Adapter)\nfrom fastapi import FastAPI, Depends\n\n\napp = FastAPI()\n\n\ndef get_user_service() -> UserApplicationService:\n    \"\"\"Get user service from DI container.\"\"\"\n    # In production, use proper DI container\n    from main import container\n    return container.resolve(UserApplicationService)\n\n\n@app.post(\"\u002Fusers\")\ndef create_user(\n    input: CreateUserInput,\n    service: UserApplicationService = Depends(get_user_service)\n):\n    \"\"\"Create user via HTTP.\"\"\"\n    try:\n        user = service.create_user(input)\n        return {\"id\": user.id, \"email\": user.email.value}\n    except ValueError as e:\n        return {\"error\": str(e)}, 400\n```\n\n## Dependency Injection Setup\n```python\nfrom dependency_injector import containers, providers\n\n\nclass Container(containers.DeclarativeContainer):\n    \"\"\"DI container for the application.\"\"\"\n    \n    # Configuration\n    config = providers.Configuration()\n    \n    # Database\n    database_session = providers.Singleton(\n        create_database_session,\n        url=config.database.url,\n    )\n    \n    # Repositories\n    user_repository = providers.Factory(\n        SQLUserRepository,\n        session=database_session,\n    )\n    \n    # Services\n    email_service = providers.Singleton(\n        SMTPEmailService,\n        smtp_host=config.email.smtp_host,\n        smtp_port=config.email.smtp_port,\n    )\n    \n    event_publisher = providers.Singleton(\n        KafkaEventPublisher,\n        bootstrap_servers=config.kafka.servers,\n    )\n    \n    # Application Services\n    user_service = providers.Factory(\n        UserApplicationService,\n        user_repository=user_repository,\n        email_service=email_service,\n        event_publisher=event_publisher,\n    )\n\n\n# Bootstrap\ndef create_container() -> Container:\n    container = Container()\n    container.config.from_yaml(\"config.yaml\")\n    return container\n```\n\n## Best Practices\n```\n1. Keep domain pure\n   No dependencies on infrastructure\n   No I\u002FO in domain models\n\n2. Define clear ports\n   Separate inbound (use cases) from outbound (persistence)\n\n3. Invert dependencies\n   Domain depends on abstractions\n   Infrastructure depends on domain\n\n4. Aggregate design\n   One aggregate root per transaction\n   References by ID only\n\n5. Domain events\n   Capture state changes as events\n   Decouple through events\n\n6. Application services\n   Orchestrate domain objects\n   Handle transactions\n\n7. Testability\n   Mock all outbound ports\n   Test domain logic in isolation\n\n8. Single responsibility\n   Each port has one purpose\n   Each adapter implements one port\n```\n","## What I do\n- Design ports and adapters architecture\n- Implement domain-driven design\n- Create dependency inversion layers\n- Structure applications for testability\n- Handle external dependencies\n- Design clear boundaries\n- Implement application services\n- Manage domain models\n\n## When to use me\nWhen designing application architecture or refactoring to hexagonal architecture.\n\n## Hexagonal Architecture Overview\n```\n┌─────────────────────────────────────────────────────────────────┐\n│                     External Layers                              │\n│                                                                  │\n│  ┌─────────────┐  ┌─────────────┐  ┌─────────────┐            │\n│  │   Web\u002FAPI   │  │   CLI       │  │   Tests     │            │\n│  │  Adapters   │  │  Adapter    │  │  Adapters   │            │\n│  └──────┬──────┘  └──────┬──────┘  └──────┬──────┘            │\n│         │                │                │                     │\n│         └────────────────┼────────────────┘                     │\n│                          │                                      │\n│              ┌───────────▼───────────┐                          │\n│              │      Adapters          │                          │\n│              │  (Infrastructure)      │                          │\n│              └───────────┬───────────┘                          │\n│                          │                                       │\n├──────────────────────────┼──────────────────────────────────────┤\n│           Application    │    Domain Layer                       │\n│                          │                                       │\n│  ┌───────────────────────▼───────────────────────┐              │\n│  │              Ports (Interfaces)               │              │\n│  │                                              │              │\n│  │  Inbound Ports:     │    Outbound Ports:      │              │\n│  │  - Use Cases       │    - Repositories       │              │\n│  │  - Services       │    - External Services   │              │\n│  │                   │    - Event Publishers   │              │\n│  └───────────────────┼─────────────────────────┘              │\n│                      │                                          │\n│       ┌──────────────▼──────────────┐                           │\n│       │      Domain Models         │                            │\n│       │                            │                            │\n│       │  - Entities                │                            │\n│       │  - Value Objects           │                            │\n│       │  - Aggregates              │                            │\n│       │  - Domain Events           │                            │\n│       │  - Domain Services         │                            │\n│       └────────────────────────────┘                            │\n│                                                                  │\n├────────────────────────────────────────────────────────────────┤\n│                     External Systems                             │\n│  ┌─────────────┐  ┌─────────────┐  ┌─────────────┐            │\n│  │  Database   │  │   Cache     │  │   APIs      │            │\n│  └─────────────┘  └─────────────┘  └─────────────┘            │\n└────────────────────────────────────────────────────────────────┘\n```\n\n## Domain Layer\n```python\nfrom dataclasses import dataclass\nfrom datetime import datetime\nfrom typing import List, Optional\nfrom abc import ABC, abstractmethod\nimport uuid\n\n\n# Value Objects\n@dataclass(frozen=True)\nclass Email:\n    \"\"\"Email value object.\"\"\"\n    value: str\n    \n    def __post_init__(self):\n        if '@' not in self.value:\n            raise ValueError(f\"Invalid email: {self.value}\")\n\n\n@dataclass(frozen=True)\nclass Money:\n    \"\"\"Money value object with currency.\"\"\"\n    amount: float\n    currency: str\n    \n    def __post_init__(self):\n        if self.amount \u003C 0:\n            raise ValueError(\"Amount cannot be negative\")\n    \n    def add(self, other: 'Money') -> 'Money':\n        if self.currency != other.currency:\n            raise ValueError(\"Cannot add different currencies\")\n        return Money(self.amount + other.amount, self.currency)\n\n\n# Entities\nclass User:\n    \"\"\"User entity with identity and behavior.\"\"\"\n    \n    def __init__(\n        self,\n        email: Email,\n        name: str,\n        id: str = None,\n        created_at: datetime = None,\n    ):\n        self.id = id or str(uuid.uuid4())\n        self._email = email\n        self.name = name\n        self.created_at = created_at or datetime.utcnow()\n        self._events: List[DomainEvent] = []\n    \n    @property\n    def email(self) -> Email:\n        return self._email\n    \n    def change_email(self, new_email: Email) -> None:\n        \"\"\"Change email with validation.\"\"\"\n        if new_email == self._email:\n            return\n        \n        self._email = new_email\n        self._events.append(UserEmailChanged(self.id, new_email))\n    \n    def pull_events(self) -> List[DomainEvent]:\n        \"\"\"Get domain events.\"\"\"\n        events = self._events.copy()\n        self._events.clear()\n        return events\n\n\n# Domain Events\nclass DomainEvent:\n    \"\"\"Base domain event.\"\"\"\n    \n    def __init__(self, aggregate_id: str):\n        self.aggregate_id = aggregate_id\n        self.occurred_at = datetime.utcnow()\n\n\nclass UserCreated(DomainEvent):\n    \"\"\"User was created.\"\"\"\n    \n    def __init__(self, user_id: str, email: Email, name: str):\n        super().__init__(user_id)\n        self.email = email\n        self.name = name\n\n\nclass UserEmailChanged(DomainEvent):\n    \"\"\"User email was changed.\"\"\"\n    \n    def __init__(self, user_id: str, new_email: Email):\n        super().__init__(user_id)\n        self.new_email = new_email\n\n\n# Aggregates\nclass Order:\n    \"\"\"Order aggregate root.\"\"\"\n    \n    def __init__(\n        self,\n        user: User,\n        items: List['OrderItem'],\n        id: str = None,\n    ):\n        self.id = id or str(uuid.uuid4())\n        self.user = user\n        self.items = items\n        self.status = OrderStatus.DRAFT\n        self.created_at = datetime.utcnow()\n        self._events: List[DomainEvent] = []\n    \n    @property\n    def total(self) -> Money:\n        \"\"\"Calculate order total.\"\"\"\n        total = sum(item.price.amount for item in self.items)\n        return Money(total, 'USD')\n    \n    def submit(self) -> None:\n        \"\"\"Submit order.\"\"\"\n        if not self.items:\n            raise ValueError(\"Cannot submit empty order\")\n        \n        self.status = OrderStatus.SUBMITTED\n        self._events.append(OrderSubmitted(self.id))\n    \n    def pull_events(self) -> List[DomainEvent]:\n        events = self._events.copy()\n        self._events.clear()\n        return events\n\n\n@dataclass\nclass OrderItem:\n    \"\"\"Order item value object.\"\"\"\n    product_id: str\n    name: str\n    quantity: int\n    price: Money\n\n\nclass OrderStatus:\n    \"\"\"Order status enum.\"\"\"\n    DRAFT = \"draft\"\n    SUBMITTED = \"submitted\"\n    PAID = \"paid\"\n    SHIPPED = \"shipped\"\n    DELIVERED = \"delivered\"\n    CANCELLED = \"cancelled\"\n```\n\n## Ports (Interfaces)\n```python\nfrom abc import ABC\nfrom typing import List, Optional\n\n\n# Inbound Ports (Application Services)\nclass UserServicePort(ABC):\n    \"\"\"Inbound port for user operations.\"\"\"\n    \n    @abstractmethod\n    def create_user(self, email: str, name: str) -> User:\n        \"\"\"Create a new user.\"\"\"\n        pass\n    \n    @abstractmethod\n    def get_user(self, user_id: str) -> Optional[User]:\n        \"\"\"Get user by ID.\"\"\"\n        pass\n    \n    @abstractmethod\n    def change_user_email(\n        self,\n        user_id: str,\n        new_email: str\n    ) -> User:\n        \"\"\"Change user email.\"\"\"\n        pass\n\n\n# Outbound Ports (Repositories)\nclass UserRepositoryPort(ABC):\n    \"\"\"Outbound port for user persistence.\"\"\"\n    \n    @abstractmethod\n    def save(self, user: User) -> User:\n        \"\"\"Save user.\"\"\"\n        pass\n    \n    @abstractmethod\n    def find_by_id(self, user_id: str) -> Optional[User]:\n        \"\"\"Find user by ID.\"\"\"\n        pass\n    \n    @abstractmethod\n    def exists_by_email(self, email: Email) -> bool:\n        \"\"\"Check if email exists.\"\"\"\n        pass\n\n\n# Outbound Ports (External Services)\nclass EmailServicePort(ABC):\n    \"\"\"Outbound port for sending emails.\"\"\"\n    \n    @abstractmethod\n    def send_email(\n        self,\n        to: Email,\n        subject: str,\n        body: str\n    ) -> None:\n        \"\"\"Send email.\"\"\"\n        pass\n\n\n# Outbound Ports (Event Publishing)\nclass EventPublisherPort(ABC):\n    \"\"\"Outbound port for publishing domain events.\"\"\"\n    \n    @abstractmethod\n    def publish(self, event: DomainEvent) -> None:\n        \"\"\"Publish domain event.\"\"\"\n        pass\n    \n    @abstractmethod\n    def publish_all(self, events: List[DomainEvent]) -> None:\n        \"\"\"Publish multiple events.\"\"\"\n        pass\n```\n\n## Application Service\n```python\nfrom dataclasses import dataclass\n\n\n@dataclass\nclass CreateUserInput:\n    \"\"\"Input for creating a user.\"\"\"\n    email: str\n    name: str\n\n\n@dataclass\nclass ChangeEmailInput:\n    \"\"\"Input for changing email.\"\"\"\n    user_id: str\n    new_email: str\n\n\nclass UserApplicationService:\n    \"\"\"\n    Application service implementing UserServicePort.\n    \n    Coordinates between inbound ports (use cases) and \n    outbound ports (infrastructure).\n    \"\"\"\n    \n    def __init__(\n        self,\n        user_repository: UserRepositoryPort,\n        email_service: EmailServicePort,\n        event_publisher: EventPublisherPort,\n    ):\n        self.user_repository = user_repository\n        self.email_service = email_service\n        self.event_publisher = event_publisher\n    \n    def create_user(self, input: CreateUserInput) -> User:\n        \"\"\"Create a new user.\"\"\"\n        # Validate email doesn't exist\n        email = Email(input.email)\n        if self.user_repository.exists_by_email(email):\n            raise ValueError(f\"Email already exists: {input.email}\")\n        \n        # Create user (domain logic)\n        user = User(\n            email=email,\n            name=input.name,\n        )\n        \n        # Save to persistence (through port)\n        saved_user = self.user_repository.save(user)\n        \n        # Get domain events\n        events = saved_user.pull_events()\n        \n        # Publish events (through port)\n        self.event_publisher.publish_all(events)\n        \n        # Send welcome email (through port)\n        self.email_service.send_email(\n            to=email,\n            subject=\"Welcome!\",\n            body=f\"Hi {input.name}, welcome to our platform!\"\n        )\n        \n        return saved_user\n    \n    def change_user_email(\n        self,\n        input: ChangeEmailInput\n    ) -> User:\n        \"\"\"Change user email.\"\"\"\n        # Get user\n        user = self.user_repository.find_by_id(input.user_id)\n        if not user:\n            raise ValueError(f\"User not found: {input.user_id}\")\n        \n        # Validate new email\n        new_email = Email(input.new_email)\n        if self.user_repository.exists_by_email(new_email):\n            raise ValueError(f\"Email already exists: {input.new_email}\")\n        \n        # Change email (domain logic)\n        user.change_email(new_email)\n        \n        # Save\n        saved_user = self.user_repository.save(user)\n        \n        # Publish events\n        events = saved_user.pull_events()\n        self.event_publisher.publish_all(events)\n        \n        return saved_user\n    \n    def get_user(self, user_id: str) -> Optional[User]:\n        \"\"\"Get user by ID.\"\"\"\n        return self.user_repository.find_by_id(user_id)\n```\n\n## Adapters\n```python\nfrom sqlalchemy.orm import Session\n\n\n# Database Adapter (Implements UserRepositoryPort)\nclass SQLUserRepository(UserRepositoryPort):\n    \"\"\"SQLAlchemy implementation of user repository.\"\"\"\n    \n    def __init__(self, session: Session):\n        self.session = session\n    \n    def save(self, user: User) -> User:\n        \"\"\"Save user to database.\"\"\"\n        from infrastructure.persistence.user_entity import UserEntity\n        \n        # Convert domain to entity\n        entity = UserEntity.from_domain(user)\n        \n        self.session.add(entity)\n        self.session.commit()\n        self.session.refresh(entity)\n        \n        return entity.to_domain()\n    \n    def find_by_id(self, user_id: str) -> Optional[User]:\n        \"\"\"Find user by ID.\"\"\"\n        from infrastructure.persistence.user_entity import UserEntity\n        \n        entity = self.session.query(UserEntity).filter(\n            UserEntity.id == user_id\n        ).first()\n        \n        return entity.to_domain() if entity else None\n    \n    def exists_by_email(self, email: Email) -> bool:\n        \"\"\"Check if email exists.\"\"\"\n        from infrastructure.persistence.user_entity import UserEntity\n        \n        count = self.session.query(UserEntity).filter(\n            UserEntity.email == email.value\n        ).count()\n        \n        return count > 0\n\n\n# Email Adapter (Implements EmailServicePort)\nclass SMTPEmailService(EmailServicePort):\n    \"\"\"SMTP implementation of email service.\"\"\"\n    \n    def __init__(self, smtp_host: str, smtp_port: int):\n        self.smtp_host = smtp_host\n        self.smtp_port = smtp_port\n    \n    def send_email(\n        self,\n        to: Email,\n        subject: str,\n        body: str\n    ) -> None:\n        \"\"\"Send email via SMTP.\"\"\"\n        import smtplib\n        from email.mime.text import MIMEText\n        \n        msg = MIMEText(body)\n        msg['Subject'] = subject\n        msg['From'] = \"noreply@example.com\"\n        msg['To'] = to.value\n        \n        with smtplib.SMTP(self.smtp_host, self.smtp_port) as server:\n            server.send_message(msg)\n\n\n# HTTP Adapter (Inbound Adapter)\nfrom fastapi import FastAPI, Depends\n\n\napp = FastAPI()\n\n\ndef get_user_service() -> UserApplicationService:\n    \"\"\"Get user service from DI container.\"\"\"\n    # In production, use proper DI container\n    from main import container\n    return container.resolve(UserApplicationService)\n\n\n@app.post(\"\u002Fusers\")\ndef create_user(\n    input: CreateUserInput,\n    service: UserApplicationService = Depends(get_user_service)\n):\n    \"\"\"Create user via HTTP.\"\"\"\n    try:\n        user = service.create_user(input)\n        return {\"id\": user.id, \"email\": user.email.value}\n    except ValueError as e:\n        return {\"error\": str(e)}, 400\n```\n\n## Dependency Injection Setup\n```python\nfrom dependency_injector import containers, providers\n\n\nclass Container(containers.DeclarativeContainer):\n    \"\"\"DI container for the application.\"\"\"\n    \n    # Configuration\n    config = providers.Configuration()\n    \n    # Database\n    database_session = providers.Singleton(\n        create_database_session,\n        url=config.database.url,\n    )\n    \n    # Repositories\n    user_repository = providers.Factory(\n        SQLUserRepository,\n        session=database_session,\n    )\n    \n    # Services\n    email_service = providers.Singleton(\n        SMTPEmailService,\n        smtp_host=config.email.smtp_host,\n        smtp_port=config.email.smtp_port,\n    )\n    \n    event_publisher = providers.Singleton(\n        KafkaEventPublisher,\n        bootstrap_servers=config.kafka.servers,\n    )\n    \n    # Application Services\n    user_service = providers.Factory(\n        UserApplicationService,\n        user_repository=user_repository,\n        email_service=email_service,\n        event_publisher=event_publisher,\n    )\n\n\n# Bootstrap\ndef create_container() -> Container:\n    container = Container()\n    container.config.from_yaml(\"config.yaml\")\n    return container\n```\n\n## Best Practices\n```\n1. Keep domain pure\n   No dependencies on infrastructure\n   No I\u002FO in domain models\n\n2. Define clear ports\n   Separate inbound (use cases) from outbound (persistence)\n\n3. Invert dependencies\n   Domain depends on abstractions\n   Infrastructure depends on domain\n\n4. Aggregate design\n   One aggregate root per transaction\n   References by ID only\n\n5. Domain events\n   Capture state changes as events\n   Decouple through events\n\n6. Application services\n   Orchestrate domain objects\n   Handle transactions\n\n7. Testability\n   Mock all outbound ports\n   Test domain logic in isolation\n\n8. Single responsibility\n   Each port has one purpose\n   Each adapter implements one port\n```\n",{"name":5,"license":15,"metadata":31,"description":7,"compatibility":23},{"audience":32,"category":19},"developers","main","2ea764e153842704d24a2e9aa4170441a7f03081",".opencode\u002Fskills\u002Fhexagonal-architecture","https:\u002F\u002Fgithub.com\u002FNeuralBlitz\u002FMito","https:\u002F\u002Fgithub.com\u002FNeuralBlitz","nuralnexus.org","Independent Multidisciplinary Researcher, Creative Producer, and AI Systems Architect\r\nAn independent creator and research-driven systems designer.","2026-11-12 03:13:05",{"source":8,"skillName":5,"commands":42,"prompt":52,"zipAvailable":53},[43,46,49],{"tool":44,"command":45},"npx","npx skills add NeuralBlitz\u002FMito --skill hexagonal-architecture",{"tool":47,"command":48},"bunx","bunx skills add NeuralBlitz\u002FMito --skill hexagonal-architecture",{"tool":50,"command":51},"pnpm","pnpm dlx skills add NeuralBlitz\u002FMito --skill hexagonal-architecture","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FNeuralBlitz\u002FMito\u002Fblob\u002Fmain\u002F.opencode\u002Fskills\u002Fhexagonal-architecture\u002FSKILL.md",true,[],[56,72,84,97,105,120],{"skillNo":57,"name":58,"nameZh":6,"description":59,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":60,"categories":61,"keywords":62,"publishedAt":26},"01M6HAZSAQK1S27CEZYAYJTQDX","wireless-communications","Wireless systems, mobile networks, and 5G\u002F6G","https:\u002F\u002Fgithub.com\u002FNeuralBlitz\u002FMito\u002Fblob\u002Fmain\u002F.opencode\u002Fskills\u002Fwireless-communications\u002FSKILL.md",[],[63,64,65,66,67,68,69,70,23,71],"communications","wireless communications","wireless","systems","engineering","networks","5G","students","mobile",{"skillNo":73,"name":74,"nameZh":6,"description":75,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":76,"categories":77,"keywords":78,"publishedAt":26},"01M6HAZFX6E8NK3WZWDX5YCKYY","websockets","WebSocket implementation and best practices","https:\u002F\u002Fgithub.com\u002FNeuralBlitz\u002FMito\u002Fblob\u002Fmain\u002F.opencode\u002Fskills\u002Fwebassembly\u002Fwebsockets\u002FSKILL.md",[],[74,79,80,24,23,81,82,83],"websocket implementation","time","real-time","websocket","best practices",{"skillNo":85,"name":86,"nameZh":6,"description":87,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":88,"categories":89,"keywords":90,"publishedAt":26},"01M6HAZ6DAXBQ7QHXXM1EM7715","vulnerability-auditing","Vulnerability assessment and auditing","https:\u002F\u002Fgithub.com\u002FNeuralBlitz\u002FMito\u002Fblob\u002Fmain\u002F.opencode\u002Fskills\u002Fvulnerability-auditing\u002FSKILL.md",[],[91,92,93,94,23,95,96],"vulnerability","vulnerability auditing","security","vulnerability assessment","cybersecurity","assessment",{"skillNo":98,"name":99,"nameZh":6,"description":100,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":101,"categories":102,"keywords":103,"publishedAt":26},"01M6HAZ3FKF3CS9Z3J96RVE2ZE","vulnerability-assessment","Finding and assessing security vulnerabilities","https:\u002F\u002Fgithub.com\u002FNeuralBlitz\u002FMito\u002Fblob\u002Fmain\u002F.opencode\u002Fskills\u002Fvue\u002Fvulnerability-assessment\u002FSKILL.md",[],[94,91,96,93,104,23],"vulnerabilities",{"skillNo":106,"name":107,"nameZh":6,"description":108,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":109,"categories":110,"keywords":111,"publishedAt":26},"01M6HAYSHM6HKRKEHFP0SGZQX7","vlsi-design","Very-Large-Scale Integration circuit design and semiconductor engineering","https:\u002F\u002Fgithub.com\u002FNeuralBlitz\u002FMito\u002Fblob\u002Fmain\u002F.opencode\u002Fskills\u002Fvlsi-design\u002FSKILL.md",[],[112,113,114,115,116,67,117,23,118,70,119],"vlsi design","VLSI","design","hardware","integration","computer","scale","circuit",{"skillNo":121,"name":122,"nameZh":6,"description":123,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":124,"categories":125,"keywords":126,"publishedAt":26},"01M6HAYPQ30FFE2JXD7WQJ8R6C","unsupervised","Unsupervised learning concepts","https:\u002F\u002Fgithub.com\u002FNeuralBlitz\u002FMito\u002Fblob\u002Fmain\u002F.opencode\u002Fskills\u002Fvisualization\u002Funsupervised\u002FSKILL.md",[],[122,127,23,128,129,130,131,132],"learning","intelligence","unsupervised learning","machine","concepts","machine-learning"]