Aller au contenu principal

notifications

Status: implemented (services/notifications, contract: docs/dev/phase4-contracts.md, Notifications service; specs: features.md "Notifications"). Runs in the apps profile of docker-compose.yml on port 8089 (metrics 9189) and is reached through the gateway route /v1/notifications. /internal/v1/alerts is never routed.

Role: turns platform events (Kafka), monitoring alerts and broadcasts into notifications and delivers them on the channels chosen by each user: in_app (notification centre), email (SMTP), discord (webhook) and webhook (signed CloudEvent). Users manage their preferences and personal webhooks; organisation webhooks and broadcasts are permission-gated.

Limits: no browser push (refusing browser notifications never matters). External borrowers (non-members) are not notified (their contact stays encrypted in borrowing). Recipients granted a permission only through the default user role are not enumerated (see LookupSubjects).

Flow​

Sources and recipients​

TypeSourceRecipientsDefault channels
borrowing.due_soon, borrowing.overdueborrowing.reminder.due_soon / overduemember borrowerin_app, email
borrowing.approval_requestedborrowing.sheet.submittedholders of borrowing.sheet.approve on the sheetin_app
inventory.stock_lowinventory.stock.lowholders of inventory.issue.handle on the sitein_app
inventory.issue_reportedinventory.issue.reportedholders of inventory.issue.handle on the issuein_app
inventory.maintenance_dueinventory.maintenance.task_dueassignee + holders of inventory.maintenance.manage on the planin_app
finance.purchase_requestedfinance.purchase.requestedholders of finance.purchase.approve on the purchase (site, project)in_app, email
finance.purchase_decidedfinance.purchase.approved / refusedrequesterin_app, email
finance.expense_submittedfinance.expense.submittedholders of finance.expense.approve on the claimin_app, email
finance.expense_decidedfinance.expense.approved / refusedrequesterin_app, email
finance.invoice_paidfinance.invoice.payment_applied (status paid)invoice creator (actor of finance.invoice.created, remembered)in_app
bank.consent_expiring, bank.consent_expiredbank.connection.consent_expiring / expiredholders of finance.account.manage on the sitein_app, email
members.training_expiringpolled GET /v1/members/trainings/expiring (daily, TRAINING_NOTICE)memberin_app, email
projects.member_addedprojects.project.member_addedadded memberin_app
events.public_event_createdevents.event.created (visibility public)users who opted innone (opt-in)
monitoring.alertAlertmanager webhookholders of notifications.broadcast.send + ALERT_EMAILin_app, email
notifications.broadcastnotifications.broadcast.created (own topic)every active member (directory)in_app

The user who caused an event is never notified of it. Consumers ignore unknown fields and unknown event types, validate identifiers and accept the French status values still emitted by finance (payee, facture). Organisation webhooks only receive the types flagged organization (no personal data).

Delivery​

  • Idempotency: in-app notifications are unique per (event, user); deliveries per <event>|<recipient>|<channel> (recipient = user, webhook or alert_list).
  • Queue: the deliveries collection. A lease job (notifications-deliveries, every DELIVERY_INTERVAL) claims due deliveries atomically, sends them, retries failures after DELIVERY_BACKOFF × 2^(attempt-1) (capped by DELIVERY_MAX_BACKOFF) and marks them failed after DELIVERY_MAX_ATTEMPTS or on permanent errors (4xx, no address, webhook gone), publishing notifications.delivery.failed. E-mails are spaced by EMAIL_RATE_INTERVAL.
  • E-mail: address (workspace_email) and locale read from members at send time with the service principal (memory cache CONTACT_CACHE_TTL, never stored). Multipart text + HTML (html/template), FR/EN. Port 465 uses implicit TLS, other ports STARTTLS when offered; PLAIN auth when SMTP_USER is set.
  • Discord: embed with title, body and link, mentions disabled.
  • Webhook: CloudEvent JSON (application/cloudevents+json, type atl.notification.<type>, id = delivery ID), X-Atl-Signature: sha256=<hex HMAC-SHA256(secret, body)>, X-Atl-Delivery. Verify the signature on the raw body before parsing.
  • SSRF: webhook calls refuse loopback, private, link-local and CGNAT destinations and never follow redirects (WEBHOOK_ALLOW_PRIVATE / WEBHOOK_ALLOW_HTTP for development only, refused in production).
  • Secrets: webhook URLs and signing secrets are sealed with the keyring (subject = webhook ID); deleting a webhook shreds its key. The secret is shown once (creation, rotation).

API​

See the API reference. Lists are cursor-paginated, newest first. Texts are rendered in ?locale=, then Accept-Language, then French.

EndpointPurpose
GET /v1/notifications, GET /unread-count, POST /{id}/read, POST /read-allNotification centre
GET/PUT /v1/notifications/preferencesChannels per type (null resets a type)
/v1/notifications/webhooks CRUD, POST /{id}/testPersonal (owner) and organisation (notifications.webhook.manage) webhooks
GET /v1/notifications/deliveriesDelivery log (own, or one manageable webhook)
GET/POST /v1/notifications/broadcastsBroadcasts (notifications.broadcast.send)
POST /internal/v1/alertsAlertmanager receiver (bearer ALERT_WEBHOOK_TOKEN when set)

Writes are audited (notifications.preference.update, notifications.webhook.*, notifications.broadcast.send, notifications.notification.read*, one notifications.notification.create per dispatched event, notifications.member.erase).

Kafka​

Consumer group notifications-sources on borrowing.reminder.v1, borrowing.sheet.v1, inventory.stock.v1, inventory.issue.v1, inventory.maintenance.v1, finance.purchase.v1, finance.expense.v1, finance.invoice.v1, bank.connection.v1, projects.project.v1, events.event.v1, members.member.v1, notifications.broadcast.v1. Produces notifications.broadcast.v1 and notifications.delivery.v1 (failed).

Erasure: members.member.erased deletes the member's notifications, preferences, deliveries, invoice-creator links and personal webhooks (keys shredded).

Data (MongoDB notifications)​

notifications, deliveries, webhooks, preferences (one document per user × type), broadcasts, invoice_creators, plus outbox, leases and the keyring collection.

Environment​

VariableDefaultPurpose
HTTP_ADDR / METRICS_ADDR:8089 / :9189Listeners
MONGO_URI, MONGO_DATABASEnotificationsDatabase
AUTHZ_URL, MEMBERS_URLlocalhostHolders (LookupSubjects), contacts, directory, trainings
PRINCIPAL_PUBLIC_KEY, PRINCIPAL_SIGNING_KEYrequiredVerify callers, sign the service principal
CRYPTO_KEK_SOURCE, CRYPTO_KEKKeyring
WEB_URLhttp://localhost:3000Absolute links in e-mails and webhooks
SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASSWORD, SMTP_FROM, SMTP_TIMEOUTe-mail disabled without host; 587SMTP relay (Mailpit locally, Google Workspace in production)
EMAIL_RATE_INTERVAL200msMinimum gap between e-mails
ALERT_EMAILemptyAlert mailing list (comma-separated)
ALERT_WEBHOOK_TOKENempty (required in production)Bearer token expected from Alertmanager
DELIVERY_INTERVAL, DELIVERY_MAX_ATTEMPTS, DELIVERY_BACKOFF, DELIVERY_MAX_BACKOFF, DELIVERY_BATCH5s, 8, 30s, 1h, 100Delivery queue
WEBHOOK_TIMEOUT, WEBHOOK_ALLOW_PRIVATE, WEBHOOK_ALLOW_HTTP10s, false, falseWebhook client
TRAINING_NOTICE, TRAINING_CHECK_INTERVAL720h, 24hTraining expiry job
BROADCAST_MAX_RECIPIENTS, CONTACT_CACHE_TTL5000, 10mLimits

Locally, e-mails go to Mailpit (mailpit service, UI http://localhost:8025).