# badaadata/semantic-risk-engine-action architecture

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

- Interactive diagram: https://gitdiagram.com/badaadata/semantic-risk-engine-action
- Repository: https://github.com/badaadata/semantic-risk-engine-action

## Overview

Semantic Risk Engine is a GitHub Action client for detecting semantic risk in dbt SQL changes; the analysis engine itself is a hosted service, not part of this repository. The principal workflow compares compiled SQL for changed models, sends qualifying changes to the HTTPS API, then formats the verdict and posts or updates a pull-request comment. The README also documents critical-model prioritization, downstream impact, and shadow-mode failure handling. The action wiring and some runtime steps are documented but not sampled, so those links cite the README; internal analysis details are intentionally represented as an external service.

Main entry points: [`scripts/post_comment.py`](https://github.com/badaadata/semantic-risk-engine-action/blob/main/scripts/post_comment.py) (Comment formatter), [`action.yml`](https://github.com/badaadata/semantic-risk-engine-action/blob/main/action.yml) (Action entry), [`scripts/build_payload.py`](https://github.com/badaadata/semantic-risk-engine-action/blob/main/scripts/build_payload.py) (Payload builder), [`scripts/call_api.py`](https://github.com/badaadata/semantic-risk-engine-action/blob/main/scripts/call_api.py) (API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["PR entry"]
  node_action["Action entry<br/>[action.yml]"]
end

subgraph group_prepare["Change preparation"]
  node_dbt["dbt compile"]
  node_compiled["Compiled SQL"]
  node_payload["Payload builder<br/>[build_payload.py]"]
  node_payload_json["Analysis payload"]
end

subgraph group_analysis["Risk analysis"]
  node_engine["Hosted risk engine"]
  node_api_client["API client<br/>[call_api.py]"]
  node_verdict["Analysis response"]
end

subgraph group_report["PR reporting"]
  node_formatter["Comment formatter<br/>[post_comment.py]"]
  node_manifest["dbt manifest"]
  node_github["GitHub PR comments"]
end

node_pr(("Pull request"))

node_pr -->|"triggers"| node_action
node_action -->|"uses compiled output"| node_dbt
node_dbt -->|"produces"| node_compiled
node_compiled -->|"reads SQL"| node_payload
node_payload -->|"builds"| node_payload_json
node_payload_json -->|"posts payload"| node_api_client
node_api_client -->|"sends HTTPS request"| node_engine
node_engine -->|"returns analysis"| node_verdict
node_verdict -->|"formats response"| node_formatter
node_manifest -->|"provides model metadata"| node_formatter
node_formatter -->|"posts comment"| node_github
node_github -->|"shows verdict"| node_pr

click node_action "https://github.com/badaadata/semantic-risk-engine-action/blob/main/action.yml"
click node_payload "https://github.com/badaadata/semantic-risk-engine-action/blob/main/scripts/build_payload.py"
click node_api_client "https://github.com/badaadata/semantic-risk-engine-action/blob/main/scripts/call_api.py"
click node_formatter "https://github.com/badaadata/semantic-risk-engine-action/blob/main/scripts/post_comment.py"

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_action toneBlue
class node_dbt,node_compiled,node_payload,node_payload_json toneAmber
class node_engine,node_api_client,node_verdict,node_pr toneMint
class node_formatter,node_manifest,node_github toneRose
```

## Components

### PR entry

- [Action entry](https://github.com/badaadata/semantic-risk-engine-action/blob/main/action.yml): `action.yml`

### Change preparation

- **dbt compile**
- **Compiled SQL**
- [Payload builder](https://github.com/badaadata/semantic-risk-engine-action/blob/main/scripts/build_payload.py): `scripts/build_payload.py`
- **Analysis payload**

### Risk analysis

- **Hosted risk engine**
- [API client](https://github.com/badaadata/semantic-risk-engine-action/blob/main/scripts/call_api.py): `scripts/call_api.py`
- **Analysis response**

### PR reporting

- [Comment formatter](https://github.com/badaadata/semantic-risk-engine-action/blob/main/scripts/post_comment.py): `scripts/post_comment.py`
- **dbt manifest**
- **GitHub PR comments**

### Other components

- **Pull request**

## Connections

- Pull request → Action entry: triggers (evidence: `README.md`)
- Action entry → dbt compile: uses compiled output (evidence: `README.md`)
- dbt compile → Compiled SQL: produces (evidence: `README.md`)
- Compiled SQL → Payload builder: reads SQL (evidence: `scripts/build_payload.py`)
- Payload builder → Analysis payload: builds (evidence: `scripts/build_payload.py`)
- Analysis payload → API client: posts payload (evidence: `README.md`)
- API client → Hosted risk engine: sends HTTPS request (evidence: `scripts/call_api.py`)
- Hosted risk engine → Analysis response: returns analysis (evidence: `README.md`)
- Analysis response → Comment formatter: formats response (evidence: `scripts/post_comment.py`)
- dbt manifest → Comment formatter: provides model metadata (evidence: `scripts/post_comment.py`)
- Comment formatter → GitHub PR comments: posts comment (evidence: `scripts/post_comment.py`)
- GitHub PR comments → Pull request: shows verdict (evidence: `README.md`)
