# orbisearendel/re-dact architecture

> Architecture diagram of the GitHub repository orbisearendel/re-dact, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/orbisearendel/re-dact
- Repository: https://github.com/orbisearendel/re-dact

## Overview

RE-DACT is an offline, in-memory document de-identification engine with a built-in web interface. Its principal workflow accepts a document, validates and routes it for native extraction or OCR, detects and selects sensitive spans under a legal policy, applies a chosen redaction level, writes a format-specific result, and supports verification and signed audit reporting. The README also describes dataset, image, and plaintext adapters. Some of those implementations were not excerpted, so their relationships are shown only where documented; unsampled internals are not inferred.

Main entry points: [`server.py`](https://github.com/orbisearendel/re-dact/blob/master/server.py) (HTTP server), [`redact/extract/pdf.py`](https://github.com/orbisearendel/re-dact/blob/master/redact/extract/pdf.py) (PDF extraction), [`redact/writers/pdf.py`](https://github.com/orbisearendel/re-dact/blob/master/redact/writers/pdf.py) (PDF redaction), [`redact/gate.py`](https://github.com/orbisearendel/re-dact/blob/master/redact/gate.py) (Content gate)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Ingestion and extraction"]
  node_gate["Content gate<br/>[gate.py]"]
  node_extract["Format extraction"]
  node_pdf_extract["PDF extraction<br/>[pdf.py]"]
  node_ocr["OCR extraction<br/>[ocr.py]"]
end

subgraph group_detect["Detection and policy"]
  node_entity["Span model<br/>[entity.py]"]
  node_regex["Regex and checksums<br/>[regex_rules.py]"]
  node_context["Context rules<br/>[context_rules.py]"]
  node_ner["Local NER<br/>[gliner_ner.py]"]
  node_visual["Visual PII<br/>[visual.py]"]
  node_merge["Span merging<br/>[merge.py]"]
  node_policy["Legal policy<br/>[policy.py]"]
end

subgraph group_transform["Transform and output"]
  node_levels["Level transforms<br/>[levels.py]"]
  node_writers["Format adapters"]
  node_pdf_writer["PDF redaction<br/>[pdf.py]"]
  node_image_writer["Image redaction<br/>[image.py]"]
end

subgraph group_assurance["Verification and audit"]
  node_rescan["Anti-leak rescan<br/>[rescan.py]"]
  node_audit["Audit report<br/>[report.py]"]
end

subgraph group_interface["Web application"]
  node_server["HTTP server<br/>[server.py]"]
  node_ui["Browser UI<br/>[index.html]"]
end

node_user(("Document user"))

node_user -->|"uploads document"| node_ui
node_ui -->|"submits job"| node_server
node_server -.->|"validates input"| node_gate
node_gate -->|"routes content"| node_extract
node_extract -.->|"extracts PDF"| node_pdf_extract
node_pdf_extract -->|"gets route plan"| node_gate
node_pdf_extract -->|"uses OCR"| node_ocr
node_pdf_extract -->|"detects visual PII"| node_visual
node_server -.->|"runs redaction"| node_pdf_writer
node_pdf_writer -->|"extracts document"| node_pdf_extract
node_pdf_writer -->|"filters entities"| node_policy
node_regex -->|"uses context rules"| node_context
node_ner -->|"merges spans"| node_merge
node_server -.->|"configures policy"| node_policy
node_policy -->|"selects level"| node_levels
node_server -.->|"sets level"| node_levels
node_server -.->|"dispatches formats"| node_writers
node_writers -.->|"writes images"| node_image_writer
node_server -.->|"verifies output"| node_rescan
node_server -.->|"builds report"| node_audit
node_audit -.->|"provides certificate"| node_user

click node_server "https://github.com/orbisearendel/re-dact/blob/master/server.py"
click node_ui "https://github.com/orbisearendel/re-dact/blob/master/ui/index.html"
click node_gate "https://github.com/orbisearendel/re-dact/blob/master/redact/gate.py"
click node_extract "https://github.com/orbisearendel/re-dact/tree/master/redact/extract"
click node_pdf_extract "https://github.com/orbisearendel/re-dact/blob/master/redact/extract/pdf.py"
click node_ocr "https://github.com/orbisearendel/re-dact/blob/master/redact/extract/ocr.py"
click node_entity "https://github.com/orbisearendel/re-dact/blob/master/redact/entity.py"
click node_regex "https://github.com/orbisearendel/re-dact/blob/master/redact/detect/regex_rules.py"
click node_context "https://github.com/orbisearendel/re-dact/blob/master/redact/detect/context_rules.py"
click node_ner "https://github.com/orbisearendel/re-dact/blob/master/redact/detect/gliner_ner.py"
click node_visual "https://github.com/orbisearendel/re-dact/blob/master/redact/detect/visual.py"
click node_merge "https://github.com/orbisearendel/re-dact/blob/master/redact/detect/merge.py"
click node_policy "https://github.com/orbisearendel/re-dact/blob/master/redact/policy/policy.py"
click node_levels "https://github.com/orbisearendel/re-dact/blob/master/redact/transform/levels.py"
click node_writers "https://github.com/orbisearendel/re-dact/tree/master/redact/writers"
click node_pdf_writer "https://github.com/orbisearendel/re-dact/blob/master/redact/writers/pdf.py"
click node_image_writer "https://github.com/orbisearendel/re-dact/blob/master/redact/writers/image.py"
click node_rescan "https://github.com/orbisearendel/re-dact/blob/master/redact/verify/rescan.py"
click node_audit "https://github.com/orbisearendel/re-dact/blob/master/redact/verify/report.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_gate,node_extract,node_pdf_extract,node_ocr,node_user toneBlue
class node_entity,node_regex,node_context,node_ner,node_visual,node_merge,node_policy toneAmber
class node_levels,node_writers,node_pdf_writer,node_image_writer toneMint
class node_rescan,node_audit toneRose
class node_server,node_ui toneIndigo
```

## Components

### Ingestion and extraction

- [Content gate](https://github.com/orbisearendel/re-dact/blob/master/redact/gate.py): `redact/gate.py`
- [Format extraction](https://github.com/orbisearendel/re-dact/tree/master/redact/extract): `redact/extract`
- [PDF extraction](https://github.com/orbisearendel/re-dact/blob/master/redact/extract/pdf.py): `redact/extract/pdf.py`
- [OCR extraction](https://github.com/orbisearendel/re-dact/blob/master/redact/extract/ocr.py): `redact/extract/ocr.py`

### Detection and policy

- [Span model](https://github.com/orbisearendel/re-dact/blob/master/redact/entity.py): `redact/entity.py`
- [Regex and checksums](https://github.com/orbisearendel/re-dact/blob/master/redact/detect/regex_rules.py): `redact/detect/regex_rules.py`
- [Context rules](https://github.com/orbisearendel/re-dact/blob/master/redact/detect/context_rules.py): `redact/detect/context_rules.py`
- [Local NER](https://github.com/orbisearendel/re-dact/blob/master/redact/detect/gliner_ner.py): `redact/detect/gliner_ner.py`
- [Visual PII](https://github.com/orbisearendel/re-dact/blob/master/redact/detect/visual.py): `redact/detect/visual.py`
- [Span merging](https://github.com/orbisearendel/re-dact/blob/master/redact/detect/merge.py): `redact/detect/merge.py`
- [Legal policy](https://github.com/orbisearendel/re-dact/blob/master/redact/policy/policy.py): `redact/policy/policy.py`

### Transform and output

- [Level transforms](https://github.com/orbisearendel/re-dact/blob/master/redact/transform/levels.py): `redact/transform/levels.py`
- [Format adapters](https://github.com/orbisearendel/re-dact/tree/master/redact/writers): `redact/writers`
- [PDF redaction](https://github.com/orbisearendel/re-dact/blob/master/redact/writers/pdf.py): `redact/writers/pdf.py`
- [Image redaction](https://github.com/orbisearendel/re-dact/blob/master/redact/writers/image.py): `redact/writers/image.py`

### Verification and audit

- [Anti-leak rescan](https://github.com/orbisearendel/re-dact/blob/master/redact/verify/rescan.py): `redact/verify/rescan.py`
- [Audit report](https://github.com/orbisearendel/re-dact/blob/master/redact/verify/report.py): `redact/verify/report.py`

### Web application

- [HTTP server](https://github.com/orbisearendel/re-dact/blob/master/server.py): `server.py`
- [Browser UI](https://github.com/orbisearendel/re-dact/blob/master/ui/index.html): `ui/index.html`

### Other components

- **Document user**

## Connections

- Document user → Browser UI: uploads document (evidence: `README.md`)
- Browser UI → HTTP server: submits job (evidence: `server.py`)
- HTTP server → Content gate: validates input
- Content gate → Format extraction: routes content (evidence: `redact/gate.py`)
- Format extraction → PDF extraction: extracts PDF (evidence: `redact/extract/__init__.py`)
- PDF extraction → Content gate: gets route plan (evidence: `redact/extract/pdf.py`)
- PDF extraction → OCR extraction: uses OCR (evidence: `redact/extract/pdf.py`)
- PDF extraction → Visual PII: detects visual PII (evidence: `redact/extract/pdf.py`)
- HTTP server → PDF redaction: runs redaction (evidence: `server.py`)
- PDF redaction → PDF extraction: extracts document (evidence: `redact/writers/pdf.py`)
- PDF redaction → Legal policy: filters entities (evidence: `redact/writers/pdf.py`)
- Regex and checksums → Context rules: uses context rules (evidence: `redact/detect/regex_rules.py`)
- Local NER → Span merging: merges spans (evidence: `redact/detect/gliner_ner.py`)
- HTTP server → Legal policy: configures policy (evidence: `server.py`)
- Legal policy → Level transforms: selects level (evidence: `redact/transform/levels.py`)
- HTTP server → Level transforms: sets level (evidence: `server.py`)
- HTTP server → Format adapters: dispatches formats (evidence: `server.py`)
- Format adapters → Image redaction: writes images (evidence: `README.md`)
- HTTP server → Anti-leak rescan: verifies output
- HTTP server → Audit report: builds report
- Audit report → Document user: provides certificate (evidence: `README.md`)
