# darkerror64/ledgerlens architecture

> Architecture diagram of the GitHub repository darkerror64/ledgerlens, 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/darkerror64/ledgerlens
- Repository: https://github.com/darkerror64/ledgerlens

## Overview

LedgerLens is an analyst-facing root-cause ranking tool, not a causal-inference system. An analyst submits a metric and date through the UI or pipeline; the system detects and drills into an anomaly, gathers ticket symptoms, matches the affected cohort against recorded business changes, tests candidates with negative controls, and presents an auditable diagnosis card. Supporting layers provide typed domain models, tunable rules, and a DuckDB query registry. The README documents optional production change-source integrations; connector internals were not sampled, so those links are marked accordingly.

Main entry points: [`ledgerlens/store.py`](https://github.com/darkerror64/ledgerlens/blob/main/ledgerlens/store.py) (Query registry), [`ledgerlens/pipeline.py`](https://github.com/darkerror64/ledgerlens/blob/main/ledgerlens/pipeline.py) (Diagnosis pipeline), [`ledgerlens/hypothesis.py`](https://github.com/darkerror64/ledgerlens/blob/main/ledgerlens/hypothesis.py) (Candidate ranking), [`app.py`](https://github.com/darkerror64/ledgerlens/blob/main/app.py) (Analyst UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Analyst interface"]
  node_ui["Analyst UI<br/>[app.py]"]
  node_pipeline["Diagnosis pipeline<br/>[pipeline.py]"]
end

subgraph group_signals["Signals and ledger"]
  node_anomaly["Anomaly and drill-down<br/>[anomaly.py]"]
  node_symptoms["Ticket clustering<br/>[symptoms.py]"]
  node_ledger["Change connectors<br/>[connectors.py]"]
  node_inputdata["Demo input data"]
end

subgraph group_diagnosis["Candidate diagnosis"]
  node_hypothesis["Candidate ranking<br/>[hypothesis.py]"]
  node_controls["Negative controls<br/>[controls.py]"]
  node_learning["Learned prior<br/>[learning.py]"]
  node_narration["Diagnosis card<br/>[narrate.py]"]
end

subgraph group_evidence["Evidence and state"]
  node_rules["Rules and thresholds<br/>[config.py]"]
  node_models["Domain models<br/>[models.py]"]
  node_store["Query registry<br/>[store.py]"]
  node_database[("DuckDB state")]
end

node_analyst(("Analyst"))
node_source_systems["Business source systems"]

node_analyst -->|"submits diagnosis"| node_ui
node_ui -->|"loads diagnosis"| node_pipeline
node_pipeline -->|"initializes and loads"| node_store
node_pipeline -->|"detects and attributes"| node_anomaly
node_pipeline -->|"clusters tickets"| node_symptoms
node_pipeline -->|"ranks candidates"| node_hypothesis
node_pipeline -.->|"prepares card"| node_narration
node_store -->|"queries and records"| node_database
node_store -->|"loads change events"| node_ledger
node_inputdata -->|"loads demo records"| node_store
node_source_systems -.->|"provides change metadata"| node_ledger
node_symptoms -.->|"reads ticket data"| node_store
node_anomaly -.->|"queries metric data"| node_store
node_hypothesis -->|"tests candidates"| node_controls
node_hypothesis -.->|"uses learned prior"| node_learning
node_hypothesis -->|"measures sub-slices"| node_anomaly
node_ui -->|"opens query details"| node_store
node_narration -.->|"renders diagnosis"| node_ui

click node_ui "https://github.com/darkerror64/ledgerlens/blob/main/app.py"
click node_pipeline "https://github.com/darkerror64/ledgerlens/blob/main/ledgerlens/pipeline.py"
click node_rules "https://github.com/darkerror64/ledgerlens/blob/main/config.py"
click node_models "https://github.com/darkerror64/ledgerlens/blob/main/ledgerlens/models.py"
click node_anomaly "https://github.com/darkerror64/ledgerlens/blob/main/ledgerlens/anomaly.py"
click node_symptoms "https://github.com/darkerror64/ledgerlens/blob/main/ledgerlens/ledger/symptoms.py"
click node_ledger "https://github.com/darkerror64/ledgerlens/blob/main/ledgerlens/ledger/connectors.py"
click node_inputdata "https://github.com/darkerror64/ledgerlens/tree/main/data"
click node_hypothesis "https://github.com/darkerror64/ledgerlens/blob/main/ledgerlens/hypothesis.py"
click node_controls "https://github.com/darkerror64/ledgerlens/blob/main/ledgerlens/controls.py"
click node_learning "https://github.com/darkerror64/ledgerlens/blob/main/ledgerlens/learning.py"
click node_narration "https://github.com/darkerror64/ledgerlens/blob/main/ledgerlens/narrate.py"
click node_store "https://github.com/darkerror64/ledgerlens/blob/main/ledgerlens/store.py"
click node_database "https://github.com/darkerror64/ledgerlens/tree/main/data"

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_ui,node_pipeline toneBlue
class node_anomaly,node_symptoms,node_ledger,node_inputdata toneAmber
class node_hypothesis,node_controls,node_learning,node_narration toneMint
class node_rules,node_models,node_store,node_database toneRose
class node_analyst,node_source_systems toneIndigo
```

## Components

### Analyst interface

- [Analyst UI](https://github.com/darkerror64/ledgerlens/blob/main/app.py): `app.py`
- [Diagnosis pipeline](https://github.com/darkerror64/ledgerlens/blob/main/ledgerlens/pipeline.py): `ledgerlens/pipeline.py`

### Signals and ledger

- [Anomaly and drill-down](https://github.com/darkerror64/ledgerlens/blob/main/ledgerlens/anomaly.py): `ledgerlens/anomaly.py`
- [Ticket clustering](https://github.com/darkerror64/ledgerlens/blob/main/ledgerlens/ledger/symptoms.py): `ledgerlens/ledger/symptoms.py`
- [Change connectors](https://github.com/darkerror64/ledgerlens/blob/main/ledgerlens/ledger/connectors.py): `ledgerlens/ledger/connectors.py`
- [Demo input data](https://github.com/darkerror64/ledgerlens/tree/main/data): `data`

### Candidate diagnosis

- [Candidate ranking](https://github.com/darkerror64/ledgerlens/blob/main/ledgerlens/hypothesis.py): `ledgerlens/hypothesis.py`
- [Negative controls](https://github.com/darkerror64/ledgerlens/blob/main/ledgerlens/controls.py): `ledgerlens/controls.py`
- [Learned prior](https://github.com/darkerror64/ledgerlens/blob/main/ledgerlens/learning.py): `ledgerlens/learning.py`
- [Diagnosis card](https://github.com/darkerror64/ledgerlens/blob/main/ledgerlens/narrate.py): `ledgerlens/narrate.py`

### Evidence and state

- [Rules and thresholds](https://github.com/darkerror64/ledgerlens/blob/main/config.py): `config.py`
- [Domain models](https://github.com/darkerror64/ledgerlens/blob/main/ledgerlens/models.py): `ledgerlens/models.py`
- [Query registry](https://github.com/darkerror64/ledgerlens/blob/main/ledgerlens/store.py): `ledgerlens/store.py`
- [DuckDB state](https://github.com/darkerror64/ledgerlens/tree/main/data): `data`

### Other components

- **Analyst**
- **Business source systems**

## Connections

- Analyst → Analyst UI: submits diagnosis (evidence: `app.py`)
- Analyst UI → Diagnosis pipeline: loads diagnosis (evidence: `app.py`)
- Diagnosis pipeline → Query registry: initializes and loads (evidence: `ledgerlens/pipeline.py`)
- Diagnosis pipeline → Anomaly and drill-down: detects and attributes (evidence: `ledgerlens/pipeline.py`)
- Diagnosis pipeline → Ticket clustering: clusters tickets (evidence: `ledgerlens/pipeline.py`)
- Diagnosis pipeline → Candidate ranking: ranks candidates (evidence: `ledgerlens/pipeline.py`)
- Diagnosis pipeline → Diagnosis card: prepares card (evidence: `ledgerlens/pipeline.py`)
- Query registry → DuckDB state: queries and records (evidence: `README.md`)
- Query registry → Change connectors: loads change events (evidence: `ledgerlens/store.py`)
- Demo input data → Query registry: loads demo records
- Business source systems → Change connectors: provides change metadata (evidence: `README.md`)
- Ticket clustering → Query registry: reads ticket data (evidence: `ledgerlens/ledger/symptoms.py`)
- Anomaly and drill-down → Query registry: queries metric data (evidence: `ledgerlens/anomaly.py`)
- Candidate ranking → Negative controls: tests candidates (evidence: `README.md`)
- Candidate ranking → Learned prior: uses learned prior (evidence: `README.md`)
- Candidate ranking → Anomaly and drill-down: measures sub-slices (evidence: `ledgerlens/hypothesis.py`)
- Analyst UI → Query registry: opens query details (evidence: `app.py`)
- Diagnosis card → Analyst UI: renders diagnosis
