# bookang869/re-vi architecture

> Architecture diagram of the GitHub repository bookang869/re-vi, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bookang869/re-vi
- Repository: https://github.com/bookang869/re-vi
- Video tour (about a minute): https://gitdiagram.com/bookang869/re-vi/video

## Overview

Re:vi is a self-healing telemetry and alert-triage pipeline. Production alerts are enriched and deduplicated by the Gateway, queued for dispatch to the companion repository’s Hermes workflow, and later reported back for run tracking and a scheduled Slack digest. The Gateway also exposes a repair toggle and run-status endpoint. The README documents the observability stack and external repair workflow; source excerpts show key Gateway calls. The companion workflow’s internals are outside this repository, so it is represented as an external system.

Main entry points: [`gateway/cmd/server/main.go`](https://github.com/bookang869/re-vi/blob/main/gateway/cmd/server/main.go) (Gateway server), [`gateway/internal/queue/queue.go`](https://github.com/bookang869/re-vi/blob/main/gateway/internal/queue/queue.go) (NATS JetStream), [`gateway/internal/dispatcher/dispatcher.go`](https://github.com/bookang869/re-vi/blob/main/gateway/internal/dispatcher/dispatcher.go) (Repair dispatcher), [`gateway/internal/digest/handler.go`](https://github.com/bookang869/re-vi/blob/main/gateway/internal/digest/handler.go) (Outcome intake)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_telemetry["Telemetry and alerts"]
  node_otel["OTel Collector"]
  node_metrics_store[("VictoriaMetrics")]
  node_logs_store[("VictoriaLogs")]
  node_alert_rules["vmalert"]
  node_alertmanager["Alertmanager"]
end

subgraph group_gateway["Gateway processing"]
  node_gateway_server["Gateway server<br/>[main.go]"]
  node_alert_handler["Alert endpoint<br/>[handler.go]"]
  node_alert_mapping["Alert parsing<br/>[alerts.go]"]
  node_alert_publish["Lock and publish<br/>[dispatch.go]"]
  node_victoria_client["Log context query<br/>[client.go]"]
  node_nats["NATS JetStream<br/>[queue.go]"]
  node_dispatcher["Repair dispatcher<br/>[dispatcher.go]"]
  node_github_client["GitHub dispatch<br/>[dispatch.go]"]
  node_admin_handler["Repair toggle API<br/>[handler.go]"]
end

subgraph group_tracking["Run tracking"]
  node_runs_handler["Run status API<br/>[handler.go]"]
  node_digest_handler["Outcome intake<br/>[handler.go]"]
  node_run_store[("Run records<br/>[store.go]")]
  node_metrics["Gateway metrics<br/>[metrics.go]"]
end

subgraph group_digest["Digest delivery"]
  node_digest_cron["Digest scheduler<br/>[cron.go]"]
  node_slack_client["Slack delivery<br/>[client.go]"]
end

node_app["Production app"]
node_repair_workflow["Target Hermes workflow"]
node_slack["Slack"]
node_operator(("Operator"))

node_app -->|"exports telemetry"| node_otel
node_otel -->|"sends metrics"| node_metrics_store
node_otel -->|"sends logs"| node_logs_store
node_metrics_store -->|"evaluates alerts"| node_alert_rules
node_alert_rules -->|"routes alerts"| node_alertmanager
node_alertmanager -->|"posts webhook"| node_alert_handler
node_gateway_server -->|"registers route"| node_alert_handler
node_gateway_server -->|"registers routes"| node_admin_handler
node_gateway_server -->|"registers route"| node_digest_handler
node_gateway_server -->|"registers route"| node_runs_handler
node_gateway_server -->|"connects"| node_nats
node_gateway_server -->|"starts consumer"| node_dispatcher
node_gateway_server -->|"starts scheduler"| node_digest_cron
node_alert_handler -->|"parses alerts"| node_alert_mapping
node_alert_handler -->|"publishes alerts"| node_alert_publish
node_alert_publish -->|"locks and queues"| node_nats
node_alert_publish -->|"fetches context"| node_victoria_client
node_victoria_client -->|"queries logs"| node_logs_store
node_dispatcher -->|"consumes alerts"| node_nats
node_dispatcher -->|"dispatches event"| node_github_client
node_github_client -->|"triggers workflow"| node_repair_workflow
node_dispatcher -->|"records skipped runs"| node_run_store
node_dispatcher -->|"records routing"| node_metrics
node_admin_handler -->|"sets repair toggle"| node_nats
node_digest_handler -->|"buffers outcomes"| node_nats
node_digest_handler -->|"records outcomes"| node_run_store
node_digest_handler -->|"counts failures"| node_metrics
node_runs_handler -->|"reads run status"| node_run_store
node_repair_workflow -->|"reports outcomes"| node_digest_handler
node_digest_cron -->|"reads and clears digest"| node_nats
node_digest_cron -->|"posts digest"| node_slack_client
node_slack_client -->|"sends message"| node_slack
node_operator -->|"controls repair"| node_admin_handler

click node_gateway_server "https://github.com/bookang869/re-vi/blob/main/gateway/cmd/server/main.go"
click node_alert_handler "https://github.com/bookang869/re-vi/blob/main/gateway/internal/alerts/handler.go"
click node_alert_mapping "https://github.com/bookang869/re-vi/blob/main/gateway/internal/alerts/alerts.go"
click node_alert_publish "https://github.com/bookang869/re-vi/blob/main/gateway/internal/alerts/dispatch.go"
click node_victoria_client "https://github.com/bookang869/re-vi/blob/main/gateway/internal/victorialogs/client.go"
click node_nats "https://github.com/bookang869/re-vi/blob/main/gateway/internal/queue/queue.go"
click node_dispatcher "https://github.com/bookang869/re-vi/blob/main/gateway/internal/dispatcher/dispatcher.go"
click node_github_client "https://github.com/bookang869/re-vi/blob/main/gateway/internal/github/dispatch.go"
click node_admin_handler "https://github.com/bookang869/re-vi/blob/main/gateway/internal/admin/handler.go"
click node_runs_handler "https://github.com/bookang869/re-vi/blob/main/gateway/internal/runs/handler.go"
click node_digest_handler "https://github.com/bookang869/re-vi/blob/main/gateway/internal/digest/handler.go"
click node_run_store "https://github.com/bookang869/re-vi/blob/main/gateway/internal/store/store.go"
click node_metrics "https://github.com/bookang869/re-vi/blob/main/gateway/internal/metrics/metrics.go"
click node_digest_cron "https://github.com/bookang869/re-vi/blob/main/gateway/internal/digestcron/cron.go"
click node_slack_client "https://github.com/bookang869/re-vi/blob/main/gateway/internal/slack/client.go"

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_otel,node_metrics_store,node_logs_store,node_alert_rules,node_alertmanager toneBlue
class node_gateway_server,node_alert_handler,node_alert_mapping,node_alert_publish,node_victoria_client,node_nats,node_dispatcher,node_github_client,node_admin_handler toneAmber
class node_runs_handler,node_digest_handler,node_run_store,node_metrics toneMint
class node_digest_cron,node_slack_client toneRose
class node_app,node_repair_workflow,node_slack,node_operator toneIndigo
```

## Components

### Telemetry and alerts

- **OTel Collector**
- **VictoriaMetrics**
- **VictoriaLogs**
- **vmalert**
- **Alertmanager**

### Gateway processing

- [Gateway server](https://github.com/bookang869/re-vi/blob/main/gateway/cmd/server/main.go): `gateway/cmd/server/main.go`
- [Alert endpoint](https://github.com/bookang869/re-vi/blob/main/gateway/internal/alerts/handler.go): `gateway/internal/alerts/handler.go`
- [Alert parsing](https://github.com/bookang869/re-vi/blob/main/gateway/internal/alerts/alerts.go): `gateway/internal/alerts/alerts.go`
- [Lock and publish](https://github.com/bookang869/re-vi/blob/main/gateway/internal/alerts/dispatch.go): `gateway/internal/alerts/dispatch.go`
- [Log context query](https://github.com/bookang869/re-vi/blob/main/gateway/internal/victorialogs/client.go): `gateway/internal/victorialogs/client.go`
- [NATS JetStream](https://github.com/bookang869/re-vi/blob/main/gateway/internal/queue/queue.go): `gateway/internal/queue/queue.go`
- [Repair dispatcher](https://github.com/bookang869/re-vi/blob/main/gateway/internal/dispatcher/dispatcher.go): `gateway/internal/dispatcher/dispatcher.go`
- [GitHub dispatch](https://github.com/bookang869/re-vi/blob/main/gateway/internal/github/dispatch.go): `gateway/internal/github/dispatch.go`
- [Repair toggle API](https://github.com/bookang869/re-vi/blob/main/gateway/internal/admin/handler.go): `gateway/internal/admin/handler.go`

### Run tracking

- [Run status API](https://github.com/bookang869/re-vi/blob/main/gateway/internal/runs/handler.go): `gateway/internal/runs/handler.go`
- [Outcome intake](https://github.com/bookang869/re-vi/blob/main/gateway/internal/digest/handler.go): `gateway/internal/digest/handler.go`
- [Run records](https://github.com/bookang869/re-vi/blob/main/gateway/internal/store/store.go): `gateway/internal/store/store.go`
- [Gateway metrics](https://github.com/bookang869/re-vi/blob/main/gateway/internal/metrics/metrics.go): `gateway/internal/metrics/metrics.go`

### Digest delivery

- [Digest scheduler](https://github.com/bookang869/re-vi/blob/main/gateway/internal/digestcron/cron.go): `gateway/internal/digestcron/cron.go`
- [Slack delivery](https://github.com/bookang869/re-vi/blob/main/gateway/internal/slack/client.go): `gateway/internal/slack/client.go`

### Other components

- **Production app**
- **Target Hermes workflow**
- **Slack**
- **Operator**

## Connections

- Production app → OTel Collector: exports telemetry (evidence: `README.md`)
- OTel Collector → VictoriaMetrics: sends metrics (evidence: `README.md`)
- OTel Collector → VictoriaLogs: sends logs (evidence: `README.md`)
- VictoriaMetrics → vmalert: evaluates alerts (evidence: `README.md`)
- vmalert → Alertmanager: routes alerts (evidence: `README.md`)
- Alertmanager → Alert endpoint: posts webhook (evidence: `README.md`)
- Gateway server → Alert endpoint: registers route (evidence: `gateway/cmd/server/main.go`)
- Gateway server → Repair toggle API: registers routes (evidence: `gateway/cmd/server/main.go`)
- Gateway server → Outcome intake: registers route (evidence: `gateway/cmd/server/main.go`)
- Gateway server → Run status API: registers route (evidence: `gateway/cmd/server/main.go`)
- Gateway server → NATS JetStream: connects (evidence: `gateway/cmd/server/main.go`)
- Gateway server → Repair dispatcher: starts consumer (evidence: `gateway/cmd/server/main.go`)
- Gateway server → Digest scheduler: starts scheduler (evidence: `gateway/cmd/server/main.go`)
- Alert endpoint → Alert parsing: parses alerts (evidence: `gateway/internal/alerts/handler.go`)
- Alert endpoint → Lock and publish: publishes alerts (evidence: `gateway/internal/alerts/handler.go`)
- Lock and publish → NATS JetStream: locks and queues (evidence: `gateway/internal/alerts/dispatch.go`)
- Lock and publish → Log context query: fetches context (evidence: `gateway/internal/alerts/dispatch.go`)
- Log context query → VictoriaLogs: queries logs (evidence: `gateway/internal/victorialogs/client.go`)
- Repair dispatcher → NATS JetStream: consumes alerts (evidence: `gateway/internal/dispatcher/dispatcher.go`)
- Repair dispatcher → GitHub dispatch: dispatches event (evidence: `gateway/internal/dispatcher/dispatcher.go`)
- GitHub dispatch → Target Hermes workflow: triggers workflow (evidence: `README.md`)
- Repair dispatcher → Run records: records skipped runs (evidence: `gateway/internal/dispatcher/dispatcher.go`)
- Repair dispatcher → Gateway metrics: records routing (evidence: `gateway/internal/dispatcher/dispatcher.go`)
- Repair toggle API → NATS JetStream: sets repair toggle (evidence: `gateway/internal/admin/handler.go`)
- Outcome intake → NATS JetStream: buffers outcomes (evidence: `gateway/internal/digest/handler.go`)
- Outcome intake → Run records: records outcomes (evidence: `gateway/internal/digest/handler.go`)
- Outcome intake → Gateway metrics: counts failures (evidence: `gateway/internal/digest/handler.go`)
- Run status API → Run records: reads run status (evidence: `gateway/internal/runs/handler.go`)
- Target Hermes workflow → Outcome intake: reports outcomes (evidence: `README.md`)
- Digest scheduler → NATS JetStream: reads and clears digest (evidence: `gateway/internal/digestcron/cron.go`)
- Digest scheduler → Slack delivery: posts digest (evidence: `gateway/internal/digestcron/cron.go`)
- Slack delivery → Slack: sends message (evidence: `gateway/internal/slack/client.go`)
- Operator → Repair toggle API: controls repair (evidence: `README.md`)
