# akshit-saharia/cadence-pii-shield architecture

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

- Interactive diagram: https://gitdiagram.com/akshit-saharia/cadence-pii-shield
- Repository: https://github.com/akshit-saharia/cadence-pii-shield

## Overview

Cadence PII Shield turns PDF, DOCX, and PPTX files into protected text for downstream LLM use: it extracts document content and images, OCRs embedded images, detects PII, classifies and redacts it, then releases only files allowed by a fail-closed gate. Its result also supports exposure reporting and token rehydration for end-user responses. The README documents the Streamlit UI and evaluation capability; evaluation wiring is not shown in the sampled evidence, so no evaluation flow is inferred.

Main entry points: [`redaction/pipeline.py`](https://github.com/akshit-saharia/cadence-pii-shield/blob/main/redaction/pipeline.py) (Protection pipeline), [`extraction/router.py`](https://github.com/akshit-saharia/cadence-pii-shield/blob/main/extraction/router.py) (Format router), [`detection/engine.py`](https://github.com/akshit-saharia/cadence-pii-shield/blob/main/detection/engine.py) (Detection engine), [`app/streamlit_app.py`](https://github.com/akshit-saharia/cadence-pii-shield/blob/main/app/streamlit_app.py) (Streamlit UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_intake["Document Intake"]
  node_extract_router["Format router<br/>[router.py]"]
  node_pdf_extract["PDF extraction<br/>[pdf_extractor.py]"]
  node_docx_extract["DOCX extraction<br/>[docx_extractor.py]"]
  node_pptx_extract["PPTX extraction<br/>[pptx_extractor.py]"]
  node_ocr_stage["Image OCR stage<br/>[ocr_stage.py]"]
  node_ocr_pipeline["OCR pipeline<br/>[ocr_pipeline.py]"]
  node_ocr_engine["Tesseract engine<br/>[engine.py]"]
end

subgraph group_detection["PII Detection"]
  node_detection_engine["Detection engine<br/>[engine.py]"]
  node_recognizers["PII recognizers"]
  node_allowlist["False-positive controls<br/>[allowlist.py]"]
end

subgraph group_protection["Protection and Release"]
  node_protection_pipeline["Protection pipeline<br/>[pipeline.py]"]
  node_classifier["Risk classifier<br/>[classifier.py]"]
  node_redactor["PII redactor<br/>[redactor.py]"]
  node_tokenizer["Token formatter<br/>[tokenizer.py]"]
  node_vault[("Token vault<br/>[vault.py]")]
  node_gate["Fail-closed gate<br/>[gate.py]"]
  node_report["Exposure report<br/>[report.py]"]
end

subgraph group_shared["Shared Contracts"]
  node_schemas["Shared data schemas<br/>[schemas.py]"]
  node_config["Shared settings<br/>[config.py]"]
end

subgraph group_interface["User Interface"]
  node_streamlit["Streamlit UI<br/>[streamlit_app.py]"]
  node_cli["CLI entrypoint<br/>[pipeline.py]"]
end

node_user(("Document user"))
node_llm(("LLM consumer"))

node_user -->|"uses"| node_streamlit
node_user -->|"runs"| node_cli
node_streamlit -->|"uses"| node_protection_pipeline
node_streamlit -->|"uses"| node_report
node_cli -->|"invokes"| node_protection_pipeline
node_protection_pipeline -->|"extracts files"| node_extract_router
node_extract_router -->|"dispatches"| node_pdf_extract
node_extract_router -->|"dispatches"| node_docx_extract
node_extract_router -->|"dispatches"| node_pptx_extract
node_protection_pipeline -->|"processes images"| node_ocr_stage
node_ocr_stage -->|"requests OCR"| node_ocr_pipeline
node_ocr_pipeline -->|"recognizes text"| node_ocr_engine
node_protection_pipeline -->|"detects PII"| node_detection_engine
node_detection_engine -->|"generates candidates"| node_recognizers
node_detection_engine -->|"filters spans"| node_allowlist
node_protection_pipeline -->|"classifies findings"| node_classifier
node_protection_pipeline -->|"redacts findings"| node_redactor
node_redactor -->|"stores reversible tokens"| node_vault
node_vault -->|"formats tokens"| node_tokenizer
node_protection_pipeline -->|"evaluates release"| node_gate
node_protection_pipeline -->|"builds report"| node_report
node_protection_pipeline -->|"uses result models"| node_schemas
node_protection_pipeline -->|"reads settings"| node_config
node_llm -->|"receives allowed payload"| node_protection_pipeline

click node_streamlit "https://github.com/akshit-saharia/cadence-pii-shield/blob/main/app/streamlit_app.py"
click node_cli "https://github.com/akshit-saharia/cadence-pii-shield/blob/main/pipeline.py"
click node_protection_pipeline "https://github.com/akshit-saharia/cadence-pii-shield/blob/main/redaction/pipeline.py"
click node_extract_router "https://github.com/akshit-saharia/cadence-pii-shield/blob/main/extraction/router.py"
click node_pdf_extract "https://github.com/akshit-saharia/cadence-pii-shield/blob/main/extraction/pdf_extractor.py"
click node_docx_extract "https://github.com/akshit-saharia/cadence-pii-shield/blob/main/extraction/docx_extractor.py"
click node_pptx_extract "https://github.com/akshit-saharia/cadence-pii-shield/blob/main/extraction/pptx_extractor.py"
click node_ocr_stage "https://github.com/akshit-saharia/cadence-pii-shield/blob/main/redaction/ocr_stage.py"
click node_ocr_pipeline "https://github.com/akshit-saharia/cadence-pii-shield/blob/main/ocr/ocr_pipeline.py"
click node_ocr_engine "https://github.com/akshit-saharia/cadence-pii-shield/blob/main/ocr/engine.py"
click node_detection_engine "https://github.com/akshit-saharia/cadence-pii-shield/blob/main/detection/engine.py"
click node_recognizers "https://github.com/akshit-saharia/cadence-pii-shield/tree/main/detection/recognizers"
click node_allowlist "https://github.com/akshit-saharia/cadence-pii-shield/blob/main/detection/allowlist.py"
click node_classifier "https://github.com/akshit-saharia/cadence-pii-shield/blob/main/redaction/classifier.py"
click node_redactor "https://github.com/akshit-saharia/cadence-pii-shield/blob/main/redaction/redactor.py"
click node_tokenizer "https://github.com/akshit-saharia/cadence-pii-shield/blob/main/redaction/tokenizer.py"
click node_vault "https://github.com/akshit-saharia/cadence-pii-shield/blob/main/redaction/vault.py"
click node_gate "https://github.com/akshit-saharia/cadence-pii-shield/blob/main/redaction/gate.py"
click node_report "https://github.com/akshit-saharia/cadence-pii-shield/blob/main/redaction/report.py"
click node_schemas "https://github.com/akshit-saharia/cadence-pii-shield/blob/main/schemas.py"
click node_config "https://github.com/akshit-saharia/cadence-pii-shield/blob/main/config.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_extract_router,node_pdf_extract,node_docx_extract,node_pptx_extract,node_ocr_stage,node_ocr_pipeline,node_ocr_engine,node_user toneBlue
class node_detection_engine,node_recognizers,node_allowlist toneAmber
class node_protection_pipeline,node_classifier,node_redactor,node_tokenizer,node_vault,node_gate,node_report toneMint
class node_schemas,node_config toneRose
class node_streamlit,node_cli,node_llm toneIndigo
```

## Components

### Document Intake

- [Format router](https://github.com/akshit-saharia/cadence-pii-shield/blob/main/extraction/router.py): `extraction/router.py`
- [PDF extraction](https://github.com/akshit-saharia/cadence-pii-shield/blob/main/extraction/pdf_extractor.py): `extraction/pdf_extractor.py`
- [DOCX extraction](https://github.com/akshit-saharia/cadence-pii-shield/blob/main/extraction/docx_extractor.py): `extraction/docx_extractor.py`
- [PPTX extraction](https://github.com/akshit-saharia/cadence-pii-shield/blob/main/extraction/pptx_extractor.py): `extraction/pptx_extractor.py`
- [Image OCR stage](https://github.com/akshit-saharia/cadence-pii-shield/blob/main/redaction/ocr_stage.py): `redaction/ocr_stage.py`
- [OCR pipeline](https://github.com/akshit-saharia/cadence-pii-shield/blob/main/ocr/ocr_pipeline.py): `ocr/ocr_pipeline.py`
- [Tesseract engine](https://github.com/akshit-saharia/cadence-pii-shield/blob/main/ocr/engine.py): `ocr/engine.py`

### PII Detection

- [Detection engine](https://github.com/akshit-saharia/cadence-pii-shield/blob/main/detection/engine.py): `detection/engine.py`
- [PII recognizers](https://github.com/akshit-saharia/cadence-pii-shield/tree/main/detection/recognizers): `detection/recognizers`
- [False-positive controls](https://github.com/akshit-saharia/cadence-pii-shield/blob/main/detection/allowlist.py): `detection/allowlist.py`

### Protection and Release

- [Protection pipeline](https://github.com/akshit-saharia/cadence-pii-shield/blob/main/redaction/pipeline.py): `redaction/pipeline.py`
- [Risk classifier](https://github.com/akshit-saharia/cadence-pii-shield/blob/main/redaction/classifier.py): `redaction/classifier.py`
- [PII redactor](https://github.com/akshit-saharia/cadence-pii-shield/blob/main/redaction/redactor.py): `redaction/redactor.py`
- [Token formatter](https://github.com/akshit-saharia/cadence-pii-shield/blob/main/redaction/tokenizer.py): `redaction/tokenizer.py`
- [Token vault](https://github.com/akshit-saharia/cadence-pii-shield/blob/main/redaction/vault.py): `redaction/vault.py`
- [Fail-closed gate](https://github.com/akshit-saharia/cadence-pii-shield/blob/main/redaction/gate.py): `redaction/gate.py`
- [Exposure report](https://github.com/akshit-saharia/cadence-pii-shield/blob/main/redaction/report.py): `redaction/report.py`

### Shared Contracts

- [Shared data schemas](https://github.com/akshit-saharia/cadence-pii-shield/blob/main/schemas.py): `schemas.py`
- [Shared settings](https://github.com/akshit-saharia/cadence-pii-shield/blob/main/config.py): `config.py`

### User Interface

- [Streamlit UI](https://github.com/akshit-saharia/cadence-pii-shield/blob/main/app/streamlit_app.py): `app/streamlit_app.py`
- [CLI entrypoint](https://github.com/akshit-saharia/cadence-pii-shield/blob/main/pipeline.py): `pipeline.py`

### Other components

- **Document user**
- **LLM consumer**

## Connections

- Document user → Streamlit UI: uses (evidence: `README.md`)
- Document user → CLI entrypoint: runs (evidence: `README.md`)
- Streamlit UI → Protection pipeline: uses (evidence: `app/streamlit_app.py`)
- Streamlit UI → Exposure report: uses (evidence: `app/streamlit_app.py`)
- CLI entrypoint → Protection pipeline: invokes (evidence: `pipeline.py`)
- Protection pipeline → Format router: extracts files (evidence: `redaction/pipeline.py`)
- Format router → PDF extraction: dispatches (evidence: `extraction/router.py`)
- Format router → DOCX extraction: dispatches (evidence: `extraction/router.py`)
- Format router → PPTX extraction: dispatches (evidence: `extraction/router.py`)
- Protection pipeline → Image OCR stage: processes images (evidence: `redaction/pipeline.py`)
- Image OCR stage → OCR pipeline: requests OCR (evidence: `redaction/ocr_stage.py`)
- OCR pipeline → Tesseract engine: recognizes text (evidence: `ocr/ocr_pipeline.py`)
- Protection pipeline → Detection engine: detects PII (evidence: `redaction/pipeline.py`)
- Detection engine → PII recognizers: generates candidates (evidence: `detection/engine.py`)
- Detection engine → False-positive controls: filters spans (evidence: `detection/engine.py`)
- Protection pipeline → Risk classifier: classifies findings (evidence: `redaction/pipeline.py`)
- Protection pipeline → PII redactor: redacts findings (evidence: `redaction/pipeline.py`)
- PII redactor → Token vault: stores reversible tokens (evidence: `redaction/redactor.py`)
- Token vault → Token formatter: formats tokens (evidence: `redaction/vault.py`)
- Protection pipeline → Fail-closed gate: evaluates release (evidence: `redaction/pipeline.py`)
- Protection pipeline → Exposure report: builds report (evidence: `redaction/pipeline.py`)
- Protection pipeline → Shared data schemas: uses result models (evidence: `redaction/pipeline.py`)
- Protection pipeline → Shared settings: reads settings (evidence: `redaction/pipeline.py`)
- LLM consumer → Protection pipeline: receives allowed payload (evidence: `README.md`)
