# jasonmassie01/pg_sage architecture

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

- Interactive diagram: https://gitdiagram.com/jasonmassie01/pg_sage
- Repository: https://github.com/jasonmassie01/pg_sage

## Overview

pg_sage is an agentic PostgreSQL DBA that monitors one or more databases, turns collected signals into findings and ranked DBA cases, and proposes or executes guarded remediation. Its main user workflow runs from dashboard/API access through database collection, deterministic analysis and optional LLM investigation, then case review and trust-gated actions with verification. The README also documents fleet monitoring, SRE investigations, forecasting, alerting, provider adapters, and shadow mode, represented as distinct capability branches. Relationships are based on README workflow statements and the shown UI excerpts; unsampled implementation details are not asserted.

Main entry points: [`sidecar/internal/executor/engine_outcome.go`](https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/internal/executor/engine_outcome.go) (Guarded executor), [`sidecar/internal/fleet/manager.go`](https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/internal/fleet/manager.go) (Fleet manager), [`sidecar/cmd/pg_sage_sidecar/main.go`](https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/cmd/pg_sage_sidecar/main.go) (Sidecar runtime), [`sidecar/internal/collector/collector.go`](https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/internal/collector/collector.go) (Metrics collector)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Access and fleet"]
  node_dashboard["Dashboard UI<br/>[App.jsx]"]
  node_api["REST API<br/>[router.go]"]
  node_fleet["Fleet manager<br/>[manager.go]"]
  node_runtime["Sidecar runtime<br/>[main.go]"]
end

subgraph group_observe["Database observation"]
  node_collector["Metrics collector<br/>[collector.go]"]
  node_cloud["Cloud adapters<br/>[runtime.go]"]
end

subgraph group_analyze["Analysis and advice"]
  node_analyzer["Rules and findings<br/>[analyzer.go]"]
  node_cases["DBA cases<br/>[case.go]"]
  node_investigator["SRE investigations<br/>[engine.go]"]
  node_advisor["Query and config advice<br/>[advisor.go]"]
  node_llm["LLM service<br/>[manager.go]"]
end

subgraph group_act["Remediation and trust"]
  node_executor["Guarded executor<br/>[engine_outcome.go]"]
  node_approval["Action approvals<br/>[card.go]"]
  node_verification["Action verification<br/>[engine.go]"]
  node_shadow["Shadow mode<br/>[shadow_runtime.go]"]
end

subgraph group_operate["Operations and integrations"]
  node_alerting["Alert delivery<br/>[alerting.go]"]
  node_briefing["Health briefings<br/>[briefing.go]"]
  node_prometheus["Prometheus metrics<br/>[prometheus.go]"]
end

node_operator(("DBA operator"))
node_postgres[("PostgreSQL")]
node_external_llm(("LLM endpoint"))

node_operator -->|"reviews"| node_dashboard
node_dashboard -->|"requests"| node_api
node_api -.->|"serves"| node_runtime
node_runtime -.->|"monitors"| node_fleet
node_fleet -.->|"collects from"| node_collector
node_collector -->|"reads metrics"| node_postgres
node_collector -->|"supplies data"| node_analyzer
node_analyzer -->|"projects findings"| node_cases
node_cases -->|"investigates"| node_investigator
node_investigator -->|"requests review"| node_llm
node_advisor -->|"requests analysis"| node_llm
node_llm -->|"calls endpoint"| node_external_llm
node_cases -->|"proposes actions"| node_executor
node_executor -->|"gates risky actions"| node_approval
node_executor -->|"applies actions"| node_postgres
node_executor -->|"verifies changes"| node_verification
node_executor -->|"reports policy outcomes"| node_shadow
node_fleet -.->|"uses adapters"| node_cloud
node_analyzer -.->|"routes alerts"| node_alerting
node_fleet -.->|"summarizes health"| node_briefing
node_runtime -->|"exposes metrics"| node_prometheus

click node_dashboard "https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/web/src/App.jsx"
click node_api "https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/internal/api/router.go"
click node_fleet "https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/internal/fleet/manager.go"
click node_runtime "https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/cmd/pg_sage_sidecar/main.go"
click node_collector "https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/internal/collector/collector.go"
click node_cloud "https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/internal/cloudtel/runtime.go"
click node_analyzer "https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/internal/analyzer/analyzer.go"
click node_cases "https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/internal/cases/case.go"
click node_investigator "https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/internal/sre/slo/engine.go"
click node_advisor "https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/internal/advisor/advisor.go"
click node_llm "https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/internal/llm/manager.go"
click node_executor "https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/internal/executor/engine_outcome.go"
click node_approval "https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/internal/approvalcard/card.go"
click node_verification "https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/internal/verify/engine.go"
click node_shadow "https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/cmd/pg_sage_sidecar/shadow_runtime.go"
click node_alerting "https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/internal/alerting/alerting.go"
click node_briefing "https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/internal/briefing/briefing.go"
click node_prometheus "https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/cmd/pg_sage_sidecar/prometheus.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_dashboard,node_api,node_fleet,node_runtime toneBlue
class node_collector,node_cloud,node_postgres toneAmber
class node_analyzer,node_cases,node_investigator,node_advisor,node_llm toneMint
class node_executor,node_approval,node_verification,node_shadow toneRose
class node_alerting,node_briefing,node_prometheus,node_operator,node_external_llm toneIndigo
```

## Components

### Access and fleet

- [Dashboard UI](https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/web/src/App.jsx): `sidecar/web/src/App.jsx`
- [REST API](https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/internal/api/router.go): `sidecar/internal/api/router.go`
- [Fleet manager](https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/internal/fleet/manager.go): `sidecar/internal/fleet/manager.go`
- [Sidecar runtime](https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/cmd/pg_sage_sidecar/main.go): `sidecar/cmd/pg_sage_sidecar/main.go`

### Database observation

- [Metrics collector](https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/internal/collector/collector.go): `sidecar/internal/collector/collector.go`
- [Cloud adapters](https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/internal/cloudtel/runtime.go): `sidecar/internal/cloudtel/runtime.go`

### Analysis and advice

- [Rules and findings](https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/internal/analyzer/analyzer.go): `sidecar/internal/analyzer/analyzer.go`
- [DBA cases](https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/internal/cases/case.go): `sidecar/internal/cases/case.go`
- [SRE investigations](https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/internal/sre/slo/engine.go): `sidecar/internal/sre/slo/engine.go`
- [Query and config advice](https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/internal/advisor/advisor.go): `sidecar/internal/advisor/advisor.go`
- [LLM service](https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/internal/llm/manager.go): `sidecar/internal/llm/manager.go`

### Remediation and trust

- [Guarded executor](https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/internal/executor/engine_outcome.go): `sidecar/internal/executor/engine_outcome.go`
- [Action approvals](https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/internal/approvalcard/card.go): `sidecar/internal/approvalcard/card.go`
- [Action verification](https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/internal/verify/engine.go): `sidecar/internal/verify/engine.go`
- [Shadow mode](https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/cmd/pg_sage_sidecar/shadow_runtime.go): `sidecar/cmd/pg_sage_sidecar/shadow_runtime.go`

### Operations and integrations

- [Alert delivery](https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/internal/alerting/alerting.go): `sidecar/internal/alerting/alerting.go`
- [Health briefings](https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/internal/briefing/briefing.go): `sidecar/internal/briefing/briefing.go`
- [Prometheus metrics](https://github.com/jasonmassie01/pg_sage/blob/master/sidecar/cmd/pg_sage_sidecar/prometheus.go): `sidecar/cmd/pg_sage_sidecar/prometheus.go`

### Other components

- **DBA operator**
- **PostgreSQL**
- **LLM endpoint**

## Connections

- DBA operator → Dashboard UI: reviews (evidence: `README.md`)
- Dashboard UI → REST API: requests
- REST API → Sidecar runtime: serves
- Sidecar runtime → Fleet manager: monitors
- Fleet manager → Metrics collector: collects from
- Metrics collector → PostgreSQL: reads metrics (evidence: `README.md`)
- Metrics collector → Rules and findings: supplies data (evidence: `README.md`)
- Rules and findings → DBA cases: projects findings (evidence: `README.md`)
- DBA cases → SRE investigations: investigates (evidence: `README.md`)
- SRE investigations → LLM service: requests review (evidence: `README.md`)
- Query and config advice → LLM service: requests analysis (evidence: `README.md`)
- LLM service → LLM endpoint: calls endpoint (evidence: `README.md`)
- DBA cases → Guarded executor: proposes actions (evidence: `README.md`)
- Guarded executor → Action approvals: gates risky actions (evidence: `README.md`)
- Guarded executor → PostgreSQL: applies actions (evidence: `README.md`)
- Guarded executor → Action verification: verifies changes (evidence: `README.md`)
- Guarded executor → Shadow mode: reports policy outcomes (evidence: `README.md`)
- Fleet manager → Cloud adapters: uses adapters
- Rules and findings → Alert delivery: routes alerts (evidence: `README.md`)
- Fleet manager → Health briefings: summarizes health (evidence: `README.md`)
- Sidecar runtime → Prometheus metrics: exposes metrics (evidence: `README.md`)
