# kirivoll/ai-picture-generator architecture

> Architecture diagram of the GitHub repository kirivoll/ai-picture-generator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kirivoll/ai-picture-generator
- Repository: https://github.com/kirivoll/ai-picture-generator

## Overview

1. **Repository shape**
   - This is a very small, single-script project: `AIpictureGenerator.py` is the whole application.
   - There are no packages, services, databases, build steps, or internal modules. The architecture is a single-process console utility.

2. **Primary purpose**
   - The tool takes a text prompt from the terminal and asks an image-generation provider to create an image.
   - The output of each successful request is an image URL, not an embedded image file.

3. **User interaction layer**
   - The only UI is the command line.
   - The script runs an input loop where the user enters prompts or special commands.
   - Supported commands include exit variants (`exit`, `quit`, `выход`) and `/model` for switching the active generation model without restarting.

4. **Model selection subsystem**
   - The app maintains a current model choice in memory.
   - At startup, the user selects one of several supported providers/models: Bing, DeepAI, Flux, or Pollinations.
   - This selection is then passed into the generation call, so model choice directly affects the external service used.

5. **Generation subsystem**
   - The core operation is a call through the `g4f` library, using its image generation API.
   - The request flow is prompt → `g4f` client → remote image service → response containing a URL.
   - The architecture assumes `g4f` as the abstraction boundary over the underlying providers.

6. **Output handling**
   - On success, the script extracts the first returned image URL from the response.
   - That URL is both shown to the user and copied to the clipboard.
   - The tool is therefore optimized for quick reuse of the generated image link rather than local file management.

7. **Clipboard and notification side effects**
   - `pyperclip` is used as a convenience layer for copying the resulting URL to the system clipboard.
   - `winsound.MessageBeep` provides a short audible confirmation after successful generation.
   - These are peripheral but important parts of the user experience; they are OS/library side effects, not core business logic.

8. **Error boundary**
   - API and generation failures are caught and reported as readable console messages.
   - The readme indicates the tool is designed to continue running after a failed request, so each prompt is isolated from the next by exception handling.
   - There is no evidence of retry logic, fallback providers, or persisted failure state.

9. **Runtime and platform assumptions**
   - The tool targets Python 3.7+.
   - It is explicitly Windows-oriented because of the `winsound` dependency.
   - Aside from `g4f` and `pyperclip`, there is no infrastructure dependence.

10. **Data flow for an architecture diagram**
   - Terminal input enters the script.
   - The script interprets either a command or a prompt.
   - For prompts, it sends the prompt plus selected model into `g4f`.
   - The returned image URL comes back to the script.
   - The URL is copied to clipboard, optionally announced with a beep, and printed to the console.

11. **Important boundaries**
   - The main boundary is between local CLI logic and the external image-generation provider accessed through `g4f`.
   - A second boundary is between Python logic and OS-specific functionality: clipboard access and sound notification.
   - There are no internal service boundaries because everything runs in one process.

12. **Architectural summary**
   - Conceptually, this is a thin command-line orchestration layer around third-party image generation.
   - Its responsibilities are input handling, model selection, request dispatch, URL post-processing, and user feedback.
   - Everything else is delegated to external libraries and remote providers.

Main entry points: [`AIpictureGenerator.py`](https://github.com/kirivoll/ai-picture-generator/blob/main/AIpictureGenerator.py) (Prompt dispatch)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_local["Local script"]
  node_cli["CLI loop<br/>command-line UI"]
  node_commands["Command parser<br/>input control"]
  node_model(("Model state<br/>runtime selection"))
  node_prompt["Prompt dispatch<br/>request orchestration"]
  node_result["URL output<br/>post-processing"]
  node_errors{{"Error handling<br/>exception boundary"}}
end

subgraph group_external["External services"]
  node_g4f["g4f client<br/>image API adapter"]
  node_provider[("Image provider<br/>remote service")]
  node_clipboard["Clipboard<br/>OS side effect"]
  node_beep(("Beep sound<br/>OS feedback"))
end

node_cli -->|"reads"| node_commands
node_commands -->|"updates"| node_model
node_commands -->|"routes prompt"| node_prompt
node_model -->|"supplies model"| node_prompt
node_prompt -->|"calls"| node_g4f
node_g4f -->|"requests image"| node_provider
node_provider -->|"returns URL"| node_result
node_result -->|"copies"| node_clipboard
node_result -->|"signals success"| node_beep
node_prompt -->|"on failure"| node_errors
node_cli -->|"reports"| node_errors

click node_cli "https://github.com/kirivoll/ai-picture-generator/blob/main/AIpictureGenerator.py"
click node_commands "https://github.com/kirivoll/ai-picture-generator/blob/main/AIpictureGenerator.py"
click node_model "https://github.com/kirivoll/ai-picture-generator/blob/main/AIpictureGenerator.py"
click node_prompt "https://github.com/kirivoll/ai-picture-generator/blob/main/AIpictureGenerator.py"
click node_result "https://github.com/kirivoll/ai-picture-generator/blob/main/AIpictureGenerator.py"
click node_errors "https://github.com/kirivoll/ai-picture-generator/blob/main/AIpictureGenerator.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_commands,node_model,node_prompt,node_result,node_errors toneBlue
class node_g4f,node_provider,node_clipboard,node_beep toneAmber
```

## Components

### Local script

Single-process CLI orchestration in AIpictureGenerator.py

- [CLI loop](https://github.com/kirivoll/ai-picture-generator/blob/main/AIpictureGenerator.py): command-line UI · Reads prompts and commands from the terminal · `AIpictureGenerator.py`
- [Command parser](https://github.com/kirivoll/ai-picture-generator/blob/main/AIpictureGenerator.py): input control · Handles exit variants and /model switching · `AIpictureGenerator.py`
- [Model state](https://github.com/kirivoll/ai-picture-generator/blob/main/AIpictureGenerator.py): runtime selection · Keeps the current provider/model choice in memory · `AIpictureGenerator.py`
- [Prompt dispatch](https://github.com/kirivoll/ai-picture-generator/blob/main/AIpictureGenerator.py): request orchestration · Sends the user prompt and selected model into generation · `AIpictureGenerator.py`
- [URL output](https://github.com/kirivoll/ai-picture-generator/blob/main/AIpictureGenerator.py): post-processing · Extracts the first image URL, prints it, and copies it to the clipboard · `AIpictureGenerator.py`
- [Error handling](https://github.com/kirivoll/ai-picture-generator/blob/main/AIpictureGenerator.py): exception boundary · Catches generation failures and keeps the loop running · `AIpictureGenerator.py`

### External services

Third-party libraries and remote image generation providers

- **g4f client**: image API adapter · Abstraction layer used to call remote image generation
- **Image provider**: remote service · Bing, DeepAI, Flux, or Pollinations depending on the selected model
- **Clipboard**: OS side effect · Copies the generated URL for reuse
- **Beep sound**: OS feedback · Plays a confirmation tone after success

## Connections

- CLI loop → Command parser: reads · Terminal input is interpreted as commands or prompts
- Command parser → Model state: updates · The /model command changes the active provider/model
- Command parser → Prompt dispatch: routes prompt · Non-command input is treated as an image request
- Model state → Prompt dispatch: supplies model · Current model selection is passed into generation
- Prompt dispatch → g4f client: calls · Dispatches the prompt through the g4f image generation API
- g4f client → Image provider: requests image · The library forwards the request to the chosen remote provider
- Image provider → URL output: returns URL · Successful generation returns an image URL
- URL output → Clipboard: copies · The first returned URL is copied to the system clipboard
- URL output → Beep sound: signals success · A short sound confirms generation completion
- Prompt dispatch → Error handling: on failure · Exceptions are caught so the loop can continue
- CLI loop → Error handling: reports · Readable console messages are shown for failures
