/

Ambitwin · source-available, not open source · © 2026 Nicolò Ghignatti

Notification

Keywords on this page
WordMeaningExample
BreachA value outside its limit31 °C, limit 28 °C
AlertWhat a person receives about a breach“Room 2 is too hot”
CooldownA pause during which repeats of one alert are muted5 minutes per room and field
Web PushBrowser notifications that arrive with no tab openPhone lock screen
Push subscriptionOne device’s address for Web PushAda’s laptop
Dead-letter topicWhere messages that cannot be handled waitalerts.dlq
System callerA service calling with no person behind itsystem:notification-service

Realises the Alerting domain. Rust, MongoDB, Redis. Code-level page: Notification Service.

Decides who should hear about a breach, then tells them twice: in the app and by Web Push.


Who talks to it

flowchart LR
    T["telemetry"] == "breaches" ==> N["notification"]
    Tw["digital-twin"] -- "upload failed" --> N
    C["client"] -- "devices, choices, test alert" --> N
    N -- "who owns this building?" --> Tw
    N -. "in-app alert" .-> S["socket"]
    N -- "Web Push" --> P["Push provider"]

Thick: Kafka. Thin: a request. Dotted: Redis.

Two things it keeps, kept apart:

KeptHoldsWhy apart
DevicesWhere each person can be reachedA lost phone is removed without losing choices
ChoicesWhat each person wants to hearChoices change without registering devices again

Inside

flowchart LR
    subgraph In["Driving adapters"]
        H["HTTP"]
        K["Kafka: alerts"]
    end
    subgraph Core["Use cases"]
        AL["Alerts: mute repeats, find owners, send"]
        PU["Push: pick devices, send, prune"]
        PR["Devices and choices"]
    end
    subgraph Out["Driven adapters"]
        DB[("MongoDB")]
        R["Redis: cooldown, in-app channel"]
        TW["digital-twin lookup"]
        WP["Web Push"]
    end
    H --> AL
    H --> PR
    K --> AL
    AL --> PU
    AL -.-> R & TW
    PU -.-> DB & WP
    PR -.-> DB

Two ways in, one alert logic. A test alert and a real breach go through the same steps.


A breach becomes an alert

flowchart TD
    In["Breach from Kafka"] --> M{"Muted? Same room and field in the last 5 min"}
    M -- "yes" --> Stop["Done, nothing sent"]
    M -- "no" --> L{"Who owns the building?"}
    L -- "lookup failed" --> DLQ["Parked on alerts.dlq, not muted"]
    L -- "no owner" --> Drop["Dropped, logged, muted"]
    L -- "owners" --> Send["In-app and Web Push to each owner organization"]
    Send --> Mute["Muted for 5 min"]
CaseWhy
Lookup failed: not mutedThe alert can be sent again once digital-twin is back
No owner: mutedEvery following tick would flood the log otherwise
Never sent with no organizationIt would reach every browser of every customer

Example. Room 2 reads 31 °C every 10 s, limit 28 °C. The first breach alerts at 10:00:00. The next 29 are muted. The one at 10:05:00 alerts again.

Watch the “failed” and “unroutable” counts: either means an alert reached nobody.


Finding the owners

socket keeps the same answer only 60 s. Different question: it decides who may read live data, so it needs to be fresher.


Who may receive

CallerGets alerts for
A person, through the test routeOwner organizations they belong to, nothing else
A system callerEvery owner organization

A system caller has no memberships. Filtering would drop everything, and the failed-upload alert from digital-twin would vanish. Only services inside the mesh can be a system caller: the edge strips the claims header from outside requests.

The system identity keeps an older name, system:notification-service, on purpose. It is checked byte for byte at a trust boundary.


Web Push


Gaps