# thunderhead-exe/advanced-prompt-generator architecture

> Architecture diagram of the GitHub repository thunderhead-exe/advanced-prompt-generator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/thunderhead-exe/advanced-prompt-generator
- Repository: https://github.com/thunderhead-exe/advanced-prompt-generator

## Overview

##### Project Type and Purpose
- This is an **LLM-based Advanced Prompt Generator** tool that offers:
- A **core pipeline** (prompt enhancement logic)
- A **FastAPI microservice** for scalable backend deployment (Docker-packaged).
- A **Gradio UI** for quick demos (Hugging Face Spaces).
- A **local CLI/test script** for development.
- Purpose: take a user’s input prompt, apply AI-agent-based prompt engineering via OpenAI APIs (gpt-4o/gpt-4o-mini), and return an enhanced prompt.

##### File Structure
- Root:
- Advancd_Prompt_Generator.py → local entrypoint calling pipeline.py
- pipeline.py → core logic (shared by all interfaces)
- requirements.txt → all dependencies
- Docker-FastAPI-app:
- Dockerfile → container build instructions
- requirements.txt → backend dependencies
- app/main.py → FastAPI server endpoints
- app/pipeline.py → imports/adapts core logic
- Gradio-app:
- app.py → Gradio UI endpoints
- pipeline.py → imports/adapts core logic
- requirements.txt

##### README for Insights
- Lists features: automated prompt engineering, OpenAI API usage, FastAPI + Docker, Gradio interface, Hugging Face deployment
- No database—external dependency is the OpenAI API

a. Main Components
- **User Interfaces**:
◦ CLI/Test Script (Advancd_Prompt_Generator.py)
◦ Gradio Frontend (Gradio-app/app.py)
- **Backend Service**:
◦ FastAPI API (Docker-FastAPI-app/app/main.py)
- **Core Pipeline Module**:
◦ pipeline.py (root, reused by both interfaces)
- **External Services**:
◦ OpenAI API (gpt-4o / gpt-4o-mini)
◦ Hugging Face Spaces hosting
- **Infrastructure**:
◦ Docker container for FastAPI
◦ Python runtime environments

b. Relationships and Data Flow
1. **User** → (CLI or Gradio UI) → **Core Pipeline** → **OpenAI API** → **Core Pipeline** → (CLI or FastAPI or Gradio) → **User**
2. For FastAPI: **User** → HTTP Request → **FastAPI Endpoint** → **Core Pipeline** → **OpenAI** → response → **FastAPI** → HTTP Response → **User**
3. For Gradio: **User** → Gradio Web UI → **Core Pipeline** → **OpenAI** → displayed result

c. Architectural Patterns & Principles
- **Separation of Concerns**: UI layers (CLI, Gradio, FastAPI) are thin wrappers around a shared core pipeline module.
- **Modularity**: Single pipeline.py holds logic; interfaces import/adapt it.
- **Containerization**: FastAPI service is isolated in a Docker container for consistency and scalability.
- **Stateless Backend**: No persistent storage; each request is independent, relying only on real-time OpenAI calls.

d. Key Technologies & Frameworks
- Python 3.x
- FastAPI (backend microservice)
- Docker (containerization)
- Gradio (demo UI)
- OpenAI Python SDK (LLM integration)
- Hugging Face Spaces (Gradio hosting)

## Diagram (Mermaid)

```mermaid
flowchart TD
    User["User"]:::interface

    subgraph "Local CLI Interface"
        CLI["Advancd_Prompt_Generator.py"]:::interface
        click CLI "https://github.com/thunderhead-exe/advanced-prompt-generator/blob/main/Advancd_Prompt_Generator.py"
    end

    subgraph "Gradio UI"
        GR_APP["app.py"]:::interface
        click GR_APP "https://github.com/thunderhead-exe/advanced-prompt-generator/blob/main/Gradio-app/app.py"
        GR_PIPE["pipeline.py"]:::core
        click GR_PIPE "https://github.com/thunderhead-exe/advanced-prompt-generator/blob/main/Gradio-app/pipeline.py"
        GR_REQ["requirements.txt"]:::infra
        click GR_REQ "https://github.com/thunderhead-exe/advanced-prompt-generator/blob/main/Gradio-app/requirements.txt"
    end

    subgraph "FastAPI Service"
        subgraph "Docker Container" 
            FA_MAIN["main.py"]:::interface
            click FA_MAIN "https://github.com/thunderhead-exe/advanced-prompt-generator/blob/main/Docker-FastAPI-app/app/main.py"
            FA_PIPE["pipeline.py"]:::core
            click FA_PIPE "https://github.com/thunderhead-exe/advanced-prompt-generator/blob/main/Docker-FastAPI-app/app/pipeline.py"
            DF["Dockerfile"]:::infra
            click DF "https://github.com/thunderhead-exe/advanced-prompt-generator/tree/main/Docker-FastAPI-app/Dockerfile"
            FAR["requirements.txt"]:::infra
            click FAR "https://github.com/thunderhead-exe/advanced-prompt-generator/blob/main/Docker-FastAPI-app/requirements.txt"
        end
    end

    PIPE["pipeline.py (Core Pipeline Module)"]:::core
    click PIPE "https://github.com/thunderhead-exe/advanced-prompt-generator/blob/main/pipeline.py"

    OPENAI["OpenAI API<br/>(gpt-4o/gpt-4o-mini)"]:::external
    HUGGING["Hugging Face Spaces"]:::external

    ROOT_REQ["requirements.txt"]:::infra
    click ROOT_REQ "https://github.com/thunderhead-exe/advanced-prompt-generator/blob/main/requirements.txt"
    MEDIA["media/"]:::infra
    click MEDIA "https://github.com/thunderhead-exe/advanced-prompt-generator/tree/main/media/"
    README["README.md"]:::infra
    click README "https://github.com/thunderhead-exe/advanced-prompt-generator/blob/main/README.md"

    %% User Flows
    User -->|CLI Input| CLI
    CLI -->|calls| PIPE
    PIPE -->|API Key, gpt-4o/gpt-4o-mini| OPENAI
    OPENAI -->|response| PIPE
    PIPE -->|enhanced prompt| CLI
    CLI -->|output| User

    User -->|Web UI| GR_APP
    GR_APP -->|invokes| GR_PIPE
    GR_PIPE -->|calls| PIPE
    PIPE -->|API Key, gpt-4o/gpt-4o-mini| OPENAI
    OPENAI -->|response| PIPE
    PIPE -->|result| GR_PIPE
    GR_PIPE -->|display| GR_APP
    GR_APP -->|served on| HUGGING
    GR_APP -->|output| User

    User -->|HTTP Request| FA_MAIN
    FA_MAIN -->|forwards to| FA_PIPE
    FA_PIPE -->|calls| PIPE
    PIPE -->|API Key, gpt-4o/gpt-4o-mini| OPENAI
    OPENAI -->|response| PIPE
    PIPE -->|data| FA_PIPE
    FA_PIPE -->|response| FA_MAIN
    FA_MAIN -->|HTTP Response| User

    %% Documentation and Assets
    ROOT_REQ --> README
    README --> MEDIA

    classDef interface fill:#bbdefb,stroke:#2b669a,color:#0b2e8a
    classDef core fill:#c8e6c9,stroke:#2e7d32,color:#1b5e20
    classDef external fill:#ffe0b2,stroke:#f57c00,color:#e65100
    classDef infra fill:#f5f5f5,stroke:#9e9e9e,color:#424242
```
