# enesdertli/pictograph-sd architecture

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

- Interactive diagram: https://gitdiagram.com/enesdertli/pictograph-sd
- Repository: https://github.com/enesdertli/pictograph-sd

## Overview

##### Client Layer
- Discord Client/Server
- Users interacting with the bot through Discord

##### Bot Layer
- Discord Bot (implemented in main.py)
- Discord API Integration (using discord-py-interactions library)

##### Service Layer
- Stable Diffusion Web UI
- Stable Diffusion Web UI API (running on http://127.0.0.1:7860)

##### Flow and Connections
a. User → Discord Client (Input: commands and prompts)
b. Discord Client → Discord Bot (via Discord API)
c. Discord Bot → Stable Diffusion Web UI API
d. Stable Diffusion Web UI → Discord Bot (Image response)
e. Discord Bot → Discord Client (Final image output)

##### Important Details
- API endpoints (/docs, /text2img)
- Key parameters used (prompt, style, negative_prompt, steps, width, height)
- Port number (7860) for the Stable Diffusion Web UI
- Environment variables (TOKEN)

##### Additional Elements
- Notes about required configurations
- Authentication flow (Discord Token)

Specific Considerations:
- Keep the focus on the integration aspects rather than internal Stable Diffusion workings
- Asynchronous nature of image generation requests
- Error handling paths
- Configuration requirements (COMMANDLINE_ARGS=--api)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        User(("👤 User"))
        DC["Discord Client"]
    end

    subgraph BotLayer["Bot Layer"]
        Bot["Discord Bot"]:::bot
        Token[("Discord Token")]
    end

    subgraph ServiceLayer["Service Layer"]
        SDUI["Stable Diffusion Web UI"]
        SDAPI["SD Web UI API<br/>(Port: 7860)"]:::api
    end

    %% Main Flow
    User --> |"Commands & Prompts"| DC
    DC --> |"Discord API"| Bot
    Bot --> |"API Requests"| SDAPI
    SDAPI --> |"Image Generation"| SDUI
    SDUI --> |"Generated Image"| SDAPI
    SDAPI --> |"Image Response"| Bot
    Bot --> |"Final Output"| DC
    DC --> |"Display Image"| User

    %% Authentication
    Token -.- |"Authentication"| Bot

    %% API Parameters
    Parameters["Key Parameters:<br/>- prompt<br/>- style<br/>- negative_prompt<br/>- steps<br/>- width<br/>- height"]:::note
    Parameters -.- SDAPI

    %% Configuration
    Config["Required Config:<br/>COMMANDLINE_ARGS=--api"]:::note
    Config -.- SDUI

    %% Click Events
    click Bot "https://github.com/enesdertli/Pictograph-SD/blob/main/main.py"
    click Parameters "https://github.com/enesdertli/Pictograph-SD/tree/main/assets/"
    click Config "https://github.com/enesdertli/Pictograph-SD/blob/main/README.md"

    %% Styling
    classDef default fill:#f9f9f9,stroke:#333,stroke-width:2px
    classDef bot fill:#90EE90,stroke:#333
    classDef api fill:#FFE5CC,stroke:#333
    classDef note fill:#FFE5CC,stroke:#333,stroke-dasharray: 5 5

    %% Legend
    subgraph Legend
        L1[User/Client]:::default
        L2[Bot Component]:::bot
        L3[API/Service]:::api
        L4[Notes]:::note
    end
```
