# shashi3070/aigov-redact architecture

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

- Interactive diagram: https://gitdiagram.com/shashi3070/aigov-redact
- Repository: https://github.com/shashi3070/aigov-redact

## Overview

aigov-redact is a local-first privacy gateway and redaction library for LLM workflows. Its main reversible path is application text through PrivacyGateway protection, then to an LLM, with the response returned to the session for resolution. A separate classic-redaction path supports one-shot detection and redaction; CLI commands expose detection, redaction, auditing, and usage history. The README documents policy profiles, optional NER, broad pattern coverage, and audit logging. Edges reflect shown calls, imports listed in the source index, or README statements; unsampled or optional integrations are left unverified.

Main entry points: [`src/aigov_redact/gateway/session.py`](https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/gateway/session.py) (Gateway session), [`src/aigov_redact/detector.py`](https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/detector.py) (PII detector), [`src/aigov_redact/cli/main.py`](https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/cli/main.py) (CLI commands), [`src/aigov_redact/gateway/gateway.py`](https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/gateway/gateway.py) (PrivacyGateway)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_gateway["Privacy gateway"]
  node_gateway["PrivacyGateway<br/>[gateway.py]"]
  node_session["Gateway session<br/>[session.py]"]
  node_vault[("Mapping vault<br/>[vault.py]")]
  node_token["Token generator<br/>[token_generator.py]"]
  node_mapping_session["Mapping session<br/>[session.py]"]
  node_numbers["Number transformer<br/>[numbers.py]"]
  node_dates["Date transformer<br/>[dates.py]"]
  node_semantic["Semantic abstraction<br/>[semantic.py]"]
end

subgraph group_detection["Detection and policy"]
  node_policy["Policy engine<br/>[engine.py]"]
  node_detector["PII detector<br/>[detector.py]"]
  node_patterns["PII patterns<br/>[patterns.py]"]
  node_ner["Optional NER<br/>[presidio.py]"]
  node_models["Result models<br/>[models.py]"]
  node_config["Configuration<br/>[config.py]"]
end

subgraph group_classic["Classic redaction"]
  node_redactor["Classic redactor<br/>[redactor.py]"]
  node_cli["CLI commands<br/>[main.py]"]
end

subgraph group_governance["Audit and usage"]
  node_auditor["Log auditor<br/>[auditor.py]"]
  node_usage["Usage history<br/>[usage.py]"]
end

node_app(("Application"))
node_llm["LLM service"]

node_app -->|"protects text"| node_gateway
node_gateway -->|"creates session"| node_session
node_gateway -->|"configures detector"| node_detector
node_gateway -->|"selects policy"| node_policy
node_gateway -->|"configures abstraction"| node_semantic
node_session -->|"detects entities"| node_detector
node_session -->|"gets actions"| node_policy
node_session -->|"registers mappings"| node_vault
node_session -->|"transforms numbers"| node_numbers
node_session -->|"transforms dates"| node_dates
node_session -->|"sends protected text"| node_llm
node_llm -->|"returns response"| node_session
node_session -->|"resolves response"| node_app
node_mapping_session -->|"uses vault"| node_vault
node_mapping_session -->|"creates generator"| node_token
node_numbers -->|"records transforms"| node_vault
node_dates -->|"records transforms"| node_vault
node_detector -->|"matches patterns"| node_patterns
node_detector -->|"builds entities"| node_models
node_config -->|"configures patterns"| node_patterns
node_detector -.-> node_ner
node_app -->|"redacts text"| node_redactor
node_redactor -.->|"detects entities"| node_detector
node_app -->|"runs commands"| node_cli
node_cli -->|"loads configuration"| node_config
node_cli -->|"runs detection"| node_detector
node_cli -->|"runs redaction"| node_redactor
node_cli -->|"runs audits"| node_auditor
node_cli -->|"shows history"| node_usage
node_auditor -->|"scans content"| node_detector
node_auditor -->|"creates entries"| node_models

click node_gateway "https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/gateway/gateway.py"
click node_session "https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/gateway/session.py"
click node_vault "https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/mapping/vault.py"
click node_token "https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/mapping/token_generator.py"
click node_mapping_session "https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/mapping/session.py"
click node_numbers "https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/transformation/numbers.py"
click node_dates "https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/transformation/dates.py"
click node_semantic "https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/transformation/semantic.py"
click node_policy "https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/policy/engine.py"
click node_detector "https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/detector.py"
click node_patterns "https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/patterns.py"
click node_ner "https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/ner/presidio.py"
click node_models "https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/models.py"
click node_config "https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/config.py"
click node_redactor "https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/redactor.py"
click node_cli "https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/cli/main.py"
click node_auditor "https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/auditor.py"
click node_usage "https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/usage.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_gateway,node_session,node_vault,node_token,node_mapping_session,node_numbers,node_dates,node_semantic toneBlue
class node_policy,node_detector,node_patterns,node_ner,node_models,node_config toneAmber
class node_redactor,node_cli toneMint
class node_auditor,node_usage toneRose
class node_app,node_llm toneIndigo
```

## Components

### Privacy gateway

- [PrivacyGateway](https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/gateway/gateway.py): `src/aigov_redact/gateway/gateway.py`
- [Gateway session](https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/gateway/session.py): `src/aigov_redact/gateway/session.py`
- [Mapping vault](https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/mapping/vault.py): `src/aigov_redact/mapping/vault.py`
- [Token generator](https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/mapping/token_generator.py): `src/aigov_redact/mapping/token_generator.py`
- [Mapping session](https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/mapping/session.py): `src/aigov_redact/mapping/session.py`
- [Number transformer](https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/transformation/numbers.py): `src/aigov_redact/transformation/numbers.py`
- [Date transformer](https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/transformation/dates.py): `src/aigov_redact/transformation/dates.py`
- [Semantic abstraction](https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/transformation/semantic.py): `src/aigov_redact/transformation/semantic.py`

### Detection and policy

- [Policy engine](https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/policy/engine.py): `src/aigov_redact/policy/engine.py`
- [PII detector](https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/detector.py): `src/aigov_redact/detector.py`
- [PII patterns](https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/patterns.py): `src/aigov_redact/patterns.py`
- [Optional NER](https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/ner/presidio.py): `src/aigov_redact/ner/presidio.py`
- [Result models](https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/models.py): `src/aigov_redact/models.py`
- [Configuration](https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/config.py): `src/aigov_redact/config.py`

### Classic redaction

- [Classic redactor](https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/redactor.py): `src/aigov_redact/redactor.py`
- [CLI commands](https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/cli/main.py): `src/aigov_redact/cli/main.py`

### Audit and usage

- [Log auditor](https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/auditor.py): `src/aigov_redact/auditor.py`
- [Usage history](https://github.com/shashi3070/aigov-redact/blob/master/src/aigov_redact/usage.py): `src/aigov_redact/usage.py`

### Other components

- **Application**
- **LLM service**

## Connections

- Application → PrivacyGateway: protects text (evidence: `README.md`)
- PrivacyGateway → Gateway session: creates session (evidence: `src/aigov_redact/gateway/gateway.py`)
- PrivacyGateway → PII detector: configures detector (evidence: `src/aigov_redact/gateway/gateway.py`)
- PrivacyGateway → Policy engine: selects policy (evidence: `src/aigov_redact/gateway/gateway.py`)
- PrivacyGateway → Semantic abstraction: configures abstraction (evidence: `src/aigov_redact/gateway/gateway.py`)
- Gateway session → PII detector: detects entities (evidence: `src/aigov_redact/gateway/session.py`)
- Gateway session → Policy engine: gets actions (evidence: `src/aigov_redact/gateway/session.py`)
- Gateway session → Mapping vault: registers mappings (evidence: `src/aigov_redact/gateway/session.py`)
- Gateway session → Number transformer: transforms numbers (evidence: `src/aigov_redact/gateway/session.py`)
- Gateway session → Date transformer: transforms dates (evidence: `src/aigov_redact/gateway/session.py`)
- Gateway session → LLM service: sends protected text (evidence: `README.md`)
- LLM service → Gateway session: returns response (evidence: `README.md`)
- Gateway session → Application: resolves response (evidence: `README.md`)
- Mapping session → Mapping vault: uses vault (evidence: `src/aigov_redact/mapping/session.py`)
- Mapping session → Token generator: creates generator (evidence: `src/aigov_redact/mapping/session.py`)
- Number transformer → Mapping vault: records transforms (evidence: `src/aigov_redact/transformation/numbers.py`)
- Date transformer → Mapping vault: records transforms (evidence: `src/aigov_redact/transformation/dates.py`)
- PII detector → PII patterns: matches patterns (evidence: `src/aigov_redact/detector.py`)
- PII detector → Result models: builds entities (evidence: `src/aigov_redact/detector.py`)
- Configuration → PII patterns: configures patterns (evidence: `src/aigov_redact/config.py`)
- PII detector → Optional NER
- Application → Classic redactor: redacts text (evidence: `README.md`)
- Classic redactor → PII detector: detects entities
- Application → CLI commands: runs commands (evidence: `README.md`)
- CLI commands → Configuration: loads configuration (evidence: `src/aigov_redact/cli/main.py`)
- CLI commands → PII detector: runs detection (evidence: `src/aigov_redact/cli/main.py`)
- CLI commands → Classic redactor: runs redaction (evidence: `src/aigov_redact/cli/main.py`)
- CLI commands → Log auditor: runs audits (evidence: `src/aigov_redact/cli/main.py`)
- CLI commands → Usage history: shows history (evidence: `src/aigov_redact/cli/main.py`)
- Log auditor → PII detector: scans content (evidence: `src/aigov_redact/auditor.py`)
- Log auditor → Result models: creates entries (evidence: `src/aigov_redact/auditor.py`)
