# microsoft/presidio architecture

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

- Interactive diagram: https://gitdiagram.com/microsoft/presidio
- Repository: https://github.com/microsoft/presidio

## Overview

##### Main Components Overview
The system should be divided into four main service components:

a. Presidio Analyzer
- Primary component for PII detection
- Uses NLP engines, recognizers, and pattern matching
- Handles multiple languages and contexts

b. Presidio Anonymizer
- Handles text anonymization and de-identification
- Manages different anonymization operators (mask, hash, encrypt, etc.)
- Processes both single items and batches

c. Presidio Image Redactor
- Handles PII detection and redaction in images
- Supports standard images and DICOM medical images
- Integrates OCR capabilities

d. Presidio Structured
- Manages structured data analysis
- Handles tabular data processing
- Provides data transformation capabilities

##### Key Relationships and Data Flow

**External Input → Analyzer → Anonymizer → Protected Output**
- ↓
- Image Redactor
- ↓
- Structured Data

##### Detailed Component Breakdown

For each main component, include subcomponents:

Analyzer:
- NLP Engine (Spacy/Stanza/Transformers)
- Recognizer Registry
- Pattern Recognizers
- Context Aware Enhancers

Anonymizer:
- Operator Factory
- Encryption Services
- Text Replace Builder
- Batch Processing Engine

Image Redactor:
- OCR Engine
- Image Processing Engine
- DICOM Handler
- Verification Engine

Structured:
- Analysis Builder
- Data Processors
- Data Reader
- Configuration Manager

##### Integration Points

External integration points:
- Docker containers
- REST APIs
- Python SDK interfaces
- Spark integration

##### Cross-Cutting Concerns

Shared services:
- Configuration Management
- Logging
- Error Handling
- Validation Services

##### Deployment Options

Deployment variants:
- Kubernetes cluster
- Docker containers
- Python packages
- Spark clusters

Use these visual elements:
- Rounded rectangles for subcomponents
- Clear labels for all components and interactions

- Blue: Core Services
- Green: External Integrations
- Yellow: Processing Engines
- Gray: Support Services
- Red: Security Components

Remember to include:
- Version compatibility
- Security boundaries
- Scale-out possibilities
- Configuration points
- Monitoring interfaces

This will provide a clear understanding of how Presidio's components work together to provide PII detection and anonymization capabilities across different data types and formats.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph External["External Layer"]
        Input["External Input"]
        Output["Protected Output"]
    end

    subgraph Core["Core Services"]
        Analyzer["Presidio Analyzer"]:::core
        Anonymizer["Presidio Anonymizer"]:::core
        ImageRedactor["Presidio Image Redactor"]:::core
        Structured["Presidio Structured"]:::core
    end

    subgraph AnalyzerComponents["Analyzer Components"]
        NLP["NLP Engine"]:::engine
        Registry["Recognizer Registry"]:::processor
        Pattern["Pattern Recognizers"]:::processor
        Context["Context Aware Enhancers"]:::processor
    end

    subgraph AnonymizerComponents["Anonymizer Components"]
        OpFactory["Operator Factory"]:::processor
        Encrypt["Encryption Services"]:::security
        TextReplace["Text Replace Builder"]:::processor
        BatchProc["Batch Processing Engine"]:::engine
    end

    subgraph ImageComponents["Image Redactor Components"]
        OCR["OCR Engine"]:::engine
        ImgProc["Image Processing Engine"]:::engine
        DICOM["DICOM Handler"]:::processor
        Verify["Verification Engine"]:::processor
    end

    subgraph StructuredComponents["Structured Components"]
        ABuilder["Analysis Builder"]:::processor
        DProc["Data Processors"]:::processor
        DReader["Data Reader"]:::processor
        Config["Configuration Manager"]:::support
    end

    subgraph Integration["Integration Points"]
        Docker["Docker Containers"]:::integration
        REST["REST APIs"]:::integration
        SDK["Python SDK"]:::integration
        Spark["Spark Integration"]:::integration
    end

    subgraph Shared["Shared Services"]
        ConfigMgmt["Configuration Management"]:::support
        Logging["Logging"]:::support
        ErrorHandle["Error Handling"]:::support
        Validation["Validation Services"]:::support
    end

    %% Main Flow
    Input --> Analyzer
    Analyzer --> Anonymizer
    Anonymizer --> Output
    Analyzer --> ImageRedactor
    Analyzer --> Structured

    %% Component Connections
    Analyzer --- AnalyzerComponents
    Anonymizer --- AnonymizerComponents
    ImageRedactor --- ImageComponents
    Structured --- StructuredComponents

    %% Integration Connections
    Core --- Integration
    Core --- Shared

    %% Click Events
    click Analyzer "https://github.com/microsoft/presidio/tree/main/presidio-analyzer/presidio_analyzer/"
    click NLP "https://github.com/microsoft/presidio/tree/main/presidio-analyzer/presidio_analyzer/nlp_engine/"
    click Registry "https://github.com/microsoft/presidio/tree/main/presidio-analyzer/presidio_analyzer/recognizer_registry/"
    click Pattern "https://github.com/microsoft/presidio/tree/main/presidio-analyzer/presidio_analyzer/predefined_recognizers/"
    click Context "https://github.com/microsoft/presidio/tree/main/presidio-analyzer/presidio_analyzer/context_aware_enhancers/"
    
    click Anonymizer "https://github.com/microsoft/presidio/tree/main/presidio-anonymizer/presidio_anonymizer/"
    click OpFactory "https://github.com/microsoft/presidio/blob/main/presidio-anonymizer/presidio_anonymizer/operators/operators_factory.py"
    click Encrypt "https://github.com/microsoft/presidio/blob/main/presidio-anonymizer/presidio_anonymizer/operators/encrypt.py"
    click TextReplace "https://github.com/microsoft/presidio/blob/main/presidio-anonymizer/presidio_anonymizer/core/text_replace_builder.py"
    click BatchProc "https://github.com/microsoft/presidio/blob/main/presidio-anonymizer/presidio_anonymizer/batch_anonymizer_engine.py"
    
    click ImageRedactor "https://github.com/microsoft/presidio/tree/main/presidio-image-redactor/presidio_image_redactor/"
    click OCR "https://github.com/microsoft/presidio/blob/main/presidio-image-redactor/presidio_image_redactor/tesseract_ocr.py"
    click ImgProc "https://github.com/microsoft/presidio/blob/main/presidio-image-redactor/presidio_image_redactor/image_processing_engine.py"
    click DICOM "https://github.com/microsoft/presidio/blob/main/presidio-image-redactor/presidio_image_redactor/dicom_image_redactor_engine.py"
    click Verify "https://github.com/microsoft/presidio/blob/main/presidio-image-redactor/presidio_image_redactor/image_pii_verify_engine.py"
    
    click Structured "https://github.com/microsoft/presidio/tree/main/presidio-structured/presidio_structured/"
    click ABuilder "https://github.com/microsoft/presidio/blob/main/presidio-structured/presidio_structured/analysis_builder.py"
    click DProc "https://github.com/microsoft/presidio/blob/main/presidio-structured/presidio_structured/data/data_processors.py"
    click DReader "https://github.com/microsoft/presidio/blob/main/presidio-structured/presidio_structured/data/data_reader.py"
    click Config "https://github.com/microsoft/presidio/blob/main/presidio-structured/presidio_structured/config/structured_analysis.py"

    %% Styling
    classDef core fill:#2374ab
    classDef engine fill:#ffd700
    classDef processor fill:#95c623
    classDef security fill:#ff6b6b
    classDef support fill:#808080
    classDef integration fill:#4caf50
```
