# o-k1ng0/promptalloy architecture

> Architecture diagram of the GitHub repository o-k1ng0/promptalloy, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/o-k1ng0/promptalloy
- Repository: https://github.com/o-k1ng0/promptalloy

## Overview

#### Purpose and Runtime

PromptAlloy is a local Flask application that turns a free-form project idea into an LLM-ready implementation blueprint. It runs via `app.py`, serves browser pages from `templates/`, and uses vanilla browser JavaScript under `static/js/`. Python dependencies and environment-driven provider settings are defined in `requirements.txt` and `.env.example`.

#### HTTP Application and UI Entry Points

`app.py` is the backend entry point and central orchestration boundary: it serves the wizard, session detail, and history views; validates requests; calls LLM providers; and persists generated output. The primary UI routes are represented by:
- `templates/index.html` — three-stage idea, clarification, and blueprint workflow.
- `templates/session.html` — generated blueprint/session view and export actions.
- `templates/history.html` — persisted-session listing.

#### Blueprint Generation Pipeline

The principal control flow is: user description → local validation → LLM-generated clarification questions → optional per-question AI answers → final blueprint generation → session persistence and display. Backend prompt construction and provider invocation reside in `app.py`; browser workflow state and API calls are coordinated by `static/js/script.js`. The application intentionally produces textual implementation instructions rather than generated source code.

#### LLM Provider Boundary

The backend is provider-agnostic at the OpenAI-compatible `chat/completions` boundary. It reads API key, endpoint URL, model, and provider identity from environment configuration, allowing OpenRouter, OpenAI, Groq, NVIDIA NIM, Together AI, or local Ollama endpoints. `app.py` also supports Gemini as a fallback path when the primary provider fails. `.env.example` is the deploy-time configuration contract; no provider credentials belong in application state.

#### Client-Side Workflow and Export

The main wizard behavior—including idea submission, clarification rendering, answer generation, and final generation—is implemented in `static/js/script.js`. Generated sessions support browser-side copy and downloads in Markdown, text, and JSON through `static/js/session.js`. Presentation is server-rendered HTML with a shared static visual layer in `static/css/style.css`; there is no separate frontend build runtime.

#### Persistence and History

Generated blueprint sessions are stored as file-based JSON rather than in a database. `data/history.json` is the durable local history artifact, managed by backend logic in `app.py`. History retrieval, display, and clearing interactions are handled in `templates/history.html` and `static/js/history.js`. This makes persistence single-instance/local-filesystem scoped and is the main operational boundary for concurrent or multi-host deployment considerations.

#### Material Architecture Constraints

The application requires Python 3.10+, Flask, outbound access to the selected LLM endpoint (unless using local Ollama), and writable access to `data/`. It is a server-rendered local web app with browser-to-Flask requests and Flask-to-LLM-provider requests; the browser does not directly hold provider credentials.

Main entry points: [`app.py`](https://github.com/o-k1ng0/promptalloy/blob/main/app.py) (Flask application), [`templates/session.html`](https://github.com/o-k1ng0/promptalloy/blob/main/templates/session.html) (Session detail), [`templates/index.html`](https://github.com/o-k1ng0/promptalloy/blob/main/templates/index.html) (Blueprint wizard), [`templates/history.html`](https://github.com/o-k1ng0/promptalloy/blob/main/templates/history.html) (History page)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_browser["Browser UI"]
  node_wizard_page["Blueprint wizard<br/>server-rendered page<br/>[index.html]"]
  node_session_page["Session detail<br/>server-rendered page<br/>[session.html]"]
  node_history_page["History page<br/>server-rendered page<br/>[history.html]"]
  node_wizard_client["Wizard workflow<br/>browser JavaScript<br/>[script.js]"]
  node_session_export["Session export<br/>browser JavaScript<br/>[session.js]"]
  node_history_client["History interactions<br/>browser JavaScript<br/>[history.js]"]
  node_shared_styles["Shared visual layer<br/>CSS<br/>[style.css]"]
end

subgraph group_backend["Flask Backend"]
  node_app["Flask application<br/>Python entry point<br/>[app.py]"]
  node_request_validation["Request validation<br/>backend layer<br/>[app.py]"]
  node_prompt_generation["Prompt &amp; blueprint generation<br/>backend layer<br/>[app.py]"]
  node_provider_client{{"LLM provider client<br/>provider adapter<br/>[app.py]"}}
  node_session_repository["Session persistence<br/>file repository<br/>[app.py]"]
end

subgraph group_external["External Services &amp; Storage"]
  node_environment_contract["Provider environment config<br/>environment contract<br/>[.env.example]"]
  node_llm_endpoints{{"Configured LLM endpoint<br/>LLM service"}}
  node_history_store[("Local session history<br/>JSON file<br/>[history.json]")]
  node_python_dependencies["Python dependencies<br/>runtime manifest<br/>[requirements.txt]"]
end

node_wizard_page -->|"loads"| node_wizard_client
node_session_page -->|"loads"| node_session_export
node_history_page -->|"loads"| node_history_client
node_wizard_page -->|"styled by"| node_shared_styles
node_session_page -->|"styled by"| node_shared_styles
node_history_page -->|"styled by"| node_shared_styles
node_wizard_client -->|"wizard requests"| node_app
node_session_export -->|"exports displayed session"| node_session_page
node_history_client -->|"history requests"| node_app
node_app -->|"renders"| node_wizard_page
node_app -->|"renders"| node_session_page
node_app -->|"renders"| node_history_page
node_app -->|"validates through"| node_request_validation
node_request_validation -->|"accepted input"| node_prompt_generation
node_prompt_generation -->|"invokes"| node_provider_client
node_provider_client -->|"chat completions"| node_llm_endpoints
node_environment_contract -.->|"configures"| node_provider_client
node_prompt_generation -->|"stores final blueprint"| node_session_repository
node_session_repository -->|"reads and writes"| node_history_store
node_python_dependencies -.->|"provides runtime"| node_app

click node_app "https://github.com/o-k1ng0/promptalloy/blob/main/app.py"
click node_request_validation "https://github.com/o-k1ng0/promptalloy/blob/main/app.py"
click node_prompt_generation "https://github.com/o-k1ng0/promptalloy/blob/main/app.py"
click node_provider_client "https://github.com/o-k1ng0/promptalloy/blob/main/app.py"
click node_session_repository "https://github.com/o-k1ng0/promptalloy/blob/main/app.py"
click node_wizard_page "https://github.com/o-k1ng0/promptalloy/blob/main/templates/index.html"
click node_session_page "https://github.com/o-k1ng0/promptalloy/blob/main/templates/session.html"
click node_history_page "https://github.com/o-k1ng0/promptalloy/blob/main/templates/history.html"
click node_wizard_client "https://github.com/o-k1ng0/promptalloy/blob/main/static/js/script.js"
click node_session_export "https://github.com/o-k1ng0/promptalloy/blob/main/static/js/session.js"
click node_history_client "https://github.com/o-k1ng0/promptalloy/blob/main/static/js/history.js"
click node_shared_styles "https://github.com/o-k1ng0/promptalloy/blob/main/static/css/style.css"
click node_environment_contract "https://github.com/o-k1ng0/promptalloy/blob/main/.env.example"
click node_history_store "https://github.com/o-k1ng0/promptalloy/blob/main/data/history.json"
click node_python_dependencies "https://github.com/o-k1ng0/promptalloy/blob/main/requirements.txt"

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_wizard_page,node_session_page,node_history_page,node_wizard_client,node_session_export,node_history_client,node_shared_styles toneBlue
class node_app,node_request_validation,node_prompt_generation,node_provider_client,node_session_repository toneAmber
class node_environment_contract,node_llm_endpoints,node_history_store,node_python_dependencies toneMint
```

## Components

### Browser UI

Server-rendered pages and vanilla JavaScript workflows.

- [Blueprint wizard](https://github.com/o-k1ng0/promptalloy/blob/main/templates/index.html): server-rendered page · Three-stage idea, clarification, and blueprint workflow. · `templates/index.html`
- [Session detail](https://github.com/o-k1ng0/promptalloy/blob/main/templates/session.html): server-rendered page · Displays a generated blueprint and export controls. · `templates/session.html`
- [History page](https://github.com/o-k1ng0/promptalloy/blob/main/templates/history.html): server-rendered page · Lists persisted sessions and supports clearing history. · `templates/history.html`
- [Wizard workflow](https://github.com/o-k1ng0/promptalloy/blob/main/static/js/script.js): browser JavaScript · Coordinates submissions, clarifications, AI answers, and final generation. · `static/js/script.js`
- [Session export](https://github.com/o-k1ng0/promptalloy/blob/main/static/js/session.js): browser JavaScript · Copies and downloads Markdown, text, and JSON. · `static/js/session.js`
- [History interactions](https://github.com/o-k1ng0/promptalloy/blob/main/static/js/history.js): browser JavaScript · Retrieves and clears persisted session history. · `static/js/history.js`
- [Shared visual layer](https://github.com/o-k1ng0/promptalloy/blob/main/static/css/style.css): CSS · `static/css/style.css`

### Flask Backend

Local orchestration and provider boundary.

- [Flask application](https://github.com/o-k1ng0/promptalloy/blob/main/app.py): Python entry point · Serves views, APIs, generation, and persistence. · `app.py`
- [Request validation](https://github.com/o-k1ng0/promptalloy/blob/main/app.py): backend layer · Validates idea and clarification inputs before generation. · `app.py`
- [Prompt & blueprint generation](https://github.com/o-k1ng0/promptalloy/blob/main/app.py): backend layer · Builds prompts for clarifications, answers, and final blueprint text. · `app.py`
- [LLM provider client](https://github.com/o-k1ng0/promptalloy/blob/main/app.py): provider adapter · Uses OpenAI-compatible chat completions with Gemini fallback. · `app.py`
- [Session persistence](https://github.com/o-k1ng0/promptalloy/blob/main/app.py): file repository · Reads, writes, lists, and clears generated sessions. · `app.py`

### External Services & Storage

Environment-configured LLM access and local persistence.

- [Provider environment config](https://github.com/o-k1ng0/promptalloy/blob/main/.env.example): environment contract · Defines provider identity, endpoint, model, and API key settings. · `.env.example`
- **Configured LLM endpoint**: LLM service · Remote provider or local Ollama endpoint.
- [Local session history](https://github.com/o-k1ng0/promptalloy/blob/main/data/history.json): JSON file · Single-instance durable blueprint-session store. · `data/history.json`
- [Python dependencies](https://github.com/o-k1ng0/promptalloy/blob/main/requirements.txt): runtime manifest · Defines Flask and required Python packages. · `requirements.txt`

## Connections

- Blueprint wizard → Wizard workflow: loads
- Session detail → Session export: loads
- History page → History interactions: loads
- Blueprint wizard → Shared visual layer: styled by
- Session detail → Shared visual layer: styled by
- History page → Shared visual layer: styled by
- Wizard workflow → Flask application: wizard requests
- Session export → Session detail: exports displayed session
- History interactions → Flask application: history requests
- Flask application → Blueprint wizard: renders
- Flask application → Session detail: renders
- Flask application → History page: renders
- Flask application → Request validation: validates through
- Request validation → Prompt & blueprint generation: accepted input
- Prompt & blueprint generation → LLM provider client: invokes
- LLM provider client → Configured LLM endpoint: chat completions
- Provider environment config → LLM provider client: configures
- Prompt & blueprint generation → Session persistence: stores final blueprint
- Session persistence → Local session history: reads and writes
- Python dependencies → Flask application: provides runtime
