# dieu-merci-ndenga/relay architecture

> Architecture diagram of the GitHub repository dieu-merci-ndenga/relay, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dieu-merci-ndenga/relay
- Repository: https://github.com/dieu-merci-ndenga/relay

## Overview

Relay is a webhook reliability service: providers submit signed events, the API validates and stores them idempotently, and asynchronous workers deliver them with retries and recorded outcomes. Operators can inspect attempts and dead letters, manually retry eligible events, and monitor metrics through the API and dashboard. PostgreSQL and Redis provide durable event state and queueing. The README documents dashboard capabilities and service interactions; some implementation wiring is unsampled, so those relationships are omitted or marked unverified rather than inferred.

Main entry points: [`src/app.controller.ts`](https://github.com/dieu-merci-ndenga/relay/blob/main/src/app.controller.ts) (HTTP API), [`src/app.service.ts`](https://github.com/dieu-merci-ndenga/relay/blob/main/src/app.service.ts) (Event orchestration), [`src/app.module.ts`](https://github.com/dieu-merci-ndenga/relay/blob/main/src/app.module.ts) (Runtime composition), [`src/delivery/delivery-processor.ts`](https://github.com/dieu-merci-ndenga/relay/blob/main/src/delivery/delivery-processor.ts) (Delivery processor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and operations"]
  node_controller["HTTP API<br/>[app.controller.ts]"]
  node_service["Event orchestration<br/>[app.service.ts]"]
  node_admin["Admin authorization<br/>[admin.guard.ts]"]
  node_signatures["Signature utilities<br/>[signature.ts]"]
  node_secrets["Secret configuration<br/>[secrets.ts]"]
  node_module["Runtime composition<br/>[app.module.ts]"]
end

subgraph group_state["Event state"]
  node_store_contract["Event store contract<br/>[event-store.ts]"]
  node_postgres_store["PostgreSQL event store"]
  node_memory_store["In-memory event store"]
  node_postgres[("PostgreSQL")]
  node_outbox["Outbox recovery<br/>[outbox-sweeper.ts]"]
end

subgraph group_delivery["Delivery processing"]
  node_queue_contract["Delivery queue contract<br/>[delivery-queue.ts]"]
  node_bull_queue["BullMQ queue"]
  node_memory_queue["In-memory queue"]
  node_redis["Redis queues"]
  node_worker["Queue worker"]
  node_processor["Delivery processor"]
end

subgraph group_observability["Console and metrics"]
  node_metrics["Prometheus metrics<br/>[metrics.service.ts]"]
  node_dashboard["Web console<br/>[app.js]"]
end

node_provider(("Webhook provider"))
node_receiver(("Downstream receiver"))
node_operator(("Operator"))

node_provider -->|"submits signed event"| node_controller
node_controller -->|"delegates requests"| node_service
node_controller -->|"checks metrics token"| node_signatures
node_controller -->|"guards operator routes"| node_admin
node_service -->|"validates webhook"| node_signatures
node_service -->|"stores and queries events"| node_store_contract
node_service -->|"enqueues deliveries"| node_queue_contract
node_service -->|"records ingestion"| node_metrics
node_module -->|"selects production store"| node_postgres_store
node_module -->|"selects test store"| node_memory_store
node_module -->|"selects production queue"| node_bull_queue
node_module -->|"selects test queue"| node_memory_queue
node_postgres_store -->|"persists event history"| node_postgres
node_outbox -->|"claims pending events"| node_store_contract
node_outbox -->|"re-enqueues events"| node_queue_contract
node_outbox -->|"records recovery"| node_metrics
node_bull_queue -->|"stores delivery jobs"| node_redis
node_worker -->|"processes jobs"| node_processor
node_worker -->|"consumes and schedules jobs"| node_redis
node_processor -->|"posts signed payload"| node_receiver
node_processor -->|"records attempts and dead letters"| node_store_contract
node_processor -->|"records delivery metrics"| node_metrics
node_operator -->|"uses console"| node_dashboard
node_dashboard -.->|"calls operator API"| node_controller
node_operator -->|"queries operational data"| node_controller
node_controller -->|"serves metrics"| node_metrics

click node_controller "https://github.com/dieu-merci-ndenga/relay/blob/main/src/app.controller.ts"
click node_service "https://github.com/dieu-merci-ndenga/relay/blob/main/src/app.service.ts"
click node_admin "https://github.com/dieu-merci-ndenga/relay/blob/main/src/admin.guard.ts"
click node_signatures "https://github.com/dieu-merci-ndenga/relay/blob/main/src/signature.ts"
click node_secrets "https://github.com/dieu-merci-ndenga/relay/blob/main/src/config/secrets.ts"
click node_module "https://github.com/dieu-merci-ndenga/relay/blob/main/src/app.module.ts"
click node_store_contract "https://github.com/dieu-merci-ndenga/relay/blob/main/src/events/event-store.ts"
click node_postgres_store "https://github.com/dieu-merci-ndenga/relay/blob/main/src/events/postgres-event.store.ts"
click node_memory_store "https://github.com/dieu-merci-ndenga/relay/blob/main/src/events/in-memory-event.store.ts"
click node_outbox "https://github.com/dieu-merci-ndenga/relay/blob/main/src/delivery/outbox-sweeper.ts"
click node_queue_contract "https://github.com/dieu-merci-ndenga/relay/blob/main/src/delivery/delivery-queue.ts"
click node_bull_queue "https://github.com/dieu-merci-ndenga/relay/blob/main/src/delivery/bullmq-delivery.queue.ts"
click node_memory_queue "https://github.com/dieu-merci-ndenga/relay/blob/main/src/delivery/in-memory-delivery.queue.ts"
click node_worker "https://github.com/dieu-merci-ndenga/relay/blob/main/src/delivery/bullmq-delivery.worker.ts"
click node_processor "https://github.com/dieu-merci-ndenga/relay/blob/main/src/delivery/delivery-processor.ts"
click node_metrics "https://github.com/dieu-merci-ndenga/relay/blob/main/src/metrics/metrics.service.ts"
click node_dashboard "https://github.com/dieu-merci-ndenga/relay/blob/main/frontend/app.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_controller,node_service,node_admin,node_signatures,node_secrets,node_module toneBlue
class node_store_contract,node_postgres_store,node_memory_store,node_postgres,node_outbox toneAmber
class node_queue_contract,node_bull_queue,node_memory_queue,node_redis,node_worker,node_processor,node_provider toneMint
class node_metrics,node_dashboard toneRose
class node_receiver,node_operator toneIndigo
```

## Components

### API and operations

- [HTTP API](https://github.com/dieu-merci-ndenga/relay/blob/main/src/app.controller.ts): `src/app.controller.ts`
- [Event orchestration](https://github.com/dieu-merci-ndenga/relay/blob/main/src/app.service.ts): `src/app.service.ts`
- [Admin authorization](https://github.com/dieu-merci-ndenga/relay/blob/main/src/admin.guard.ts): `src/admin.guard.ts`
- [Signature utilities](https://github.com/dieu-merci-ndenga/relay/blob/main/src/signature.ts): `src/signature.ts`
- [Secret configuration](https://github.com/dieu-merci-ndenga/relay/blob/main/src/config/secrets.ts): `src/config/secrets.ts`
- [Runtime composition](https://github.com/dieu-merci-ndenga/relay/blob/main/src/app.module.ts): `src/app.module.ts`

### Event state

- [Event store contract](https://github.com/dieu-merci-ndenga/relay/blob/main/src/events/event-store.ts): `src/events/event-store.ts`
- [PostgreSQL event store](https://github.com/dieu-merci-ndenga/relay/blob/main/src/events/postgres-event.store.ts): `src/events/postgres-event.store.ts`
- [In-memory event store](https://github.com/dieu-merci-ndenga/relay/blob/main/src/events/in-memory-event.store.ts): `src/events/in-memory-event.store.ts`
- **PostgreSQL**
- [Outbox recovery](https://github.com/dieu-merci-ndenga/relay/blob/main/src/delivery/outbox-sweeper.ts): `src/delivery/outbox-sweeper.ts`

### Delivery processing

- [Delivery queue contract](https://github.com/dieu-merci-ndenga/relay/blob/main/src/delivery/delivery-queue.ts): `src/delivery/delivery-queue.ts`
- [BullMQ queue](https://github.com/dieu-merci-ndenga/relay/blob/main/src/delivery/bullmq-delivery.queue.ts): `src/delivery/bullmq-delivery.queue.ts`
- [In-memory queue](https://github.com/dieu-merci-ndenga/relay/blob/main/src/delivery/in-memory-delivery.queue.ts): `src/delivery/in-memory-delivery.queue.ts`
- **Redis queues**
- [Queue worker](https://github.com/dieu-merci-ndenga/relay/blob/main/src/delivery/bullmq-delivery.worker.ts): `src/delivery/bullmq-delivery.worker.ts`
- [Delivery processor](https://github.com/dieu-merci-ndenga/relay/blob/main/src/delivery/delivery-processor.ts): `src/delivery/delivery-processor.ts`

### Console and metrics

- [Prometheus metrics](https://github.com/dieu-merci-ndenga/relay/blob/main/src/metrics/metrics.service.ts): `src/metrics/metrics.service.ts`
- [Web console](https://github.com/dieu-merci-ndenga/relay/blob/main/frontend/app.js): `frontend/app.js`

### Other components

- **Webhook provider**
- **Downstream receiver**
- **Operator**

## Connections

- Webhook provider → HTTP API: submits signed event (evidence: `README.md`)
- HTTP API → Event orchestration: delegates requests (evidence: `src/app.controller.ts`)
- HTTP API → Signature utilities: checks metrics token (evidence: `src/app.controller.ts`)
- HTTP API → Admin authorization: guards operator routes (evidence: `src/app.controller.ts`)
- Event orchestration → Signature utilities: validates webhook (evidence: `src/app.service.ts`)
- Event orchestration → Event store contract: stores and queries events (evidence: `src/app.service.ts`)
- Event orchestration → Delivery queue contract: enqueues deliveries (evidence: `src/app.service.ts`)
- Event orchestration → Prometheus metrics: records ingestion (evidence: `src/app.service.ts`)
- Runtime composition → PostgreSQL event store: selects production store (evidence: `src/app.module.ts`)
- Runtime composition → In-memory event store: selects test store (evidence: `src/app.module.ts`)
- Runtime composition → BullMQ queue: selects production queue (evidence: `src/app.module.ts`)
- Runtime composition → In-memory queue: selects test queue (evidence: `src/app.module.ts`)
- PostgreSQL event store → PostgreSQL: persists event history (evidence: `README.md`)
- Outbox recovery → Event store contract: claims pending events (evidence: `src/delivery/outbox-sweeper.ts`)
- Outbox recovery → Delivery queue contract: re-enqueues events (evidence: `src/delivery/outbox-sweeper.ts`)
- Outbox recovery → Prometheus metrics: records recovery (evidence: `src/delivery/outbox-sweeper.ts`)
- BullMQ queue → Redis queues: stores delivery jobs (evidence: `README.md`)
- Queue worker → Delivery processor: processes jobs (evidence: `src/delivery/bullmq-delivery.worker.ts`)
- Queue worker → Redis queues: consumes and schedules jobs (evidence: `README.md`)
- Delivery processor → Downstream receiver: posts signed payload (evidence: `src/delivery/delivery-processor.ts`)
- Delivery processor → Event store contract: records attempts and dead letters (evidence: `src/delivery/delivery-processor.ts`)
- Delivery processor → Prometheus metrics: records delivery metrics (evidence: `src/delivery/delivery-processor.ts`)
- Operator → Web console: uses console (evidence: `README.md`)
- Web console → HTTP API: calls operator API (evidence: `README.md`)
- Operator → HTTP API: queries operational data (evidence: `README.md`)
- HTTP API → Prometheus metrics: serves metrics (evidence: `src/app.controller.ts`)
