First, let's start by connecting an external API or module like an alert. You can connect an api that sends messages or emails, but in this tutorial, we'll create an api that simply prints to the console and connect it.
Modules like service, signal, document should not be directly connected to external systems, but rather created as adapters that are injected. First, let's create an adapter in the /srvkit folder as follows.
Then, export the module in the /srvkit/index.ts file.
Why use the adapter pattern? By injecting external dependencies as adapters rather than directly importing them in services, you gain several benefits:
(1) Testability - you can easily mock or replace the adapter in tests without modifying the service code
(2) Flexibility - you can swap implementations (e.g., switch from console logging to email notifications) without changing the service logic
(3) Separation of Concerns - the service focuses on business logic while adapters handle external interactions
(4) Reusability - the same adapter can be injected and shared across multiple services