# ahmad1993aj/img-generation-flux architecture

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

- Interactive diagram: https://gitdiagram.com/ahmad1993aj/img-generation-flux
- Repository: https://github.com/ahmad1993aj/img-generation-flux

## Overview

##### Project Type & Purpose
- Type: Full-stack single-page web app (Streamlit)
- Purpose: Let users enter image prompts and settings, call the Replicate API to generate images, and display/download results.

##### Main Components
a. Client Browser (UI)
b. Streamlit App Server (Python script: main.py)
c. Configuration Store (.env for REPLICATE_API_TOKEN)
d. External AI Service (Replicate API)
e. Local File System (optional temp cache or direct download)

##### Relationships & Data Flows
1. User opens the Streamlit app in their browser.
2. Browser ↔ Streamlit App:
- GET static assets & rendered UI
- POST user inputs (prompt, quality, seed)
3. Streamlit App reads API token from .env via python-dotenv.
4. Streamlit App → Replicate API (HTTPS request) with payload: prompt, settings, token.
5. Replicate API processes request, returns generated image data (URL or bytes).
6. Streamlit App receives image, optionally caches to local FS or memory.
7. Streamlit App sends image back to Browser for preview and download.

##### Architectural Patterns & Design Principles
- Single-process “backend” embedded in the Streamlit server.
- Clear separation of concerns:
- UI rendering & user event handling (Streamlit)
- Business logic & external API orchestration (Python code in main.py)
- Configuration management (dotenv)
- External dependency is abstracted behind a simple client call (requests or Replicate SDK).

##### Relevant Technologies & Libraries
- Streamlit: UI framework, auto-reload, session management
- python-dotenv: loading .env secrets
- Replicate SDK or requests: interacting with the external AI service
- PIL or built-in Streamlit image methods for preview/download

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Layer
    subgraph "User Layer"
        Browser["Client Browser (UI)"]:::browser
    end

    %% Application Layer
    subgraph "Streamlit App Server"
        App["Streamlit App Server"]:::app
        Config["Configuration Store (.env)"]:::config
        FileSystem["Local File System (cache)"]:::fs
    end

    %% External Service
    Replicate["External AI Service (Replicate API)"]:::external

    %% Documentation
    Documentation["Project Documentation & Instructions"]:::doc

    %% Data Flows
    Browser -->|"GET UI (HTTP)"| App
    Browser -->|"POST prompt (HTTP)"| App
    App -->|"reads token"| Config
    App -->|"POST prompt & settings (HTTPS)"| Replicate
    Replicate -->|"returns image URL/bytes"| App
    App -->|"sends image (HTTP)"| Browser
    App -->|"cache image"| FileSystem

    %% Click Events
    click Browser "https://github.com/ahmad1993aj/img-generation-flux/blob/main/main.py"
    click App "https://github.com/ahmad1993aj/img-generation-flux/blob/main/main.py"
    click Config "https://github.com/ahmad1993aj/img-generation-flux/blob/main/.env"
    click Replicate "https://github.com/ahmad1993aj/img-generation-flux/blob/main/requirements.txt"
    click Documentation "https://github.com/ahmad1993aj/img-generation-flux/blob/main/README.md"

    %% Styles
    classDef browser fill:#add8e6,stroke:#000,stroke-width:1px
    classDef app fill:#90ee90,stroke:#000,stroke-width:1px
    classDef config fill:#d3d3d3,stroke:#000,stroke-width:1px
    classDef external fill:#ffa500,stroke:#000,stroke-width:1px
    classDef fs fill:#ffffe0,stroke:#000,stroke-width:1px
    classDef doc fill:#f0f0f0,stroke:#000,stroke-width:1px
```
