Inbound port contracts — the driving side of hexagonal architecture.
Inbound ports are called by infrastructure into the application core.
They define the boundary where external actors invoke application logic.
InboundPort
Bases: Port
ABC for inbound port contracts.
Responsibilities
- Define the driving-side boundary of the application core.
- Enforce that concrete inbound ports do not depend on other
inbound ports via __init_subclass__ validation.
Non-Responsibilities
- Does NOT perform structural duck-typing — returns
NotImplemented from __subclasshook__.
Example
class CreateUserPort(InboundPort):
def __init__(self, repo: "OutboundPort") -> None: ...
def execute(self, name: str) -> str: ...
# __init_subclass__ validates that every __init__
# parameter is an OutboundPort, never an InboundPort.
Source code in src/forging_blocks/foundation/ports/_inbound_port.py
| class InboundPort(Port):
"""ABC for inbound port contracts.
Responsibilities:
- Define the driving-side boundary of the application core.
- Enforce that concrete inbound ports do not depend on other
inbound ports via ``__init_subclass__`` validation.
Non-Responsibilities:
- Does NOT perform structural duck-typing — returns
``NotImplemented`` from ``__subclasshook__``.
Example:
```python
class CreateUserPort(InboundPort):
def __init__(self, repo: "OutboundPort") -> None: ...
def execute(self, name: str) -> str: ...
# __init_subclass__ validates that every __init__
# parameter is an OutboundPort, never an InboundPort.
```
"""
@classmethod
@runtime_final
def __init_subclass__(cls, /) -> None:
""" """
super().__init_subclass__()
if not AbstractPortClassifier(cls).is_abstract():
InboundDependencyValidator(cls, target_port=InboundPort).validate()
|
__init_subclass__() -> None
classmethod
Source code in src/forging_blocks/foundation/ports/_inbound_port.py
| @classmethod
@runtime_final
def __init_subclass__(cls, /) -> None:
""" """
super().__init_subclass__()
if not AbstractPortClassifier(cls).is_abstract():
InboundDependencyValidator(cls, target_port=InboundPort).validate()
|