> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bbrands.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Notification architecture

> How Horizon turns a business fact into notifications: notify(), the event registry, occurrences, decisions and the notification core.

## What it is for

This page explains, for technical readers and curious operators, what happens between "a coupon was redeemed" and
"an email left". It replaces the old "Notifications (OneSignal)" introduction of Documentation, which described a
dispatcher that no longer sends anything.

![Diagram: a business flow calls notify with an event; an invalid payload leaves the occurrence rejected; a valid one records an occurrence, resolves the recipients and takes one decision per channel with the template and the rules; what is not sent keeps its reason in Traceability; each send goes through the queue and the lane of its channel to the provider, which reports delivery events that feed the timeline, the suppressions and the metrics.](https://mintcdn.com/bbrands/_njGa-AUVffoWNDA/images/notification-user-manual/notification-pipeline.svg?fit=max\&auto=format\&n=_njGa-AUVffoWNDA\&q=85\&s=cecf58e47e5c4fa095c0d086c98a9728)

From the business fact to the provider: occurrence, decisions, queue, lane and provider.

## The pieces

| Piece | What it does | Where you see it |
| - | - | - |
| Event | A declared business fact, with its key, category, channels, audience, data schema and default rules | [**Event catalog**](https://docs.bbrands.io/enterprise/notifications/catalog/list.md) and [Events](https://docs.bbrands.io/enterprise/notifications/events/index.md) |
| `notify()` | The only door producers use: "this event happened, with this data" | Nowhere; it is code |
| Occurrence | The record of one call to `notify()` | [**Traceability**](https://docs.bbrands.io/enterprise/notifications/operation/traceability.md) |
| Decision | What was resolved for one recipient on one channel, with its outcome and reason | The **Decisions** block of an occurrence |
| Send (notification) | One message to one recipient on one channel | [**Sends**](https://docs.bbrands.io/enterprise/notifications/operation/sends.md) |
| Queue and lane | Where sends wait and the pace at which each channel leaves | [**Queues**](https://docs.bbrands.io/enterprise/notifications/operation/queues.md) |
| Provider | Resend (email), OneSignal (push, SMS, Live Activities) or Horizon itself (in-app) | [**Delivery events**](https://docs.bbrands.io/enterprise/notifications/operation/delivery-events.md) |

## notify(): one door for every producer

A producer (the Club, payments, onboarding, a cron) never chooses a channel, a template or a text. It only says
which event happened and passes its data:

```ts theme={null}
await notify("club.coupon.redeemed", {
  account,
  subject: { id: couponAccount },
  data: { benefitTitle, merchantName, redeemedAt, couponUrl },
});
```

Everything else is configuration of the module: which channels are on, which template is published, which rules
apply. That is why a business unit can change a notification without a new version of the system.

| Entry | Used by |
| - | - |
| `notify(key, input)` | Horizon's own flows; the data type is checked against the event |
| `notifyByKey(key, input)` | Event items of the notification API and the sign-in emails of Supabase |
| `POST /api/v3/notification` | Integrations with an API key and a gateway (see [API and data model](https://docs.bbrands.io/enterprise/notifications/reference/api-integration.md)) |

## The event registry

Events are declared in the code, one file per domain, and copied to the catalog by a migration. The catalog can
switch an event or a channel on and off and adjust its rules; it cannot create events or change their data.

| Declared per event | Meaning |
| - | - |
| `key` | `domain.entity.action`, for example `club.coupon.redeemed`. Never changes |
| `category` | Security, transactional, payment, system or marketing. Decides which rules apply |
| `audience` | Who receives it: the account's logins, the account owner, one login, an address or a segment |
| `payloadSchema` | The data the event carries; the template variables come from here |
| `channels` | The channels it may use, whether each starts on, its template, delay, quiet hours, cap and fallback |
| `ttl` | Time to live: a send that cannot leave in time is skipped or expires |
| `sensitiveFields` | Fields stored as `[redacted]` in the occurrence |
| `optOutAble`, `bypass` | Whether the customer can turn it off, and which rules it skips |

## What happens on each call

1. **Event.** The key is looked up in the registry and the catalog. An unknown key is a programming error.
2. **Data.** The data is checked against the schema. Invalid data leaves the occurrence **Rejected** with the
   reason **Invalid data**, and nothing is sent.
3. **Occurrence.** The occurrence is recorded once per event and idempotency key. Calling again with the same key
   returns the first occurrence and sends nothing new.
4. **Event active.** An event turned off or deprecated skips every channel (**Event inactive**).
5. **Recipients.** The audience is resolved into people or addresses. None: **No recipient**.
6. **Language and timezone** of each recipient, from their account.
7. **Each channel and recipient**, in this order, where the first failure decides: channel on, published template,
   translation (Spanish if the language is missing), render, address, suppression, preference, frequency cap,
   quiet hours, delay. If everything passes, the send is written and queued (or scheduled).
8. **Fallback.** A channel declared as fallback of another runs only when that one was skipped or suppressed, or
   later fails at delivery.
9. **Close.** The occurrence ends **Completed** or **No send**, and later moves with its sends' delivery.

Each reason of steps 2 to 8 is explained in [States and reasons](https://docs.bbrands.io/enterprise/notifications/reference/states-and-reasons.md).

## Why it works this way

| Design | Why |
| - | - |
| One door (`notify()`) | Producers stay simple and every notification gets the same rules, traceability and metrics |
| One decision per channel and recipient, always with a reason | "Why did the customer not get it?" is answered on screen, without reading logs |
| The send id is derived from occurrence, channel and recipient | A retry after a crash never sends twice |
| Rules live in the catalog, events in the code | The business adjusts timing and content; the data contract stays reviewed by Technology |

## What changed from the old design

| Before (OneSignal era) | Now |
| - | - |
| Producers called `notificationDispatcher.enqueue` with a channel and a type | Producers call `notify()` with an event; the module chooses channels |
| Push, in-app, SMS and Live Activities through OneSignal only | Email through Resend, push, SMS and Live Activities through OneSignal, in-app stored by Horizon |
| A Vercel queue per message | A QStash topic with one lane per channel (see [Delivery pipeline](https://docs.bbrands.io/enterprise/notifications/reference/delivery-pipeline.md)) |
| Opt-out checked before enqueueing, no record of what was not sent | Every decision recorded with its reason |
| Categories `marketing`, `payment`, `system`, `transactional` | Plus `security`, which skips every rule |

The old dispatcher file still exists as a thin wrapper over the core and no production code calls it. Old-shape
queue messages are still translated for one more release.

## Technical detail

| Aspect | Detail |
| - | - |
| `notify()` | `backend/horizon-api/lib/notification/event/notify.ts`; engine `lib/notification/eligibility/notify-engine.ts` and `eligibility-pipeline.ts` |
| Event registry | `backend/horizon-api/lib/notification/event/registry/<domain>.events.ts`; types in `event/notification-event.types.ts`; catalog migration `pnpm notification:event-migration` |
| Occurrences and decisions | `backend/horizon-api/lib/notification/occurrence/`; tables `notification_occurrence` and `notification_occurrence_decision` |
| Notification core | `backend/horizon-api/lib/notification/core/notification-core.service.ts` (`submit`, `sendInternal`) and `notification-intake.ts` |
| Legacy shims | `lib/notification/notification-dispatcher.ts`, `core/notification-legacy.ts` |
| Full design | Initiative `notification/notification-platform` (`10-eligibility-engine.md`, `11-traceability.md`) and ADRs 0106 and 0130 |

## Related and history

* [Introduction to the module](https://docs.bbrands.io/enterprise/notifications/getting-started/introduction.md)
* [Delivery pipeline](https://docs.bbrands.io/enterprise/notifications/reference/delivery-pipeline.md)
* [States and reasons](https://docs.bbrands.io/enterprise/notifications/reference/states-and-reasons.md)

| Date | Change |
| - | - |
| 2026-11-11 | First version, rewritten from the old "Notifications (OneSignal)" introduction, which now redirects here |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.