# bytedance/godlp architecture

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

- Interactive diagram: https://gitdiagram.com/bytedance/godlp
- Repository: https://github.com/bytedance/godlp

## Overview

##### Main Components
- Engine (Core SDK Layer): At the center is the Engine that implements the EngineAPI interface. This is realized through several core files (sdk.go, sdkconfig.go, sdkdeidentify.go, sdkdetect.go, sdkmask.go, and sdkinternal.go) which define and wire up the engine’s functions.
- Configuration Module: Illustrate a configuration component that is responsible for reading and managing the YAML config files (“conf.yml” and the code in the conf directory). This component supplies global settings, sensitive data detection rules, and masking rules.
- Data Structures & API Definitions: Represent a module for “dlpheader” (and possibly “errlist” for error handling) where API data types and constants are defined.
- Logging and Utility Components: Include the “log” module for logging functionality and any other utility components that support the engine (like helper functions or internal libraries).
- External Interfaces: Show the APIs that external callers use (the public functions listed in the README like ApplyConfig, Detect, Deidentify, Mask, etc.). This might also include CLI endpoints (as seen in mainrun/mainrun.go) and unit test / benchmarking tools.

##### Determining Relationships and Data Flows
– For sensitive data detection, it calls the Detector module.
– For de-identification/masking operations, it routes calls to the Mask module.
– It utilizes the Configuration Module to load and apply detection and masking rules.
- Error Handling & Logging: Indicate the role of the Error Handling module (errlist) for reporting issues and reference the Log module for recording processing steps.

##### Architectural Patterns and Design Principles
- Modular Design: Emphasize that each key function is encapsulated in its own module (configuration, detector, mask, etc.). This not only supports clarity in testing (as evident from “sdk_test.go” and “bench_test.go”) but also flexibility for future extension.
- Separation of Concerns: Clearly separate the responsibilities by showing how the Engine (API layer) does not embed detection/masking logic but delegates those concerns to specialized submodules.
- Extensibility: Highlight that the project facilitates custom behavior (for example, custom masking functions via RegisterMasker). This could be visualized as an extension point in the Mask module.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Layer
    subgraph "External Layer"
        EC["External Clients"]:::external
        EI["External Interfaces (CLI/API)"]:::external
    end

    %% Core Engine
    subgraph "Core Engine"
        E["Engine (Core SDK Layer)"]:::engine
    end

    %% Processing Modules
    subgraph "Processing Modules"
        C["Configuration Module (conf.yml & conf/*.go)"]:::module
        D["Detector Module (detector/detector.go)"]:::module
        M["Mask Module (mask/mask.go)"]:::module
    end

    %% Support Modules
    subgraph "Support Modules"
        DS["Data Structures (dlpheader/dlpheader.go)"]:::support
        EH["Error Handling (errlist/errlist.go)"]:::support
        L["Logging (log/log.go)"]:::support
    end

    %% Connections between layers
    EC -->|"uses"| EI
    EI -->|"calls"| E

    %% Engine interacts with Processing Modules
    E -->|"ApplyConfig"| C
    C -->|"provides config"| E

    E -->|"Detect()"| D
    D -->|"returns results"| E

    E -->|"Mask()/Deidentify()"| M
    M -->|"returns results"| E

    %% Engine interacts with Support Modules
    E -->|"formats response with"| DS
    E -->|"reports errors to"| EH
    E -->|"logs actions to"| L

    %% Click Events
    click E "https://github.com/bytedance/godlp/blob/main/sdk.go"
    click C "https://github.com/bytedance/godlp/blob/main/conf.yml"
    click D "https://github.com/bytedance/godlp/blob/main/detector/detector.go"
    click M "https://github.com/bytedance/godlp/blob/main/mask/mask.go"
    click DS "https://github.com/bytedance/godlp/blob/main/dlpheader/dlpheader.go"
    click EH "https://github.com/bytedance/godlp/blob/main/errlist/errlist.go"
    click L "https://github.com/bytedance/godlp/blob/main/log/log.go"
    click EI "https://github.com/bytedance/godlp/blob/main/mainrun/mainrun.go"

    %% Styles
    classDef engine fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef module fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef support fill:#FFFF99,stroke:#000,stroke-width:2px;
    classDef external fill:#F08080,stroke:#000,stroke-width:2px;
```
