# pavanku7/promt-eng-using-streamlit architecture

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

- Interactive diagram: https://gitdiagram.com/pavanku7/promt-eng-using-streamlit
- Repository: https://github.com/pavanku7/promt-eng-using-streamlit

## Overview

##### Project Type and Purpose
- This is an open-source, single-page Streamlit application (“tool-for-prompt-research”) whose goal is to help researchers craft, test, and store prompts against an LLM (IBM BAM or watsonx).
- The user interacts via a browser UI, the app orchestrates prompt generation, calls an external API, processes or parses returned data, and saves results locally.

##### Top Level Architecture Components
a. Streamlit UI Layer (src/main.py)
- Renders the web interface, collects user inputs (prompt text, options).
- Submits user actions into the backend controllers.
b. Core Business Logic
- language_model.py: wraps calls to the external LLM endpoints (BAM or watsonx).
- StoryCreation.py & dmb_sample.py: generate or format prompts (templates, story scaffolds).
- svg_parser.py: post-processes any SVG outputs or parses diagrammatic responses.
- save_results.py: handles persistence (writes JSON or text files under a results folder).
c. External Services
- IBM BAM or watsonx REST API (configured via .env).
d. Local File System
- Configuration (.env)
- requirements.txt for dependencies
- src/story_generator.txt, src/struts_*.txt as prompt templates
- Output folder (not committed) or local storage for result files

##### Interactions and Data Flow
- User → Streamlit UI: selects or enters prompt parameters.
- UI → Controller (main.py): calls business-logic modules.
- Controller → language_model: constructs API request (with API key and URL).
- language_model ↔ External LLM API: sends prompt, retrieves response.
- Controller → Processors (StoryCreation, svg_parser, dmb_sample) to refine or extract structure.
- Controller → save_results: writes output to disk.
- save_results → User: offers download link or displays saved results in UI.

##### Architectural Patterns & Design Principles
- Separation of Concerns: UI layer vs. service layer vs. data persistence layer.
- Modularization: each core function (prompt generation, API client, parsing, storage) lives in its own module.
- Configuration-driven: external service endpoints and keys live in env vars.
- Extensibility: new prompt templates or processors can be added by dropping a new .txt and wiring into main.py.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "UI Layer"
        UI["Streamlit UI"]:::ui
        Controller["Main Controller\n(main.py)"]:::ui
        UI -->|"user input"| Controller
    end

    %% Core Business Logic
    Controller -->|"generate prompt"| LM["LanguageModel Client\n(language_model.py)"]:::logic
    LM -->|"send prompt & receive response"| API["IBM BAM/WatsonX API"]:::external
    API -->|"response"| LM

    Controller -->|"parse/format"| Proc1["StoryCreation\n(StoryCreation.py)"]:::logic
    Controller -->|"sample formatting"| Proc2["DMB Sample\n(dmb_sample.py)"]:::logic
    Controller -->|"parse SVG"| Proc3["SVG Parser\n(svg_parser.py)"]:::logic

    Controller -->|"write results"| Save["Save Results\n(save_results.py)"]:::logic

    %% Local File System & Resources
    subgraph "Local File System" 
        direction TB
        FS[(Files & Templates)]:::resource
        Env[".env.example"]:::resource
        Req["requirements.txt"]:::resource
        T1["story_generator.txt"]:::resource
        T2["struts_.txt"]:::resource
        T3["struts__with-prompt.txt"]:::resource
        T4["PromptTest_.txt"]:::resource
    end

    Save -->|"writes to"| FS
    FS -->|"display/download"| UI
    Env -->|"configures"| LM
    Env -->|"configures"| Controller
    Req -.->|"deps"| Controller

    %% Styling
    classDef ui fill:#cfe2f3,stroke:#0b5394,color:#0b5394;
    classDef logic fill:#d9ead3,stroke:#38761d,color:#38761d;
    classDef resource fill:#ffe599,stroke:#b45f06,color:#b45f06;
    classDef external fill:#f4cccc,stroke:#cc0000,color:#cc0000;

    %% Click events
    click Controller "https://github.com/pavanku7/promt-eng-using-streamlit/blob/main/src/main.py"
    click LM "https://github.com/pavanku7/promt-eng-using-streamlit/blob/main/src/language_model.py"
    click Proc1 "https://github.com/pavanku7/promt-eng-using-streamlit/blob/main/src/StoryCreation.py"
    click Proc2 "https://github.com/pavanku7/promt-eng-using-streamlit/blob/main/src/dmb_sample.py"
    click Proc3 "https://github.com/pavanku7/promt-eng-using-streamlit/blob/main/src/svg_parser.py"
    click Save "https://github.com/pavanku7/promt-eng-using-streamlit/blob/main/src/save_results.py"
    click Env "https://github.com/pavanku7/promt-eng-using-streamlit/blob/main/.env.example"
    click Req "https://github.com/pavanku7/promt-eng-using-streamlit/blob/main/requirements.txt"
    click T1 "https://github.com/pavanku7/promt-eng-using-streamlit/blob/main/src/story_generator.txt"
    click T2 "https://github.com/pavanku7/promt-eng-using-streamlit/blob/main/src/struts_.txt"
    click T3 "https://github.com/pavanku7/promt-eng-using-streamlit/blob/main/src/struts__with-prompt.txt"
    click T4 "https://github.com/pavanku7/promt-eng-using-streamlit/blob/main/src/PromptTest_.txt"
```
