# jgravelle/grompt architecture

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

- Interactive diagram: https://gitdiagram.com/jgravelle/grompt
- Repository: https://github.com/jgravelle/grompt

## Overview

##### Project type and purpose
- This is an open-source Python utility (“Grompt”) that serves as both:
a. A command-line tool / importable module for programmatically refactoring LLM prompts.
b. A Streamlit-based web demo app for interactive prompt optimization.
- Its purpose is to accept a user’s natural-language prompt, apply configurable transformation settings, and call the Groq LLM API to return a polished, structured prompt.

##### File structure
- Top-level scripts:
- Grompt.py ­– core library and CLI entry point
- streamlit_app.py ­– front-end web app using Streamlit
- prompt_canvas.py ­– auxiliary script (e.g., interactive local prompt builder/demo)
- Configuration and docs:
- .env_sample (sample environment variables)
- requirements.txt (dependencies: groq, python-dotenv, streamlit, etc.)
- src/ (contains Markdown guides: Grompt.md and custom_instructions.txt)
- No internal database or persistent storage—state is in memory; configuration via environment.

##### README for additional insights
- Core workflow: load .env → initialize Groq client → accept prompt → optionally read defaults from src/ → call Groq API → return optimized prompt.
- Two usage modes: CLI and Streamlit web UI.
- Configurable defaults: model, temperature, max_tokens.

##### Main components and interactions (to be shown
a. Front-ends
- CLI interface (Grompt.py main)
- Streamlit UI (streamlit_app.py)
- Optional local canvas UI (prompt_canvas.py)
b. Core service
- Grompt module:
- Config loader (dotenv)
- Default-prompt loader (src/Grompt.md, src/custom_instructions.txt)
- API client wrapper (groq Python SDK)
c. External service
- Groq LLM API endpoint
d. Supporting configuration
- .env file (.env_sample template)
- requirements.txt dependencies

##### Relationships and data flow
- User enters prompt (CLI or browser)
→ Front-end script invokes Grompt.rephrase_prompt()
→ Grompt module loads environment and default templates
→ Constructs API request and posts to Groq LLM service over HTTPS
→ Receives optimized prompt JSON response
→ Returns to front-end for display (stdout or web page)

##### Architectural patterns and design principles
- Separation of concerns:
- Presentation layer (CLI / Web UI)
- Business logic (prompt transformation and API orchestration in Grompt.py)
- Configuration layer (dotenv + src/)
- Plug-and-play extensibility: Grompt.py can be imported into any Python project.
- No persistent data store—stateless, real-time API calls.

##### Technologies and frameworks
- Python 3.6+
- groq Python SDK for API calls
- python-dotenv for configuration
- Streamlit for web UI

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User
    User["User"]:::user

    %% Presentation Layer
    subgraph "Presentation Layer"
        CLI["CLI (Grompt.py)"]:::presentation
        Streamlit["Streamlit App"]:::presentation
        Canvas["Local Canvas UI"]:::presentation
    end

    %% Core Module
    Core["Grompt Module"]:::core

    %% Configuration Layer
    subgraph "Configuration Layer"
        Env[".env (dotenv sample)"]:::config
        Req["requirements.txt"]:::config
        Template["src/Grompt.md"]:::config
        Instructions["src/custom_instructions.txt"]:::config
        Docs["README.md"]:::docs
    end

    %% External Service
    Groq["Groq LLM API"]:::external

    %% Data Flow
    User -->|"enters prompt"| CLI
    User -->|"enters prompt"| Streamlit
    User -->|"enters prompt"| Canvas

    CLI -->|"rephrase_prompt()"| Core
    Streamlit -->|"rephrase_prompt()"| Core
    Canvas -->|"rephrase_prompt()"| Core

    Core -->|"load .env → initialize client"| Env
    Core -->|"load dependencies"| Req
    Core -->|"load default prompt"| Template
    Core -->|"load custom instructions"| Instructions
    Core -->|"load usage guide"| Docs

    Core -->|"POST /v1/refactor_prompt"| Groq
    Groq -->|"optimized prompt JSON"| Core

    Core -->|"return optimized prompt"| CLI
    Core -->|"return optimized prompt"| Streamlit
    Core -->|"return optimized prompt"| Canvas

    CLI -->|"display stdout"| User
    Streamlit -->|"render web UI"| User
    Canvas -->|"render local canvas"| User

    %% Click Events
    click CLI "https://github.com/jgravelle/grompt/blob/main/Grompt.py"
    click Core "https://github.com/jgravelle/grompt/blob/main/Grompt.py"
    click Streamlit "https://github.com/jgravelle/grompt/blob/main/streamlit_app.py"
    click Canvas "https://github.com/jgravelle/grompt/blob/main/prompt_canvas.py"
    click Env "https://github.com/jgravelle/grompt/blob/main/.env_sample"
    click Req "https://github.com/jgravelle/grompt/blob/main/requirements.txt"
    click Template "https://github.com/jgravelle/grompt/blob/main/src/Grompt.md"
    click Instructions "https://github.com/jgravelle/grompt/blob/main/src/custom_instructions.txt"
    click Docs "https://github.com/jgravelle/grompt/blob/main/README.md"

    %% Styles
    classDef presentation fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef core fill:#90EE90,stroke:#333,stroke-width:1px
    classDef config fill:#FFA500,stroke:#333,stroke-width:1px
    classDef external fill:#FFD700,stroke:#333,stroke-width:1px
    classDef docs fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef user fill:#FFFFFF,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
```
