# krystalunity/krystal-quorum architecture

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

- Interactive diagram: https://gitdiagram.com/krystalunity/krystal-quorum
- Repository: https://github.com/krystalunity/krystal-quorum

## Overview

1. Krystal Quorum is a Python CLI package that acts as a review gate, not an agent runtime. Its job is to review a markdown plan before implementation and, separately, review an implementation diff after code changes.

2. The top-level entry points are the CLI and module launcher (`krystal_quorum.cli`, `__main__.py`). From there the tool fans out into three user-facing workflows: `review`, `demo`, and `init` for installing agent import packs.

3. The core plan-review pipeline is: load a plan document, build reviewer prompts, send the plan to one or more reviewers, parse strict JSON responses, then reconcile the reviewer outputs into one verdict and human-readable summary.

4. Reviewer execution is abstracted behind adapter types in `src/krystal_quorum/reviewers/`. The repository supports local mock reviewers, command-based reviewers, Ollama-backed reviewers, OpenAI-compatible reviewers, and a hosted reviewer mode. This is the main “pluggable backend” boundary.

5. Reconciliation is a first-class subsystem, not a simple vote count. The codebase has dedicated modules for commitments, issue matching, diversity, approvals, and general reconcile logic. The system is intentionally safety-biased: a single `BLOCK` can veto the merged result, and low diversity or singleton blockers reduce confidence.

6. Diff review is a separate subsystem with its own models, prompts, formatting, persistence, and reconciliation path. Files such as `diff_service.py`, `diff_models.py`, `diff_prompts.py`, `diff_reconcile.py`, and `diff_persist.py` indicate that plan review and diff review share the same architectural pattern but are handled independently.

7. Persistence is local and append-only under `.krystal-quorum/reviews/`. The CLI writes raw reviewer outputs, merged summaries, and artifact metadata so the user can inspect what happened after the run. This artifact directory is also what the GitHub Action exposes as build output.

8. Configuration is split between CLI flags, project config, and environment variables. `config.py`, `reviewer_specs.py`, and the integration docs indicate that reviewers can be declared in TOML, while runtime secrets and endpoints come from env vars such as OpenAI keys, Ollama base URLs, or the hosted API token.

9. The repository has a clear boundary between local and hosted infrastructure. Local mode talks directly to tools or model servers on the machine/network; hosted mode submits the same plan to Krystal Unity’s control plane and polls for completion. The README also notes that hosted reviewers are exclusive in v1 and are not mixed with local reviewers in one command.

10. GitHub Actions support is a separate delivery surface. `integrations/github-action/` and `action.yml` wire the CLI into pull-request checks, usually in diff mode with explicit base/head SHAs. The action is designed to emit artifacts and fail the workflow on revise/block outcomes.

11. Agent import packs are another integration layer, distinct from the core reviewer engine. The templates under `src/krystal_quorum/templates/agent_integrations/` and the docs in `integrations/` install prompt files or skill files for specific agent ecosystems such as Claude Code, Codex, Copilot, Hermes, OpenClaw, and OpenCode.

12. Validation is broad and architecture-relevant: `tests/` covers CLI behavior, adapters, diff flow, reconciliation, persistence, GitHub Action wiring, and end-to-end plan-to-diff behavior. `benchmarks/` and `experiments/` exist to compare reviewer behavior and consensus matching, showing that the repository treats review quality as a measurable subsystem.

Main entry points: [`src/krystal_quorum/reconcile.py`](https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/reconcile.py) (Reconcile), [`src/krystal_quorum/reviewers/base.py`](https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/reviewers/base.py) (Reviewer API), [`src/krystal_quorum/cli.py`](https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/cli.py) (CLI), [`src/krystal_quorum/diff_service.py`](https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/diff_service.py) (Diff service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_entry["Entry points"]
  node_n_cli["CLI<br/>command surface<br/>[cli.py]"]
  node_n_main["Module run<br/>launcher<br/>[__main__.py]"]
  node_n_init["Init command<br/>installer<br/>[init_command.py]"]
end

subgraph group_grp_plan["Plan review"]
  node_n_prompts["Plan prompts<br/>prompt builder<br/>[prompts.py]"]
  node_n_models["Plan models<br/>review schema<br/>[models.py]"]
  node_n_reconcile["Reconcile<br/>decision merge<br/>[reconcile.py]"]
end

subgraph group_grp_diff["Diff review"]
  node_n_diff_service["Diff service<br/>diff pipeline<br/>[diff_service.py]"]
  node_n_diff_models["Diff models<br/>diff schema<br/>[diff_models.py]"]
  node_n_diff_prompts["Diff prompts<br/>prompt builder<br/>[diff_prompts.py]"]
  node_n_diff_reconcile["Diff reconcile<br/>decision merge<br/>[diff_reconcile.py]"]
  node_n_diff_persist[("Diff store<br/>artifact writer<br/>[diff_persist.py]")]
end

subgraph group_grp_backends["Reviewer backends"]
  node_n_reviewers_base["Reviewer API<br/>adapter interface<br/>[base.py]"]
  node_n_mock["Mock backend<br/>local reviewer<br/>[mock.py]"]
  node_n_command["Command backend<br/>local reviewer<br/>[command.py]"]
  node_n_ollama["Ollama backend<br/>local LLM reviewer<br/>[ollama.py]"]
  node_n_openai["OpenAI backend<br/>API reviewer"]
  node_n_hosted["Hosted mode<br/>remote reviewer<br/>[hosted.py]"]
end

subgraph group_grp_integrations["Integrations"]
  node_n_github_action["GitHub Action<br/>ci integration<br/>[action.yml]"]
  node_n_agent_templates["Agent packs<br/>template set<br/>[quorum-review.md]"]
end

subgraph group_grp_core["Core services"]
  node_n_commitments["Commitments<br/>consensus rule<br/>[commitments.py]"]
  node_n_issues["Issue match<br/>matching<br/>[issue_matching.py]"]
  node_n_diversity["Diversity<br/>confidence rule<br/>[diversity.py]"]
  node_n_approval["Approval<br/>safety gate<br/>[approval.py]"]
  node_n_persist[("Review store<br/>append-only artifacts<br/>[persist.py]")]
end

node_n_main -->|"launches"| node_n_cli
node_n_cli -->|"routes init"| node_n_init
node_n_cli -->|"review flow"| node_n_prompts
node_n_cli -->|"loads input"| node_n_models
node_n_prompts -->|"send prompts"| node_n_reviewers_base
node_n_reviewers_base -->|"adapts"| node_n_mock
node_n_reviewers_base -->|"adapts"| node_n_command
node_n_reviewers_base -->|"adapts"| node_n_ollama
node_n_reviewers_base -->|"adapts"| node_n_openai
node_n_reviewers_base -->|"adapts"| node_n_hosted
node_n_hosted -->|"returns verdicts"| node_n_reconcile
node_n_command -->|"local verdicts"| node_n_reconcile
node_n_ollama -->|"local verdicts"| node_n_reconcile
node_n_openai -->|"local verdicts"| node_n_reconcile
node_n_mock -->|"local verdicts"| node_n_reconcile
node_n_reconcile -->|"checks"| node_n_commitments
node_n_reconcile -->|"matches"| node_n_issues
node_n_reconcile -->|"scores"| node_n_diversity
node_n_reconcile -->|"applies gate"| node_n_approval
node_n_reconcile -->|"stores"| node_n_persist
node_n_cli -->|"routes diff"| node_n_diff_service
node_n_diff_service -->|"builds"| node_n_diff_prompts
node_n_diff_service -->|"uses"| node_n_diff_models
node_n_diff_service -->|"executes via"| node_n_reviewers_base
node_n_diff_service -->|"merges"| node_n_diff_reconcile
node_n_diff_reconcile -->|"stores"| node_n_diff_persist
node_n_github_action -->|"invokes"| node_n_cli
node_n_github_action -->|"prefers diff"| node_n_diff_service
node_n_init -->|"installs"| node_n_agent_templates

click node_n_cli "https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/cli.py"
click node_n_main "https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/__main__.py"
click node_n_init "https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/init_command.py"
click node_n_prompts "https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/prompts.py"
click node_n_models "https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/models.py"
click node_n_reviewers_base "https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/reviewers/base.py"
click node_n_mock "https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/reviewers/mock.py"
click node_n_command "https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/reviewers/command.py"
click node_n_ollama "https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/reviewers/ollama.py"
click node_n_openai "https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/reviewers/openai_compatible.py"
click node_n_hosted "https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/hosted.py"
click node_n_reconcile "https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/reconcile.py"
click node_n_commitments "https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/commitments.py"
click node_n_issues "https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/issue_matching.py"
click node_n_diversity "https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/diversity.py"
click node_n_approval "https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/approval.py"
click node_n_persist "https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/persist.py"
click node_n_diff_service "https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/diff_service.py"
click node_n_diff_models "https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/diff_models.py"
click node_n_diff_prompts "https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/diff_prompts.py"
click node_n_diff_reconcile "https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/diff_reconcile.py"
click node_n_diff_persist "https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/diff_persist.py"
click node_n_github_action "https://github.com/krystalunity/krystal-quorum/blob/main/integrations/github-action/action.yml"
click node_n_agent_templates "https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/templates/agent_integrations/common/quorum-review.md"

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_n_cli,node_n_main,node_n_init toneBlue
class node_n_prompts,node_n_models,node_n_reconcile toneAmber
class node_n_diff_service,node_n_diff_models,node_n_diff_prompts,node_n_diff_reconcile,node_n_diff_persist toneMint
class node_n_reviewers_base,node_n_mock,node_n_command,node_n_ollama,node_n_openai,node_n_hosted toneRose
class node_n_github_action,node_n_agent_templates toneIndigo
class node_n_commitments,node_n_issues,node_n_diversity,node_n_approval,node_n_persist toneTeal
```

## Components

### Entry points

CLI and module launcher surface.

- [CLI](https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/cli.py): command surface · Top-level command routing for review, demo, and init. · `src/krystal_quorum/cli.py`
- [Module run](https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/__main__.py): launcher · Module entry point for python -m execution. · `src/krystal_quorum/__main__.py`
- [Init command](https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/init_command.py): installer · Installs agent import packs and related templates. · `src/krystal_quorum/init_command.py`

### Plan review

Core markdown-plan review pipeline.

- [Plan prompts](https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/prompts.py): prompt builder · Builds reviewer prompts for plan review. · `src/krystal_quorum/prompts.py`
- [Plan models](https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/models.py): review schema · Data models for plan review input and outputs. · `src/krystal_quorum/models.py`
- [Reconcile](https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/reconcile.py): decision merge · Merges reviewer outputs into one verdict and summary. · `src/krystal_quorum/reconcile.py`

### Diff review

Separate code-diff review pipeline.

- [Diff service](https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/diff_service.py): diff pipeline · Coordinates the separate diff-review workflow. · `src/krystal_quorum/diff_service.py`
- [Diff models](https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/diff_models.py): diff schema · Data structures for diff review inputs and outputs. · `src/krystal_quorum/diff_models.py`
- [Diff prompts](https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/diff_prompts.py): prompt builder · Constructs prompts for code-diff review. · `src/krystal_quorum/diff_prompts.py`
- [Diff reconcile](https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/diff_reconcile.py): decision merge · Reconciles diff-review responses using the same pattern as plan review. · `src/krystal_quorum/diff_reconcile.py`
- [Diff store](https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/diff_persist.py): artifact writer · Persists diff-review artifacts and results. · `src/krystal_quorum/diff_persist.py`

### Reviewer backends

Pluggable execution adapters for local and hosted reviewers.

- [Reviewer API](https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/reviewers/base.py): adapter interface · Shared reviewer interfaces and abstractions. · `src/krystal_quorum/reviewers/base.py`
- [Mock backend](https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/reviewers/mock.py): local reviewer · Deterministic local reviewer for testing and demos. · `src/krystal_quorum/reviewers/mock.py`
- [Command backend](https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/reviewers/command.py): local reviewer · Runs external commands as reviewers. · `src/krystal_quorum/reviewers/command.py`
- [Ollama backend](https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/reviewers/ollama.py): local LLM reviewer · Talks to a local or networked Ollama model server. · `src/krystal_quorum/reviewers/ollama.py`
- [OpenAI backend](https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/reviewers/openai_compatible.py): API reviewer · Uses OpenAI-compatible API endpoints. · `src/krystal_quorum/reviewers/openai_compatible.py`
- [Hosted mode](https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/hosted.py): remote reviewer · Submits reviews to the Krystal Unity control plane. · `src/krystal_quorum/hosted.py`

### Integrations

Delivery surfaces for GitHub Action and agent import packs.

- [GitHub Action](https://github.com/krystalunity/krystal-quorum/blob/main/integrations/github-action/action.yml): ci integration · Wires the CLI into pull-request checks and artifact output. · `integrations/github-action/action.yml`
- [Agent packs](https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/templates/agent_integrations/common/quorum-review.md): template set · Templates for installing agent import packs across ecosystems. · `src/krystal_quorum/templates/agent_integrations/common/quorum-review.md`

### Core services

Shared policies, persistence, config, and reconciliation utilities.

- [Commitments](https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/commitments.py): consensus rule · Tracks explicit commitments used during reconciliation. · `src/krystal_quorum/commitments.py`
- [Issue match](https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/issue_matching.py): matching · Matches reviewer findings across responses. · `src/krystal_quorum/issue_matching.py`
- [Diversity](https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/diversity.py): confidence rule · Scores reviewer diversity and lowers confidence for near-duplicates. · `src/krystal_quorum/diversity.py`
- [Approval](https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/approval.py): safety gate · Safety-biased BLOCK/approve logic for final verdicts. · `src/krystal_quorum/approval.py`
- [Review store](https://github.com/krystalunity/krystal-quorum/blob/main/src/krystal_quorum/persist.py): append-only artifacts · Writes raw outputs, summaries, and metadata under local review artifacts. · `src/krystal_quorum/persist.py`

## Connections

- Module run → CLI: launches · Module execution enters the same CLI surface.
- CLI → Init command: routes init · CLI dispatches to package/install workflows.
- CLI → Plan prompts: review flow · Review command builds prompts from plan input.
- CLI → Plan models: loads input · CLI feeds plan and review models into the pipeline.
- Plan prompts → Reviewer API: send prompts · Prompted work is executed through reviewer adapters.
- Reviewer API → Mock backend: adapts · Mock reviewers implement the common reviewer interface.
- Reviewer API → Command backend: adapts · Command-backed reviewers implement the common reviewer interface.
- Reviewer API → Ollama backend: adapts · Ollama-backed reviewers implement the common reviewer interface.
- Reviewer API → OpenAI backend: adapts · OpenAI-compatible reviewers implement the common reviewer interface.
- Reviewer API → Hosted mode: adapts · Hosted reviewers live behind the same boundary.
- Hosted mode → Reconcile: returns verdicts · Hosted mode feeds into the same aggregation step.
- Command backend → Reconcile: local verdicts · Reviewer outputs are merged after execution.
- Ollama backend → Reconcile: local verdicts · Reviewer outputs are merged after execution.
- OpenAI backend → Reconcile: local verdicts · Reviewer outputs are merged after execution.
- Mock backend → Reconcile: local verdicts · Reviewer outputs are merged after execution.
- Reconcile → Commitments: checks · Reconciliation accounts for explicit commitments.
- Reconcile → Issue match: matches · Similar findings are grouped during merge.
- Reconcile → Diversity: scores · Consensus confidence depends on reviewer diversity.
- Reconcile → Approval: applies gate · A single BLOCK can veto the merged result.
- Reconcile → Review store: stores · Merged summaries and raw outputs are written locally.
- CLI → Diff service: routes diff · CLI also exposes a separate diff-review workflow.
- Diff service → Diff prompts: builds · Diff review has its own prompt construction.
- Diff service → Diff models: uses · Diff workflow uses separate models and result types.
- Diff service → Reviewer API: executes via · Diff review reuses the reviewer adapter boundary.
- Diff service → Diff reconcile: merges · Diff reviewer outputs are reconciled separately.
- Diff reconcile → Diff store: stores · Diff artifacts and status are persisted independently.
- GitHub Action → CLI: invokes · The action shells into the CLI for PR checks.
- GitHub Action → Diff service: prefers diff · GitHub checks typically run diff review with base/head SHAs.
- Init command → Agent packs: installs · Init copies agent-pack templates into target ecosystems.
