# vladmandic/automatic architecture

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

## Overview

Based on our analysis of the file structure and the README, this project is a highly modular, feature-rich implementation of image diffusion (SD.Next) built on top of a stable diffusion codebase (inspired by AUTOMATIC1111’s WebUI). It supports multiple user interfaces (Standard and Modern), a rich set of diffusion models, various GPU acceleration backends, and a flexible extension/plugin mechanism. The architecture can be broadly divided into several layers/components.

##### Main Components
- User Interface Layer:
– Frontend resources from directories like “html”, “javascript”, and the “webui.py”, “launch.py” scripts. These provide both standard and modern UIs, with support for themes and localization.
- API / Command-Line Layer:
– CLI scripts under the “cli” directory and API endpoint modules under “modules/api”. These serve as the entry points for automating and remotely controlling diffusion tasks.
- Processing / Diffusion Engine:
– The “modules” folder is the heart of the system with submodules for stable diffusion, control operations (e.g., controlnet, image pre/post-processing), model pipelines, and advanced functions (e.g., Lora, hypernetworks, face restoration). This layer handles the core image generation and manipulation workflows.
- Model Management & Configuration:
– “configs” and “models” directories hold YAML/JSON configuration files, model index files, and various Dockerfiles for platform-specific setups. They indicate support for multiple diffusion models and optimized configurations per GPU backends.
- Extensions & Plugins:
– “extensions” and “extensions-builtin” folders house add-on modules (for example, Lora networks and additional UI integrations) and support external repositories (as seen in “repositories” containing projects like Codeformer, BLIP, etc.). This represents an extensible architecture.
- Backend Acceleration / GPU Support:
– Several directories and scripts point to support for different hardware backends (CUDA, ROCm, DirectML, OpenVINO, ONNX, ZLUDA, etc.). Include a dedicated node that represents the GPU processing libraries (wrapped by PyTorch and others) and auto-detection/tuning components during installation.

- API/CLI components with the Diffusion Engine, indicating the flow of commands (e.g., text-to-image, img2img, inpainting) and the management of queues.
- Interaction between the Diffusion Engine and the Model Management layer: the engine loads models and configuration settings at runtime.

##### Architectural Patterns and Design Principles
- Modularity: each ‘module’ handles a specific concern (text prompt parsing, control processing, face restoration, etc.), keeping concerns separated and easily extensible.
- That the design follows a “plugin” pattern for extensions – new functionalities can be added outside the core engine.
- That the system supports both API-driven and CLI-driven workflows, which is reflected by separate but interacting frontends.
- Autodetection mechanism on install, which configures platform-specific optimizations—this can be represented as a “Configuration Manager” interacting with hardware abstraction.

## Diagram (Mermaid)

```mermaid
graph TD
    %% User Interface Layer
    subgraph "User Interface Layer"
        UI1("HTML Resources"):::ui
        UI2("JavaScript Resources"):::ui
        UI3("webui.py"):::ui
        UI4("launch.py"):::ui
    end

    %% API / Command-Line Layer
    subgraph "API/Command-Line Layer"
        API1("CLI Scripts"):::api
        API2("API Endpoints"):::api
    end

    %% Processing / Diffusion Engine
    subgraph "Processing / Diffusion Engine"
        Engine("Diffusion Engine (Modules)"):::engine
    end

    %% Model Management & Configuration
    subgraph "Model Management & Configuration"
        Config("Configurations"):::config
        Models("Models"):::config
    end

    %% Extensions & Plugins
    subgraph "Extensions & Plugins"
        ExtBuiltin("Builtin Extensions"):::ext
        Ext("Extensions"):::ext
        Codeformer("Codeformer"):::ext
        BLIP("BLIP"):::ext
    end

    %% Backend Acceleration / GPU Support
    subgraph "Backend Acceleration / GPU Support"
        GPU("GPU Acceleration"):::gpu
    end

    %% Relationships
    UI3 -->|"triggers"| API1
    UI3 -->|"triggers"| API2

    API1 -->|"commands"| Engine
    API2 -->|"commands"| Engine

    Engine -->|"loads-config"| Config
    Engine -->|"loads-models"| Models
    Engine -->|"offloads"| GPU

    Engine -->|"extends"| ExtBuiltin
    Engine -->|"extends"| Ext

    ExtBuiltin -->|"adds_functionality"| Codeformer
    Ext -->|"adds_functionality"| BLIP

    %% Click Events
    click UI1 "https://github.com/vladmandic/automatic/tree/master/html"
    click UI2 "https://github.com/vladmandic/automatic/tree/master/javascript"
    click UI3 "https://github.com/vladmandic/automatic/blob/master/webui.py"
    click UI4 "https://github.com/vladmandic/automatic/blob/master/launch.py"
    click API1 "https://github.com/vladmandic/automatic/tree/master/cli"
    click API2 "https://github.com/vladmandic/automatic/blob/master/modules/api/api.py"
    click Engine "https://github.com/vladmandic/automatic/tree/master/modules"
    click Config "https://github.com/vladmandic/automatic/tree/master/configs"
    click Models "https://github.com/vladmandic/automatic/tree/master/models"
    click ExtBuiltin "https://github.com/vladmandic/automatic/tree/master/extensions-builtin"
    click Ext "https://github.com/vladmandic/automatic/tree/master/extensions"
    click Codeformer "https://github.com/vladmandic/automatic/tree/master/repositories/codeformer"
    click BLIP "https://github.com/vladmandic/automatic/tree/master/repositories/blip"
    click GPU "https://github.com/vladmandic/automatic/tree/master/modules/intel/ipex"

    %% Styles
    classDef ui fill:#A2D5F2,stroke:#1B4F72,stroke-width:2px,color:black;
    classDef api fill:#FAD7A0,stroke:#D35400,stroke-width:2px,color:black;
    classDef engine fill:#D5F5E3,stroke:#239B56,stroke-width:2px,color:black;
    classDef config fill:#F9E79F,stroke:#B7950B,stroke-width:2px,color:black;
    classDef ext fill:#F5B7B1,stroke:#922B21,stroke-width:2px,color:black;
    classDef gpu fill:#D6EAF8,stroke:#21618C,stroke-width:2px,color:black;

    class UI1,UI2,UI3,UI4 ui;
    class API1,API2 api;
    class Engine engine;
    class Config,Models config;
    class ExtBuiltin,Ext,Codeformer,BLIP ext;
    class GPU gpu;
```
