# bing-su/adetailer architecture

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

- Interactive diagram: https://gitdiagram.com/bing-su/adetailer
- Repository: https://github.com/bing-su/adetailer

## Overview

##### Main Components

a) Core Components:
- ADetailer Extension Core
- Detection Models Integration
- Inpainting System
- ControlNet Integration
- WebUI Integration Layer

b) External Dependencies:
- Stable Diffusion WebUI
- Ultralytics YOLO
- MediaPipe
- ControlNet (optional)

**┌─ User Interface Layer ─────────────────────┐**
- Stable Diffusion WebUI                     │
- ADetailer Extension UI                 │
- Processing Layer ──────────────────────────┤
- ┌─ ADetailer Core ─────────────────────┐   │
- Detection Pipeline                 │   │
- Mask Processing                    │   │
- Inpainting Pipeline               │   │
- ┘   │
- Model Layer ────────────────────────────────┤
- ┌─ Detection Models ─┐ ┌─ Inpainting ──┐    │
- YOLO Models     │ │ - SD Models    │    │
- MediaPipe       │ │ - ControlNet   │    │
- ┘ └──────────────┘    │
- ┘

##### Key Components to Highlight

a) Core Modules (based on file structure):
- args.py: Configuration handling
- mask.py: Mask generation and processing
- mediapipe.py: MediaPipe integration
- ultralytics.py: YOLO model integration
- controlnet_ext: ControlNet integration

b) Processing Flow:

##### Important Relationships

- Bidirectional communication between WebUI and ADetailer
- Sequential processing flow
- Optional components (ControlNet)
- Model loading paths
- Configuration flow

##### Technical Details

- Supported model formats (.pt files)
- Input/output formats
- Configuration options
- API endpoints (for REST API support)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph UI["User Interface Layer"]
        SDWUI["Stable Diffusion WebUI"]
        ADUI["ADetailer Extension UI"]:::ui
    end

    subgraph PL["Processing Layer"]
        subgraph Core["ADetailer Core"]
            Config["Configuration Handler"]:::core
            Common["Common Utilities"]:::core
            Options["Options Manager"]:::core
            Detection["Detection Pipeline"]
            MaskProc["Mask Processing"]:::mask
            Inpainting["Inpainting Pipeline"]
        end
    end

    subgraph ML["Model Layer"]
        subgraph DM["Detection Models"]
            YOLO["YOLO Integration"]:::detect
            MediaPipe["MediaPipe Integration"]:::detect
        end
        
        subgraph IM["Inpainting Models"]
            SDModels["SD Models"]
            CNModels["ControlNet Models"]:::controlnet
        end
    end

    subgraph Helper["Helper Components"]
        UIComp["UI Components"]:::helper
        CondProc["Conditional Processing"]:::helper
        HelpFunc["Helper Functions"]:::helper
    end

    SDWUI --> ADUI
    ADUI --> Config
    Config --> Detection
    Detection --> |Detect Objects| YOLO
    Detection --> |Detect Face/Body| MediaPipe
    YOLO & MediaPipe --> MaskProc
    MaskProc --> Inpainting
    Inpainting --> SDModels
    Inpainting -.-> |Optional| CNModels
    Common --> Detection
    Options --> Detection
    UIComp --> ADUI
    CondProc --> Inpainting
    HelpFunc --> Core

    %% Click Events
    click Core "https://github.com/Bing-su/adetailer/tree/main/adetailer/"
    click Config "https://github.com/Bing-su/adetailer/blob/main/adetailer/args.py"
    click Common "https://github.com/Bing-su/adetailer/blob/main/adetailer/common.py"
    click Options "https://github.com/Bing-su/adetailer/blob/main/adetailer/opts.py"
    click YOLO "https://github.com/Bing-su/adetailer/blob/main/adetailer/ultralytics.py"
    click MediaPipe "https://github.com/Bing-su/adetailer/blob/main/adetailer/mediapipe.py"
    click MaskProc "https://github.com/Bing-su/adetailer/blob/main/adetailer/mask.py"
    click CNModels "https://github.com/Bing-su/adetailer/blob/main/controlnet_ext/controlnet_ext.py"
    click ADUI "https://github.com/Bing-su/adetailer/blob/main/scripts/!adetailer.py"
    click UIComp "https://github.com/Bing-su/adetailer/blob/main/aaaaaa/ui.py"
    click CondProc "https://github.com/Bing-su/adetailer/blob/main/aaaaaa/conditional.py"
    click HelpFunc "https://github.com/Bing-su/adetailer/blob/main/aaaaaa/helper.py"

    %% Styling
    classDef ui fill:#2374ab
    classDef core fill:#2a9d8f
    classDef detect fill:#e9c46a
    classDef mask fill:#f4a261
    classDef controlnet fill:#e76f51
    classDef helper fill:#8ecae6

    %% Legend
    subgraph Legend
        UI_L["UI Components"]:::ui
        Core_L["Core Components"]:::core
        Detect_L["Detection Components"]:::detect
        Mask_L["Mask Processing"]:::mask
        CN_L["ControlNet"]:::controlnet
        Helper_L["Helper Components"]:::helper
    end
```
