# adieyal/dynamicprompts architecture

> Architecture diagram of the GitHub repository adieyal/dynamicprompts, 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/dynamicprompts
- Repository: https://github.com/adieyal/dynamicprompts

## Overview

##### Main Components

a) Core Components:
- Parser System
- Generator System
- Wildcard Management System
- Sampler System
- Command System

b) External Integrations:
- Text-to-Image Systems (Stable Diffusion, MidJourney, Dall-e 2)
- Lexica.art API Integration
- HuggingFace Model Integration

**┌─ External Systems Layer ─────────────────────┐**
- [Text-to-Image Systems] [Lexica.art]        │
- [HuggingFace Models]                        │
- ┬───────────────────────┬─┘

**┌─ Generator Layer ─▼───────────────────────▼─┐**
- ┌─────────────────────┐ ┌────────────────┐  │
- Prompt Generators │ │Magic Generators │  │
- ┘ └────────────────┘  │
- ┬───────────────────────┬─┘

**┌─ Core Layer ──────▼───────────────────────▼─┐**
- ┌─────────┐ ┌──────────┐ ┌──────────────┐  │
- Parser  │ │ Samplers │ │   Commands   │  │
- ┘ └──────────┘ └──────────────┘  │
- ┬──────────────────────┬──┘

**┌─ Data Layer ──────▼──────────────────────▼─┐**
- ┌────────────────┐  ┌───────────────────┐  │
- Wildcard System │  │ Template Storage  │  │
- ┘  └───────────────────┘  │
- ┬──┘

##### Component Details

a) Parser System:
- Flow from raw template to parsed commands
- Config handling and syntax parsing
- To the command system

b) Generator System:
- Generator types (Random, Combinatorial, Magic, etc.)
- Connection to samplers
- Integration points with external services

c) Wildcard System:
- Hierarchy of wildcard collections
- File system integration
- Wildcard manager coordination

d) Command System:
- Different command types
- Command processing flow
- To generator system

##### Data Flow Indicators

- Template input flow
- Command processing direction
- Generator output flow
- External service interactions

##### Integration Points

Clearly mark:
- API endpoints for external services
- Model integration points
- File system access points
- Extension mechanisms

##### Additional Elements

- Version/configuration management
- Test integration points
- Primary API entry points

Remember to include notes about:
- The template processing pipeline
- Wildcard resolution mechanism
- Generator strategy pattern implementation
- External service integration patterns
- Error handling and validation flows

This will provide a complete picture of the system's architecture while maintaining clarity and usefulness for implementation and maintenance purposes.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef external fill:#90EE90,stroke:#333,stroke-width:2px
    classDef generator fill:#FFA500,stroke:#333,stroke-width:2px
    classDef core fill:#87CEEB,stroke:#333,stroke-width:2px
    classDef data fill:#FFD700,stroke:#333,stroke-width:2px

    %% External Systems Layer
    subgraph ExternalLayer["External Systems Layer"]
        T2I["Text-to-Image Systems"]:::external
        LEX["Lexica.art API"]:::external
        HF["HuggingFace Models"]:::external
    end

    %% Generator Layer
    subgraph GeneratorLayer["Generator Layer"]
        direction TB
        BasicGen["Basic Generators"]:::generator
        MagicGen["Magic Generators"]:::generator
        JinjaGen["Jinja Generator"]:::generator
        AttentionGen["Attention Generator"]:::generator
        FeelingLuckyGen["Feeling Lucky Generator"]:::generator
    end

    %% Core Layer
    subgraph CoreLayer["Core Layer"]
        direction TB
        Parser["Parser System"]:::core
        Sampler["Sampler System"]:::core
        Commands["Command System"]:::core
    end

    %% Data Layer
    subgraph DataLayer["Data Layer"]
        direction TB
        WildcardSys["Wildcard System"]:::data
        TemplateStore["Template Storage"]:::data
        CoreTypes["Core Types & Utils"]:::data
    end

    %% Relationships
    ExternalLayer --> GeneratorLayer
    GeneratorLayer --> CoreLayer
    CoreLayer --> DataLayer

    %% Click Events
    click Parser "https://github.com/adieyal/dynamicprompts/tree/main/src/dynamicprompts/parser/"
    click Commands "https://github.com/adieyal/dynamicprompts/tree/main/src/dynamicprompts/commands/"
    click BasicGen "https://github.com/adieyal/dynamicprompts/blob/main/src/dynamicprompts/generators/randomprompt.py"
    click MagicGen "https://github.com/adieyal/dynamicprompts/blob/main/src/dynamicprompts/generators/magicprompt.py"
    click JinjaGen "https://github.com/adieyal/dynamicprompts/blob/main/src/dynamicprompts/generators/jinjagenerator.py"
    click AttentionGen "https://github.com/adieyal/dynamicprompts/blob/main/src/dynamicprompts/generators/attentiongenerator.py"
    click FeelingLuckyGen "https://github.com/adieyal/dynamicprompts/blob/main/src/dynamicprompts/generators/feelinglucky.py"
    click Sampler "https://github.com/adieyal/dynamicprompts/tree/main/src/dynamicprompts/samplers/"
    click WildcardSys "https://github.com/adieyal/dynamicprompts/tree/main/src/dynamicprompts/wildcards/"
    click CoreTypes "https://github.com/adieyal/dynamicprompts/blob/main/src/dynamicprompts/types.py"

    %% Legend
    subgraph Legend
        direction TB
        E[External Systems]:::external
        G[Generators]:::generator
        C[Core Components]:::core
        D[Data Components]:::data
    end
```
