Skip to content

Request relay

Cross-platform deadline-bound request forwarding with SLA tracking. Requests arriving from an upstream platform (for example e-Mongolia) are routed to downstream agencies, tracked against their deadline, and their responses collected.

UI: /admin/relay, /admin/relay/config, /admin/relay/{id}.

The model

graph LR
  UP["Upstream platform"] -->|"webhook"| R["Gerege App — Relay"]
  R -->|"routing + SLA"| D1["District office"]
  R --> D2["Police"]
  R --> D3["Tax authority"]
  R --> D4["Civil registry"]
  D1 -->|"response"| R
  R -->|"webhook"| UP
Table What
relay_platforms Upstream / downstream platform registry — direction: upstream | downstream
relay_routes Routing rules: service_code → platform, with a per-target SLA in minutes
relay_requests Incoming deadline-bound requests (due_at, status, breach_notified)
relay_assignments Work assigned to each downstream platform
relay_events Every transition

One service_code can fan out to several platforms (UNIQUE (service_code, platform_id)).

Endpoints

Monitoring (relay.view)

Endpoint What
GET /v1/relay/overview SLA dashboard — deadlines, breaches
GET /v1/relay/requests Request list
GET /v1/relay/requests/{id} Details and assignments

Management (relay.manage)

Endpoint What
GET/POST /v1/relay/platforms Register platforms
DELETE /v1/relay/platforms/{id} Remove
GET/POST /v1/relay/routes Routing
DELETE /v1/relay/routes/{id} Remove a route
POST /v1/relay/requests Create a request manually
POST /v1/relay/requests/{id}/forward Forward downstream
POST /v1/relay/assignments/{id}/respond Record a response

Webhook

Endpoint What
POST /v1/relay/webhook Requests / responses from external platforms

Every platform has its own webhook_secret (64 hex characters). Incoming webhooks must be signed with it or they are rejected. New platforms get a secret automatically.

The secret is shown once

The webhook secret is displayed when the platform is created and cannot be read back. Lose it and you must recreate the platform or reset the secret.

SLA tracking

due_at is computed from the route's sla_minutes when a request arrives. The dashboard groups by:

State Meaning
received Arrived, not yet forwarded
On time due_at not yet reached
Warning Deadline approaching
Breach due_at passed — breach_notified is set

On a breach the platform's supervisor_contact is notified.

Demo mode

With RELAY_DEMO_MODE on, a simulator generates responses on behalf of the registered downstream platforms and drives the dashboard by itself — so the flow can be seen end to end before any real integration.

Seed data (only inserted when empty):

Platform Direction
e-mongolia upstream
khoroo — district office downstream
police downstream
tax downstream
civil-reg downstream

Example routing: residence-cert → district office (30 min) + civil registry (45 min), background-check → police (60 min), tax-clearance → tax (40 min).

Why no RLS?

Relay tables are cross-platform configuration and telemetry, not per-citizen data — the same category as gateway and roles/permissions. Protection is at the HTTP layer via relay.view / relay.manage.