# aliafana/llm-scanner architecture

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

- Interactive diagram: https://gitdiagram.com/aliafana/llm-scanner
- Repository: https://github.com/aliafana/llm-scanner

## Overview

LLM-Scanner is a source-code vulnerability scanner: a user supplies a project, deterministic Joern analysis discovers candidate flows, and the scanner slices evidence for optional advisory-grounded LLM judging before producing findings and SARIF. Its major branches are discovery, judgment, retrieval, and reporting. The README documents the overall workflow; sampled source confirms several calls, but unsampled modules and pipeline sections limit certainty about some internal connections.

Main entry points: [`scanner/main.py`](https://github.com/aliafana/llm-scanner/blob/main/scanner/main.py) (Scan Orchestrator), [`scanner/rag.py`](https://github.com/aliafana/llm-scanner/blob/main/scanner/rag.py) (Advisory Retrieval), [`scanner/llm.py`](https://github.com/aliafana/llm-scanner/blob/main/scanner/llm.py) (LLM Judge), [`scanner/joern.py`](https://github.com/aliafana/llm-scanner/blob/main/scanner/joern.py) (Joern Wrapper)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_discovery["Deterministic Discovery"]
  node_pipeline["Scan Orchestrator<br/>[main.py]"]
  node_joern["Joern Wrapper<br/>[joern.py]"]
  node_query["Taint Queries<br/>[scan.sc]"]
  node_slicer["Flow Slicer<br/>[slicer.py]"]
end

subgraph group_judgment["Candidate Judgment"]
  node_llm["LLM Judge<br/>[llm.py]"]
  node_retry["API Backoff<br/>[retry.py]"]
end

subgraph group_retrieval["Advisory Retrieval"]
  node_rag["Advisory Retrieval<br/>[rag.py]"]
  node_advisories["Advisory Corpus<br/>[advisories.jsonl]"]
  node_vector_store[("pgvector Store")]
end

subgraph group_reporting["Finding Reports"]
  node_sarif["SARIF Reporter<br/>[sarif.py]"]
  node_findings["Findings and SARIF"]
end

node_user(("Scanner User"))
node_model_api{{"Hosted Model APIs"}}

node_user -->|"starts scan"| node_pipeline
node_pipeline -->|"builds graph"| node_joern
node_joern -->|"runs queries"| node_query
node_pipeline -->|"slices flows"| node_slicer
node_pipeline -->|"retrieves context"| node_rag
node_pipeline -->|"judges candidates"| node_llm
node_llm -->|"uses backoff"| node_retry
node_llm -->|"requests verdict"| node_model_api
node_rag -.->|"retrieves matches"| node_vector_store
node_rag -.->|"grounds judgments"| node_advisories
node_rag -.->|"uses backoff"| node_retry
node_pipeline -->|"formats findings"| node_sarif
node_sarif -->|"emits SARIF"| node_findings
node_pipeline -->|"writes findings"| node_findings

click node_pipeline "https://github.com/aliafana/llm-scanner/blob/main/scanner/main.py"
click node_joern "https://github.com/aliafana/llm-scanner/blob/main/scanner/joern.py"
click node_query "https://github.com/aliafana/llm-scanner/blob/main/queries/scan.sc"
click node_slicer "https://github.com/aliafana/llm-scanner/blob/main/scanner/slicer.py"
click node_llm "https://github.com/aliafana/llm-scanner/blob/main/scanner/llm.py"
click node_retry "https://github.com/aliafana/llm-scanner/blob/main/scanner/retry.py"
click node_rag "https://github.com/aliafana/llm-scanner/blob/main/scanner/rag.py"
click node_advisories "https://github.com/aliafana/llm-scanner/blob/main/corpus/advisories.jsonl"
click node_sarif "https://github.com/aliafana/llm-scanner/blob/main/scanner/sarif.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_pipeline,node_joern,node_query,node_slicer,node_user toneBlue
class node_llm,node_retry toneAmber
class node_rag,node_advisories,node_vector_store,node_model_api toneMint
class node_sarif,node_findings toneRose
```

## Components

### Deterministic Discovery

- [Scan Orchestrator](https://github.com/aliafana/llm-scanner/blob/main/scanner/main.py): `scanner/main.py`
- [Joern Wrapper](https://github.com/aliafana/llm-scanner/blob/main/scanner/joern.py): `scanner/joern.py`
- [Taint Queries](https://github.com/aliafana/llm-scanner/blob/main/queries/scan.sc): `queries/scan.sc`
- [Flow Slicer](https://github.com/aliafana/llm-scanner/blob/main/scanner/slicer.py): `scanner/slicer.py`

### Candidate Judgment

- [LLM Judge](https://github.com/aliafana/llm-scanner/blob/main/scanner/llm.py): `scanner/llm.py`
- [API Backoff](https://github.com/aliafana/llm-scanner/blob/main/scanner/retry.py): `scanner/retry.py`

### Advisory Retrieval

- [Advisory Retrieval](https://github.com/aliafana/llm-scanner/blob/main/scanner/rag.py): `scanner/rag.py`
- [Advisory Corpus](https://github.com/aliafana/llm-scanner/blob/main/corpus/advisories.jsonl): `corpus/advisories.jsonl`
- **pgvector Store**

### Finding Reports

- [SARIF Reporter](https://github.com/aliafana/llm-scanner/blob/main/scanner/sarif.py): `scanner/sarif.py`
- **Findings and SARIF**

### Other components

- **Scanner User**
- **Hosted Model APIs**

## Connections

- Scanner User → Scan Orchestrator: starts scan (evidence: `README.md`)
- Scan Orchestrator → Joern Wrapper: builds graph (evidence: `README.md`)
- Joern Wrapper → Taint Queries: runs queries (evidence: `scanner/joern.py`)
- Scan Orchestrator → Flow Slicer: slices flows (evidence: `README.md`)
- Scan Orchestrator → Advisory Retrieval: retrieves context (evidence: `scanner/main.py`)
- Scan Orchestrator → LLM Judge: judges candidates (evidence: `scanner/main.py`)
- LLM Judge → API Backoff: uses backoff (evidence: `scanner/llm.py`)
- LLM Judge → Hosted Model APIs: requests verdict (evidence: `scanner/llm.py`)
- Advisory Retrieval → pgvector Store: retrieves matches (evidence: `README.md`)
- Advisory Retrieval → Advisory Corpus: grounds judgments (evidence: `README.md`)
- Advisory Retrieval → API Backoff: uses backoff (evidence: `scanner/retry.py`)
- Scan Orchestrator → SARIF Reporter: formats findings (evidence: `README.md`)
- SARIF Reporter → Findings and SARIF: emits SARIF (evidence: `README.md`)
- Scan Orchestrator → Findings and SARIF: writes findings (evidence: `README.md`)
