# sk-tek/statement-extractor architecture

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

- Interactive diagram: https://gitdiagram.com/sk-tek/statement-extractor
- Repository: https://github.com/sk-tek/statement-extractor

## Overview

Statement Extractor processes bank-statement PDFs into a validated, deduplicated transaction CSV. The principal workflow checks and unlocks input PDFs, obtains or reuses Document AI OCR, converts OCR tokens into table rows and transactions, then normalizes, validates, deduplicates, and exports results. Bank layouts are configurable and detected per file; run logs, history, review reports, and intermediate OCR artifacts support inspection. The graph reflects README-documented stages and sampled source references; unsampled implementation details and uncertain links are omitted.

Main entry points: [`src/main.py`](https://github.com/sk-tek/statement-extractor/blob/main/src/main.py) (CLI pipeline), [`src/inputs.py`](https://github.com/sk-tek/statement-extractor/blob/main/src/inputs.py) (Input checks), [`src/storage.py`](https://github.com/sk-tek/statement-extractor/blob/main/src/storage.py) (Data storage), [`src/banks.py`](https://github.com/sk-tek/statement-extractor/blob/main/src/banks.py) (Bank layout handling)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Input and OCR"]
  node_input["Input checks<br/>[inputs.py]"]
  node_unlock["PDF unlocking<br/>[unlock.py]"]
  node_ocr["Document AI OCR<br/>[document_ai.py]"]
  node_raw["Raw OCR cache<br/>[storage.py]"]
  node_ids["File identity<br/>[ids.py]"]
end

subgraph group_parse["Parsing and bank layouts"]
  node_words["OCR word records<br/>[words.py]"]
  node_bankconfigs["Bank layout configs"]
  node_banks["Bank layout handling<br/>[banks.py]"]
  node_rows["Rows and columns<br/>[rows.py]"]
  node_parser["Transaction parsing<br/>[parser.py]"]
end

subgraph group_quality["Transaction quality"]
  node_normalize["Normalization<br/>[normalize.py]"]
  node_ocrfixes["OCR corrections<br/>[ocr_fixes.py]"]
  node_validate["Financial validation<br/>[validate.py]"]
  node_dedupe["Transaction deduplication<br/>[dedupe.py]"]
end

subgraph group_runtime["Runtime and outputs"]
  node_entry["CLI pipeline<br/>[main.py]"]
  node_settings["Runtime settings<br/>[config.py]"]
  node_storage[("Data storage<br/>[storage.py]")]
  node_export["CSV reports<br/>[export_csv.py]"]
  node_runlogs["Run logging<br/>[logger.py]"]
end

node_operator(("Operator"))
node_pdfs["Statement PDFs"]
node_results["CSV and run artifacts"]

node_operator -->|"runs"| node_entry
node_pdfs -->|"supplies"| node_input
node_entry -->|"loads"| node_settings
node_entry -->|"selects"| node_storage
node_entry -->|"checks"| node_input
node_input -->|"hashes"| node_ids
node_input -->|"unlocks"| node_unlock
node_entry -->|"requests OCR"| node_ocr
node_entry -->|"caches OCR"| node_raw
node_entry -->|"extracts tokens"| node_words
node_entry -->|"detects layout"| node_banks
node_banks -->|"tries layouts"| node_bankconfigs
node_entry -->|"forms rows"| node_rows
node_rows -->|"groups tokens"| node_words
node_entry -->|"parses rows"| node_parser
node_entry -->|"normalizes"| node_normalize
node_entry -->|"validates"| node_validate
node_validate -->|"checks records"| node_normalize
node_entry -->|"deduplicates"| node_dedupe
node_entry -->|"writes reports"| node_export
node_export -->|"writes CSV"| node_storage
node_entry -->|"records run"| node_runlogs
node_runlogs -->|"saves log"| node_storage
node_storage -->|"stores"| node_results
node_entry -.->|"applies corrections"| node_ocrfixes

click node_entry "https://github.com/sk-tek/statement-extractor/blob/main/src/main.py"
click node_settings "https://github.com/sk-tek/statement-extractor/blob/main/src/config.py"
click node_storage "https://github.com/sk-tek/statement-extractor/blob/main/src/storage.py"
click node_input "https://github.com/sk-tek/statement-extractor/blob/main/src/inputs.py"
click node_unlock "https://github.com/sk-tek/statement-extractor/blob/main/src/unlock.py"
click node_ocr "https://github.com/sk-tek/statement-extractor/blob/main/src/document_ai.py"
click node_raw "https://github.com/sk-tek/statement-extractor/blob/main/src/storage.py"
click node_words "https://github.com/sk-tek/statement-extractor/blob/main/src/words.py"
click node_bankconfigs "https://github.com/sk-tek/statement-extractor/tree/main/config"
click node_banks "https://github.com/sk-tek/statement-extractor/blob/main/src/banks.py"
click node_rows "https://github.com/sk-tek/statement-extractor/blob/main/src/rows.py"
click node_parser "https://github.com/sk-tek/statement-extractor/blob/main/src/parser.py"
click node_ids "https://github.com/sk-tek/statement-extractor/blob/main/src/ids.py"
click node_normalize "https://github.com/sk-tek/statement-extractor/blob/main/src/normalize.py"
click node_ocrfixes "https://github.com/sk-tek/statement-extractor/blob/main/src/ocr_fixes.py"
click node_validate "https://github.com/sk-tek/statement-extractor/blob/main/src/validate.py"
click node_dedupe "https://github.com/sk-tek/statement-extractor/blob/main/src/dedupe.py"
click node_export "https://github.com/sk-tek/statement-extractor/blob/main/src/export_csv.py"
click node_runlogs "https://github.com/sk-tek/statement-extractor/blob/main/src/logger.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_input,node_unlock,node_ocr,node_raw,node_ids toneBlue
class node_words,node_bankconfigs,node_banks,node_rows,node_parser toneAmber
class node_normalize,node_ocrfixes,node_validate,node_dedupe toneMint
class node_entry,node_settings,node_storage,node_export,node_runlogs toneRose
class node_operator,node_pdfs,node_results toneIndigo
```

## Components

### Input and OCR

- [Input checks](https://github.com/sk-tek/statement-extractor/blob/main/src/inputs.py): `src/inputs.py`
- [PDF unlocking](https://github.com/sk-tek/statement-extractor/blob/main/src/unlock.py): `src/unlock.py`
- [Document AI OCR](https://github.com/sk-tek/statement-extractor/blob/main/src/document_ai.py): `src/document_ai.py`
- [Raw OCR cache](https://github.com/sk-tek/statement-extractor/blob/main/src/storage.py): `src/storage.py`
- [File identity](https://github.com/sk-tek/statement-extractor/blob/main/src/ids.py): `src/ids.py`

### Parsing and bank layouts

- [OCR word records](https://github.com/sk-tek/statement-extractor/blob/main/src/words.py): `src/words.py`
- [Bank layout configs](https://github.com/sk-tek/statement-extractor/tree/main/config): `config`
- [Bank layout handling](https://github.com/sk-tek/statement-extractor/blob/main/src/banks.py): `src/banks.py`
- [Rows and columns](https://github.com/sk-tek/statement-extractor/blob/main/src/rows.py): `src/rows.py`
- [Transaction parsing](https://github.com/sk-tek/statement-extractor/blob/main/src/parser.py): `src/parser.py`

### Transaction quality

- [Normalization](https://github.com/sk-tek/statement-extractor/blob/main/src/normalize.py): `src/normalize.py`
- [OCR corrections](https://github.com/sk-tek/statement-extractor/blob/main/src/ocr_fixes.py): `src/ocr_fixes.py`
- [Financial validation](https://github.com/sk-tek/statement-extractor/blob/main/src/validate.py): `src/validate.py`
- [Transaction deduplication](https://github.com/sk-tek/statement-extractor/blob/main/src/dedupe.py): `src/dedupe.py`

### Runtime and outputs

- [CLI pipeline](https://github.com/sk-tek/statement-extractor/blob/main/src/main.py): `src/main.py`
- [Runtime settings](https://github.com/sk-tek/statement-extractor/blob/main/src/config.py): `src/config.py`
- [Data storage](https://github.com/sk-tek/statement-extractor/blob/main/src/storage.py): `src/storage.py`
- [CSV reports](https://github.com/sk-tek/statement-extractor/blob/main/src/export_csv.py): `src/export_csv.py`
- [Run logging](https://github.com/sk-tek/statement-extractor/blob/main/src/logger.py): `src/logger.py`

### Other components

- **Operator**
- **Statement PDFs**
- **CSV and run artifacts**

## Connections

- Operator → CLI pipeline: runs (evidence: `README.md`)
- Statement PDFs → Input checks: supplies (evidence: `README.md`)
- CLI pipeline → Runtime settings: loads (evidence: `src/main.py`)
- CLI pipeline → Data storage: selects (evidence: `src/main.py`)
- CLI pipeline → Input checks: checks (evidence: `src/main.py`)
- Input checks → File identity: hashes (evidence: `src/inputs.py`)
- Input checks → PDF unlocking: unlocks (evidence: `src/inputs.py`)
- CLI pipeline → Document AI OCR: requests OCR (evidence: `README.md`)
- CLI pipeline → Raw OCR cache: caches OCR (evidence: `README.md`)
- CLI pipeline → OCR word records: extracts tokens (evidence: `README.md`)
- CLI pipeline → Bank layout handling: detects layout (evidence: `README.md`)
- Bank layout handling → Bank layout configs: tries layouts (evidence: `README.md`)
- CLI pipeline → Rows and columns: forms rows (evidence: `README.md`)
- Rows and columns → OCR word records: groups tokens (evidence: `src/rows.py`)
- CLI pipeline → Transaction parsing: parses rows (evidence: `README.md`)
- CLI pipeline → Normalization: normalizes (evidence: `README.md`)
- CLI pipeline → Financial validation: validates (evidence: `README.md`)
- Financial validation → Normalization: checks records (evidence: `src/validate.py`)
- CLI pipeline → Transaction deduplication: deduplicates (evidence: `README.md`)
- CLI pipeline → CSV reports: writes reports (evidence: `src/main.py`)
- CSV reports → Data storage: writes CSV (evidence: `src/export_csv.py`)
- CLI pipeline → Run logging: records run (evidence: `src/main.py`)
- Run logging → Data storage: saves log (evidence: `src/logger.py`)
- Data storage → CSV and run artifacts: stores (evidence: `README.md`)
- CLI pipeline → OCR corrections: applies corrections
