# adieyal/sd-dynamic-prompts architecture

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

- Interactive diagram: https://gitdiagram.com/adieyal/sd-dynamic-prompts
- Repository: https://github.com/adieyal/sd-dynamic-prompts

## Overview

##### Main Components Architecture

a) Core Components:
- Prompt Generator System
- Wildcard Management System
- Template Processing Engine
- Integration Layer with SD Web UI
- Collections Manager
- Configuration Manager

b) External Integrations:
- Magic Prompt Models
- Lexica.art API
- File System (for wildcards)
- Stable Diffusion WebUI

##### Key Architectural Elements

a) Prompt Generation Pipeline:
**Template Input -> Parser -> Wildcard Resolution -> Prompt Generation -> Output Handler**

b) Data Flow Systems:
- Wildcard File System
- Configuration System
- Template Processing System
- Model Integration System

##### Input Layer
- Template Input Interface
- Configuration Interface
- Wildcard Manager Interface

##### Processing Layer
- Template Parser
- Wildcard Resolver
- Combinatorial Generator
- Magic Prompt Processor
- Attention Grabber
- Jinja2 Template Engine

##### Integration Layer
- SD WebUI Bridge
- Model Manager
- File System Manager
- API Integration Handler

##### Output Layer
- Prompt Writer
- PNG Info Saver
- Results Display

##### Key Relationships to Highlight

- Template processing flow
- Wildcard resolution system
- Integration with SD WebUI
- Model loading and management
- Configuration management
- File system interactions

##### Technical Details

- Python-based implementation
- Jinja2 template support
- Regular expression processing
- File system operations
- API integrations
- Model management

##### Implementation Notes

- Modular architecture
- Clear separation of concerns
- Extensible design
- Error handling paths
- Configuration flexibility
- Integration points

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Legend
        L1[Core Components]:::core
        L2[(Data Store)]:::store
        L3{{External System}}:::external
        L4[/Interface/]:::interface
    end

    subgraph "Input Layer"
        TI[/Template Input Interface/]:::interface
        CI[/Configuration Interface/]:::interface
        WI[/Wildcard Manager Interface/]:::interface
    end

    subgraph "Processing Layer"
        TP["Template Parser"]:::core
        click TP "https://github.com/adieyal/sd-dynamic-prompts/blob/main/sd_dynamic_prompts/special_syntax.py"
        
        WR["Wildcard Resolver"]:::core
        click WR "https://github.com/adieyal/sd-dynamic-prompts/blob/main/sd_dynamic_prompts/wildcards_tab.py"
        
        CG["Combinatorial Generator"]:::core
        click CG "https://github.com/adieyal/sd-dynamic-prompts/blob/main/sd_dynamic_prompts/generator_builder.py"
        
        MP["Magic Prompt Processor"]:::core
        click MP "https://github.com/adieyal/sd-dynamic-prompts/blob/main/sd_dynamic_prompts/magic_prompt.py"
        
        AG["Attention Grabber"]:::core
        click AG "https://github.com/adieyal/sd-dynamic-prompts/blob/main/sd_dynamic_prompts/attention_generator.py"
        
        JTE["Jinja2 Template Engine"]:::core
    end

    subgraph "Integration Layer"
        SDB["SD WebUI Bridge"]:::core
        click SDB "https://github.com/adieyal/sd-dynamic-prompts/blob/main/scripts/dynamic_prompting.py"
        
        MM["Model Manager"]:::core
        FSM["File System Manager"]:::core
        click FSM "https://github.com/adieyal/sd-dynamic-prompts/blob/main/sd_dynamic_prompts/paths.py"
        
        AIH["API Integration Handler"]:::core
    end

    subgraph "Output Layer"
        PW["Prompt Writer"]:::core
        click PW "https://github.com/adieyal/sd-dynamic-prompts/blob/main/sd_dynamic_prompts/prompt_writer.py"
        
        PIS["PNG Info Saver"]:::core
        click PIS "https://github.com/adieyal/sd-dynamic-prompts/blob/main/sd_dynamic_prompts/pnginfo_saver.py"
        
        RD["Results Display"]:::core
    end

    subgraph "Data Stores"
        WFS[(Wildcard Files)]:::store
        click WFS "https://github.com/adieyal/sd-dynamic-prompts/tree/main/collections"
        
        CFG[(Configuration)]:::store
        click CFG "https://github.com/adieyal/sd-dynamic-prompts/blob/main/sd_dynamic_prompts/settings.py"
        
        MPM[(Magic Prompt Models)]:::store
        click MPM "https://github.com/adieyal/sd-dynamic-prompts/blob/main/config/magicprompt_models.txt"
    end

    subgraph "External Systems"
        SDUI{{SD WebUI}}:::external
        LA{{Lexica.art API}}:::external
        MPS{{Magic Prompt Service}}:::external
    end

    %% Connections
    TI --> TP
    CI --> CFG
    WI --> WR
    
    TP --> WR
    WR --> CG
    CG --> MP
    MP --> AG
    AG --> JTE
    
    WR --> WFS
    MP --> MPM
    MP --> MPS
    AIH --> LA
    
    JTE --> PW
    PW --> PIS
    PIS --> RD
    
    SDB --> SDUI
    
    %% Styles
    classDef core fill:#a8d1ff,stroke:#333,stroke-width:1px
    classDef store fill:#90EE90,stroke:#333,stroke-width:1px
    classDef external fill:#FFB366,stroke:#333,stroke-width:1px
    classDef interface fill:#E0E0E0,stroke:#333,stroke-width:1px
```
