# mithun50/medveil architecture

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

- Interactive diagram: https://gitdiagram.com/mithun50/medveil
- Repository: https://github.com/mithun50/medveil

## Overview

MedVeil is an offline privacy firewall for multilingual Indian hospital records. Its documented workflow takes an input directory and policy, parses supported records, learns context, detects sensitive and clinically protected spans, links records, plans privacy transformations, rewrites files, checks for leaks, and writes sanitized output and reports. The graph retains detection, identity resolution, privacy, and security layers; several connections rely on the CLI’s pipeline description because implementation excerpts are incomplete.

Main entry points: [`medveil/cli.py`](https://github.com/mithun50/medveil/blob/main/medveil/cli.py) (CLI workflow), [`medveil/detect/engine.py`](https://github.com/mithun50/medveil/blob/main/medveil/detect/engine.py) (Detection engine), [`medveil/ingest.py`](https://github.com/mithun50/medveil/blob/main/medveil/ingest.py) (Ingest and parse), [`medveil/rewrite.py`](https://github.com/mithun50/medveil/blob/main/medveil/rewrite.py) (Rewrite and serialize)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Workflow and I/O"]
  node_cli["CLI workflow<br/>[cli.py]"]
  node_policy["Policy config<br/>[policy.yaml]"]
  node_ingest["Ingest and parse<br/>[ingest.py]"]
  node_model["Record model<br/>[model.py]"]
  node_rewrite["Rewrite and serialize<br/>[rewrite.py]"]
  node_outputs["Sanitized files and reports<br/>[cli.py]"]
end

subgraph group_detection["Detection and language"]
  node_textnorm["Text normalization<br/>[textnorm.py]"]
  node_fields["Field classification<br/>[fields.py]"]
  node_engine["Detection engine<br/>[engine.py]"]
  node_patterns["Pattern detection<br/>[patterns.py]"]
  node_names["Name detection<br/>[names.py]"]
  node_dates["Date detection<br/>[dates.py]"]
  node_lexicon["Language lexicons<br/>[lexicon.py]"]
  node_translit["Name transliteration<br/>[translit.py]"]
end

subgraph group_identity["Identity and privacy"]
  node_link["Record linking<br/>[link.py]"]
  node_privacy["Privacy planning<br/>[privacy.py]"]
end

subgraph group_security["Security controls"]
  node_guard["Runtime guard<br/>[guard.py]"]
  node_crypto["Key and vault crypto<br/>[crypto.py]"]
  node_gate["Leak gate<br/>[gate.py]"]
end

node_user(("Operator"))

node_user -->|"runs"| node_cli
node_cli -->|"secures runtime"| node_guard
node_cli -->|"loads policy"| node_policy
node_cli -->|"parses files"| node_ingest
node_ingest -->|"builds records"| node_model
node_cli -->|"classifies fields"| node_fields
node_cli -->|"learns and detects"| node_engine
node_engine -->|"uses patterns"| node_patterns
node_engine -->|"detects names"| node_names
node_engine -->|"detects dates"| node_dates
node_engine -->|"uses vocabularies"| node_lexicon
node_engine -->|"matches scripts"| node_translit
node_ingest -->|"normalizes text"| node_textnorm
node_cli -->|"links records"| node_link
node_cli -->|"plans transformations"| node_privacy
node_privacy -->|"uses cryptography"| node_crypto
node_cli -->|"creates keys and vault"| node_crypto
node_cli -->|"rewrites records"| node_rewrite
node_rewrite -->|"renders shifted dates"| node_dates
node_rewrite -->|"applies transformations"| node_privacy
node_cli -->|"checks leaks"| node_gate
node_cli -->|"writes results"| node_outputs

click node_cli "https://github.com/mithun50/medveil/blob/main/medveil/cli.py"
click node_guard "https://github.com/mithun50/medveil/blob/main/medveil/guard.py"
click node_policy "https://github.com/mithun50/medveil/blob/main/config/policy.yaml"
click node_ingest "https://github.com/mithun50/medveil/blob/main/medveil/ingest.py"
click node_model "https://github.com/mithun50/medveil/blob/main/medveil/model.py"
click node_textnorm "https://github.com/mithun50/medveil/blob/main/medveil/textnorm.py"
click node_fields "https://github.com/mithun50/medveil/blob/main/medveil/detect/fields.py"
click node_engine "https://github.com/mithun50/medveil/blob/main/medveil/detect/engine.py"
click node_patterns "https://github.com/mithun50/medveil/blob/main/medveil/detect/patterns.py"
click node_names "https://github.com/mithun50/medveil/blob/main/medveil/detect/names.py"
click node_dates "https://github.com/mithun50/medveil/blob/main/medveil/detect/dates.py"
click node_lexicon "https://github.com/mithun50/medveil/blob/main/medveil/lexicon.py"
click node_translit "https://github.com/mithun50/medveil/blob/main/medveil/translit.py"
click node_link "https://github.com/mithun50/medveil/blob/main/medveil/link.py"
click node_privacy "https://github.com/mithun50/medveil/blob/main/medveil/privacy.py"
click node_crypto "https://github.com/mithun50/medveil/blob/main/medveil/crypto.py"
click node_rewrite "https://github.com/mithun50/medveil/blob/main/medveil/rewrite.py"
click node_gate "https://github.com/mithun50/medveil/blob/main/medveil/gate.py"
click node_outputs "https://github.com/mithun50/medveil/blob/main/medveil/cli.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_policy,node_ingest,node_model,node_rewrite,node_outputs toneBlue
class node_textnorm,node_fields,node_engine,node_patterns,node_names,node_dates,node_lexicon,node_translit toneAmber
class node_link,node_privacy toneMint
class node_guard,node_crypto,node_gate toneRose
class node_user toneIndigo
```

## Components

### Workflow and I/O

- [CLI workflow](https://github.com/mithun50/medveil/blob/main/medveil/cli.py): `medveil/cli.py`
- [Policy config](https://github.com/mithun50/medveil/blob/main/config/policy.yaml): `config/policy.yaml`
- [Ingest and parse](https://github.com/mithun50/medveil/blob/main/medveil/ingest.py): `medveil/ingest.py`
- [Record model](https://github.com/mithun50/medveil/blob/main/medveil/model.py): `medveil/model.py`
- [Rewrite and serialize](https://github.com/mithun50/medveil/blob/main/medveil/rewrite.py): `medveil/rewrite.py`
- [Sanitized files and reports](https://github.com/mithun50/medveil/blob/main/medveil/cli.py): `medveil/cli.py`

### Detection and language

- [Text normalization](https://github.com/mithun50/medveil/blob/main/medveil/textnorm.py): `medveil/textnorm.py`
- [Field classification](https://github.com/mithun50/medveil/blob/main/medveil/detect/fields.py): `medveil/detect/fields.py`
- [Detection engine](https://github.com/mithun50/medveil/blob/main/medveil/detect/engine.py): `medveil/detect/engine.py`
- [Pattern detection](https://github.com/mithun50/medveil/blob/main/medveil/detect/patterns.py): `medveil/detect/patterns.py`
- [Name detection](https://github.com/mithun50/medveil/blob/main/medveil/detect/names.py): `medveil/detect/names.py`
- [Date detection](https://github.com/mithun50/medveil/blob/main/medveil/detect/dates.py): `medveil/detect/dates.py`
- [Language lexicons](https://github.com/mithun50/medveil/blob/main/medveil/lexicon.py): `medveil/lexicon.py`
- [Name transliteration](https://github.com/mithun50/medveil/blob/main/medveil/translit.py): `medveil/translit.py`

### Identity and privacy

- [Record linking](https://github.com/mithun50/medveil/blob/main/medveil/link.py): `medveil/link.py`
- [Privacy planning](https://github.com/mithun50/medveil/blob/main/medveil/privacy.py): `medveil/privacy.py`

### Security controls

- [Runtime guard](https://github.com/mithun50/medveil/blob/main/medveil/guard.py): `medveil/guard.py`
- [Key and vault crypto](https://github.com/mithun50/medveil/blob/main/medveil/crypto.py): `medveil/crypto.py`
- [Leak gate](https://github.com/mithun50/medveil/blob/main/medveil/gate.py): `medveil/gate.py`

### Other components

- **Operator**

## Connections

- Operator → CLI workflow: runs (evidence: `README.md`)
- CLI workflow → Runtime guard: secures runtime (evidence: `medveil/cli.py`)
- CLI workflow → Policy config: loads policy (evidence: `medveil/cli.py`)
- CLI workflow → Ingest and parse: parses files (evidence: `medveil/cli.py`)
- Ingest and parse → Record model: builds records (evidence: `medveil/ingest.py`)
- CLI workflow → Field classification: classifies fields (evidence: `medveil/cli.py`)
- CLI workflow → Detection engine: learns and detects (evidence: `medveil/cli.py`)
- Detection engine → Pattern detection: uses patterns (evidence: `medveil/detect/engine.py`)
- Detection engine → Name detection: detects names (evidence: `medveil/detect/engine.py`)
- Detection engine → Date detection: detects dates (evidence: `medveil/detect/engine.py`)
- Detection engine → Language lexicons: uses vocabularies (evidence: `medveil/detect/engine.py`)
- Detection engine → Name transliteration: matches scripts (evidence: `medveil/detect/engine.py`)
- Ingest and parse → Text normalization: normalizes text (evidence: `medveil/ingest.py`)
- CLI workflow → Record linking: links records (evidence: `medveil/cli.py`)
- CLI workflow → Privacy planning: plans transformations (evidence: `medveil/cli.py`)
- Privacy planning → Key and vault crypto: uses cryptography (evidence: `medveil/privacy.py`)
- CLI workflow → Key and vault crypto: creates keys and vault (evidence: `medveil/cli.py`)
- CLI workflow → Rewrite and serialize: rewrites records (evidence: `medveil/cli.py`)
- Rewrite and serialize → Date detection: renders shifted dates (evidence: `medveil/rewrite.py`)
- Rewrite and serialize → Privacy planning: applies transformations (evidence: `medveil/rewrite.py`)
- CLI workflow → Leak gate: checks leaks (evidence: `medveil/cli.py`)
- CLI workflow → Sanitized files and reports: writes results (evidence: `medveil/cli.py`)
