# bhardwajtanuj/insurance-document-parser architecture

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

- Interactive diagram: https://gitdiagram.com/bhardwajtanuj/insurance-document-parser
- Repository: https://github.com/bhardwajtanuj/insurance-document-parser

## Overview

This is a command-line insurance document extraction engine. Its main workflow loads a PDF or text file, preprocesses the text, selects insurer patterns, extracts fields with regex and fuzzy matching, scores confidence, and prints results. The graph follows the sampled runtime calls; the README describes insurer pattern modules, but those files are not present in the supplied tree, so their implementation is not represented.

Main entry points: [`main.py`](https://github.com/bhardwajtanuj/insurance-document-parser/blob/main/main.py) (CLI Workflow), [`extractor.py`](https://github.com/bhardwajtanuj/insurance-document-parser/blob/main/extractor.py) (Field Extractor), [`loader.py`](https://github.com/bhardwajtanuj/insurance-document-parser/blob/main/loader.py) (Document Loader), [`preprocessor.py`](https://github.com/bhardwajtanuj/insurance-document-parser/blob/main/preprocessor.py) (Text Preprocessor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["Input Handling"]
  node_cli["CLI Workflow<br/>[main.py]"]
  node_loader["Document Loader<br/>[loader.py]"]
  node_ocr["OCR Engine"]
  node_preprocess["Text Preprocessor<br/>[preprocessor.py]"]
end

subgraph group_extraction["Extraction"]
  node_pattern_select["Pattern Selection<br/>[main.py]"]
  node_field_extractor["Field Extractor<br/>[extractor.py]"]
  node_regex["Regex Matching<br/>[extractor.py]"]
  node_fuzzy["Fuzzy Matching<br/>[extractor.py]"]
  node_confidence["Confidence Scoring<br/>[scorer.py]"]
end

subgraph group_results["Results"]
  node_output["Result Formatting<br/>[main.py]"]
end

node_user(("Document User"))

node_user -->|"provides document"| node_cli
node_cli -->|"loads document"| node_loader
node_loader -->|"uses OCR"| node_ocr
node_cli -->|"cleans text"| node_preprocess
node_cli -->|"selects patterns"| node_pattern_select
node_cli -->|"invokes extraction"| node_field_extractor
node_field_extractor -->|"tries first"| node_regex
node_field_extractor -->|"falls back"| node_fuzzy
node_field_extractor -->|"calculates confidence"| node_confidence
node_cli -->|"prints results"| node_output
node_field_extractor -->|"returns results"| node_output

click node_cli "https://github.com/bhardwajtanuj/insurance-document-parser/blob/main/main.py"
click node_loader "https://github.com/bhardwajtanuj/insurance-document-parser/blob/main/loader.py"
click node_preprocess "https://github.com/bhardwajtanuj/insurance-document-parser/blob/main/preprocessor.py"
click node_pattern_select "https://github.com/bhardwajtanuj/insurance-document-parser/blob/main/main.py"
click node_field_extractor "https://github.com/bhardwajtanuj/insurance-document-parser/blob/main/extractor.py"
click node_regex "https://github.com/bhardwajtanuj/insurance-document-parser/blob/main/extractor.py"
click node_fuzzy "https://github.com/bhardwajtanuj/insurance-document-parser/blob/main/extractor.py"
click node_confidence "https://github.com/bhardwajtanuj/insurance-document-parser/blob/main/scorer.py"
click node_output "https://github.com/bhardwajtanuj/insurance-document-parser/blob/main/main.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_cli,node_loader,node_ocr,node_preprocess,node_user toneBlue
class node_pattern_select,node_field_extractor,node_regex,node_fuzzy,node_confidence toneAmber
class node_output toneMint
```

## Components

### Input Handling

- [CLI Workflow](https://github.com/bhardwajtanuj/insurance-document-parser/blob/main/main.py): `main.py`
- [Document Loader](https://github.com/bhardwajtanuj/insurance-document-parser/blob/main/loader.py): `loader.py`
- **OCR Engine**
- [Text Preprocessor](https://github.com/bhardwajtanuj/insurance-document-parser/blob/main/preprocessor.py): `preprocessor.py`

### Extraction

- [Pattern Selection](https://github.com/bhardwajtanuj/insurance-document-parser/blob/main/main.py): `main.py`
- [Field Extractor](https://github.com/bhardwajtanuj/insurance-document-parser/blob/main/extractor.py): `extractor.py`
- [Regex Matching](https://github.com/bhardwajtanuj/insurance-document-parser/blob/main/extractor.py): `extractor.py`
- [Fuzzy Matching](https://github.com/bhardwajtanuj/insurance-document-parser/blob/main/extractor.py): `extractor.py`
- [Confidence Scoring](https://github.com/bhardwajtanuj/insurance-document-parser/blob/main/scorer.py): `scorer.py`

### Results

- [Result Formatting](https://github.com/bhardwajtanuj/insurance-document-parser/blob/main/main.py): `main.py`

### Other components

- **Document User**

## Connections

- Document User → CLI Workflow: provides document (evidence: `main.py`)
- CLI Workflow → Document Loader: loads document (evidence: `main.py`)
- Document Loader → OCR Engine: uses OCR (evidence: `loader.py`)
- CLI Workflow → Text Preprocessor: cleans text (evidence: `main.py`)
- CLI Workflow → Pattern Selection: selects patterns (evidence: `main.py`)
- CLI Workflow → Field Extractor: invokes extraction (evidence: `main.py`)
- Field Extractor → Regex Matching: tries first (evidence: `extractor.py`)
- Field Extractor → Fuzzy Matching: falls back (evidence: `extractor.py`)
- Field Extractor → Confidence Scoring: calculates confidence (evidence: `extractor.py`)
- CLI Workflow → Result Formatting: prints results (evidence: `main.py`)
- Field Extractor → Result Formatting: returns results (evidence: `main.py`)
