# serilog-contrib/serilog.enrichers.sensitive architecture

> Architecture diagram of the GitHub repository serilog-contrib/serilog.enrichers.sensitive, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/serilog-contrib/serilog.enrichers.sensitive
- Repository: https://github.com/serilog-contrib/serilog.enrichers.sensitive

## Overview

Based on our analysis, this project is a .NET library that acts as a Serilog enricher to mask sensitive data (such as email addresses, IBANs, and credit card numbers) in log events. It provides both a “always mask” mode and a “mask in sensitive areas only” mode. There is also support for custom masking operators and JSON configuration.

##### Main Components Identification
- Library Core: Represent the heart of the project in the src/Serilog.Enrichers.Sensitive folder. This is where all core classes exist (such as SensitiveDataEnricher, MaskOptions, Masking operators like EmailAddressMaskingOperator, IbanMaskingOperator, CreditCardMaskingOperator, and the base RegexMaskingOperator).
- Demo Application: The sample app (in src/Serilog.Enrichers.Sensitive.Demo) demonstrates how to integrate the enricher into a logging setup.
- Testing Suite: Separate sections under the test directory include unit tests and benchmarks. This should be depicted as components that test the functionality and performance of the masking library.
- Configuration & Build Infrastructure: The .github directory (with workflows for build, test, pre-release, and release) and configuration files (like Directory.Build.props, get-changelog.ps1) indicate continuous integration and deployment practices.
- Documentation: The README and accompanying markdown files (Changelog.md, LICENSE) give usage examples and detail masking options and configuration.

##### Relationships and Interactions Between Components
- The CI/CD pipelines (containerized in the GitHub workflows) automatically build and test the library, showing integration with source control and continuous integration tools.

##### Important Architectural Patterns & Design Principles
- Modularity & Extensibility: The use of masking operators (each implemented as a specific operator class) illustrates the strategy pattern whereby each operator can be substituted or extended.
- Separation of Concerns: The separation between the core library, demo application, and test layers.
- Configuration-Driven Behavior: Flexible configuration options including JSON-based configuration show that the system is designed for adaptability.
- External Integration: The enricher integrates into the application’s logging workflow, demonstrating loose coupling by allowing configuration to drive whether data gets masked before logging.

##### Relevant Technologies, Frameworks, or Libraries
- .NET (C#) for development
- Serilog for logging
- GitHub Actions for CI/CD
- NuGet for package distribution
- Benchmarking libraries and xUnit (or similar) frameworks for testing

1. Out the high-level nodes (Core Library, Demo, Tests, CI/CD).
2. Within the Core Library, nest sub-components that represent each masking operator and shared functionality.
4. Side nodes for CI/CD workflows and configuration files to denote auxiliary processes (automatic build/test, package distribution).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CI/CD Pipeline
    CI_CD["CI/CD Pipeline"]:::cicd
    click CI_CD "https://github.com/serilog-contrib/serilog.enrichers.sensitive/tree/master/.github/workflows"
    
    %% Documentation & Configuration
    DOC["Documentation & Configuration"]:::doc
    click DOC "https://github.com/serilog-contrib/serilog.enrichers.sensitive/blob/master/README.md"
    
    %% Demo Application
    DEMO["Demo Application"]:::demo
    click DEMO "https://github.com/serilog-contrib/serilog.enrichers.sensitive/blob/master/src/Serilog.Enrichers.Sensitive.Demo"
    
    %% Test Suites
    UNIT["Unit Tests"]:::test
    click UNIT "https://github.com/serilog-contrib/serilog.enrichers.sensitive/blob/master/test/Serilog.Enrichers.Sensitive.Tests.Unit"
    
    BM["Benchmark Tests"]:::test
    click BM "https://github.com/serilog-contrib/serilog.enrichers.sensitive/blob/master/test/Serilog.Enrichers.Sensitive.Tests.Benchmark"

    %% Core Library Subgraph
    subgraph "Core Library (src/Serilog.Enrichers.Sensitive)"
        CORE["Core Library"]:::core
        click CORE "https://github.com/serilog-contrib/serilog.enrichers.sensitive/blob/master/src/Serilog.Enrichers.Sensitive"
        
        SDE["SensitiveDataEnricher"]:::core
        MASKOPTS["MaskOptions"]:::core
        MASKCOL["MaskPropertyCollection"]:::core
        SDEOPTS["SensitiveDataEnricherOptions"]:::core
        
        subgraph "Masking Operators"
            EMAIL["EmailAddressMaskingOperator"]:::core
            click EMAIL "https://github.com/serilog-contrib/serilog.enrichers.sensitive/blob/master/src/Serilog.Enrichers.Sensitive/EmailAddressMaskingOperator.cs"
            
            IBAN["IbanMaskingOperator"]:::core
            click IBAN "https://github.com/serilog-contrib/serilog.enrichers.sensitive/blob/master/src/Serilog.Enrichers.Sensitive/IbanMaskingOperator.cs"
            
            CREDIT["CreditCardMaskingOperator"]:::core
            click CREDIT "https://github.com/serilog-contrib/serilog.enrichers.sensitive/blob/master/src/Serilog.Enrichers.Sensitive/CreditCardMaskingOperator.cs"
            
            REGEX["RegexMaskingOperator"]:::core
            click REGEX "https://github.com/serilog-contrib/serilog.enrichers.sensitive/blob/master/src/Serilog.Enrichers.Sensitive/RegexMaskingOperator.cs"
            
            INTERFACE["IMaskingOperator"]:::core
            click INTERFACE "https://github.com/serilog-contrib/serilog.enrichers.sensitive/blob/master/src/Serilog.Enrichers.Sensitive/IMaskingOperator.cs"
        end
    end

    %% Relationships between components
    DEMO -->|"uses"| CORE
    UNIT -->|"tests"| CORE
    BM -->|"benchmarks"| CORE

    CI_CD -->|"builds"| CORE
    CI_CD -->|"builds"| DEMO
    CI_CD -->|"runs"| UNIT
    CI_CD -->|"runs"| BM
    CI_CD -->|"deploys"| DOC

    %% Internal relationships within Core Library
    CORE --> SDE
    SDE -->|"invokes"| EMAIL
    SDE -->|"invokes"| IBAN
    SDE -->|"invokes"| CREDIT
    SDE -->|"invokes"| REGEX
    SDE -->|"uses"| INTERFACE
    SDE -->|"configures"| MASKOPTS
    SDE -->|"configures"| MASKCOL
    SDE -->|"configures"| SDEOPTS

    %% Styling Classes
    classDef core fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef demo fill:#AED6F1,stroke:#5DADE2,stroke-width:2px;
    classDef test fill:#A9DFBF,stroke:#27AE60,stroke-width:2px;
    classDef cicd fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
    classDef doc fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px;
```
