Integrating external services
While databases store our application state, external services enable our application to interact with the wider world by sending notifications, processing payments, or integrating with third-party APIs. Like databases, these services represent essential but volatile dependencies that must be managed carefully to maintain clean architectural boundaries.
External services in Clean Architecture
Recall from Chapter 5 that our Application layer defines ports which are interfaces that specify how our core application interacts with external services. The NotificationPort
interface exemplifies this approach:
class NotificationPort(ABC):
"""Interface for sending notifications about task events."""
@abstractmethod
def notify_task_completed(self, task: Task) -> None:
""...