YouBothAgent▾
You — Business rules and flows you own. Read these yourself.
Both — Know the idea; your agent follows the details.
Agent — Conventions and references your agent follows. Look up as needed.
Introduction▾
Tutorials▾
System Architecture▾
Module Convention▾
Scalar Convention▾
Interact in Service
When an order comes in, you need to inform the staff so that they can make ice cream, and when the ice cream is made, you need to notify the customer. Also, if the ice cream melts, you need to notify the customer again if they don't pick it up for a long time.
To achieve this, you need to add a service that sends periodic warnings if a served order is not finished, and a service that sends an alert message to the customer to remind them to pick up the order.
Declare Adapter
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 /nest folder as follows.
apps/koyo/nest/alarmApi.ts
Then, export the module in the /nest/index.ts file.
apps/koyo/nest/index.ts


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
Use External API
Now, in order to inject the adapter for the alarm into the server, you need to declare and register the adapter to be injected in the option.ts file.
apps/koyo/lib/option.ts
Now, you can inject the alarmApi in the icecreamOrderService and use it.
apps/koyo/lib/icecreamOrder/icecreamOrder.service.ts
Query in Document
Now, let's add a service function that sends a warning message if a served order is not finished. For easy testing, let's send a warning message after 15 seconds if the order is served.
apps/koyo/lib/icecreamOrder/icecreamOrder.service.ts
However, how can we query only the served icecream orders? To do this, let's create a list query function by utilizing the feature of creating a query based on the given conditions in the icecreamOrder.document file.
Now, let's apply the query to the document.
apps/koyo/lib/icecreamOrder/icecreamOrder.document.ts
By declaring the byStatuses query in IcecreamOrderFilter, you can use list, find, count, sample functions according to the given query conditions. For example, you can use listByStatuses, countByStatuses functions.


Why do we receive an array of statuses instead of a single status? This is useful when we need to query multiple statuses at once. If we think there is a possibility of querying multiple statuses, it is better to receive them as an array and process them.
Use Interval
Now, let's use interval to execute the service every 15 seconds. The interval trigger is a trigger that works internally, and can be declared in IcecreamOrderInternal.
apps/koyo/lib/icecreamOrder/icecreamOrder.signal.ts
Now, you can see the warning message printed to the console if the order is served for more than 15 seconds.


Signal file is a file that declares triggers for executing service functions, and Signal has Internal, Endpoint, Slice classes.
Internal is a class that declares triggers for executing service functions, and has init, interval, cron, queue, etc. triggers.