# ushasreddy060626/ai-powered-latex-diagram-generator architecture

> Architecture diagram of the GitHub repository ushasreddy060626/ai-powered-latex-diagram-generator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ushasreddy060626/ai-powered-latex-diagram-generator
- Repository: https://github.com/ushasreddy060626/ai-powered-latex-diagram-generator

## Overview

This is a Streamlit application that turns natural-language descriptions (and experimentally, sketches) into downloadable TikZ diagrams. The main workflow runs from user input through example retrieval and AI generation, then LaTeX compilation, repair, and preview; users can refine, undo, and export results. The graph preserves the README’s documented capabilities, while source-level evidence is limited to `rag.py` and `kb_examples.py`; relationships documented but not verified in sampled implementation are cited to the README.

Main entry points: [`app.py`](https://github.com/ushasreddy060626/ai-powered-latex-diagram-generator/blob/main/app.py) (Streamlit Interface), [`tikz_agent.py`](https://github.com/ushasreddy060626/ai-powered-latex-diagram-generator/blob/main/tikz_agent.py) (Diagram Agent), [`rag.py`](https://github.com/ushasreddy060626/ai-powered-latex-diagram-generator/blob/main/rag.py) (Similarity Retrieval), [`kb_examples.py`](https://github.com/ushasreddy060626/ai-powered-latex-diagram-generator/blob/main/kb_examples.py) (Verified TikZ Examples)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User Interface"]
  node_app["Streamlit Interface<br/>[app.py]"]
  node_sketch["Sketch Input<br/>[app.py]"]
  node_refine["Refine and Undo<br/>[app.py]"]
end

subgraph group_retrieval["Example Retrieval"]
  node_examples["Verified TikZ Examples<br/>[kb_examples.py]"]
  node_rag["Similarity Retrieval<br/>[rag.py]"]
  node_embedding["Embedding Service"]
end

subgraph group_generation["Diagram Generation"]
  node_agent["Diagram Agent<br/>[tikz_agent.py]"]
  node_textmodel["Granite Text Model"]
  node_vision["Vision Model"]
end

subgraph group_output["Compile and Export"]
  node_compiler["TikZ Compiler<br/>[tikz_agent.py]"]
  node_pdflatex["pdflatex"]
  node_preview["PDF Preview<br/>[tikz_agent.py]"]
  node_export["PDF and TikZ Export<br/>[app.py]"]
end

node_user(("Diagram Author"))

node_user -->|"describes diagram"| node_app
node_user -.->|"uploads sketch"| node_sketch
node_app -.->|"routes upload"| node_sketch
node_sketch -.->|"interprets sketch"| node_vision
node_app -->|"requests generation"| node_agent
node_agent -->|"retrieves examples"| node_rag
node_rag -->|"embeds query"| node_embedding
node_rag -->|"embeds descriptions"| node_examples
node_agent -->|"generates TikZ"| node_textmodel
node_agent -->|"compiles code"| node_compiler
node_compiler -->|"runs compiler"| node_pdflatex
node_compiler -->|"requests repair"| node_textmodel
node_compiler -->|"converts PDF"| node_preview
node_app -->|"accepts instructions"| node_refine
node_refine -->|"modifies diagram"| node_agent
node_app -->|"offers downloads"| node_export
node_preview -->|"displays preview"| node_app

click node_app "https://github.com/ushasreddy060626/ai-powered-latex-diagram-generator/blob/main/app.py"
click node_sketch "https://github.com/ushasreddy060626/ai-powered-latex-diagram-generator/blob/main/app.py"
click node_refine "https://github.com/ushasreddy060626/ai-powered-latex-diagram-generator/blob/main/app.py"
click node_examples "https://github.com/ushasreddy060626/ai-powered-latex-diagram-generator/blob/main/kb_examples.py"
click node_rag "https://github.com/ushasreddy060626/ai-powered-latex-diagram-generator/blob/main/rag.py"
click node_agent "https://github.com/ushasreddy060626/ai-powered-latex-diagram-generator/blob/main/tikz_agent.py"
click node_compiler "https://github.com/ushasreddy060626/ai-powered-latex-diagram-generator/blob/main/tikz_agent.py"
click node_preview "https://github.com/ushasreddy060626/ai-powered-latex-diagram-generator/blob/main/tikz_agent.py"
click node_export "https://github.com/ushasreddy060626/ai-powered-latex-diagram-generator/blob/main/app.py"

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_app,node_sketch,node_refine toneBlue
class node_examples,node_rag,node_embedding toneAmber
class node_agent,node_textmodel,node_vision toneMint
class node_compiler,node_pdflatex,node_preview,node_export toneRose
class node_user toneIndigo
```

## Components

### User Interface

- [Streamlit Interface](https://github.com/ushasreddy060626/ai-powered-latex-diagram-generator/blob/main/app.py): `app.py`
- [Sketch Input](https://github.com/ushasreddy060626/ai-powered-latex-diagram-generator/blob/main/app.py): `app.py`
- [Refine and Undo](https://github.com/ushasreddy060626/ai-powered-latex-diagram-generator/blob/main/app.py): `app.py`

### Example Retrieval

- [Verified TikZ Examples](https://github.com/ushasreddy060626/ai-powered-latex-diagram-generator/blob/main/kb_examples.py): `kb_examples.py`
- [Similarity Retrieval](https://github.com/ushasreddy060626/ai-powered-latex-diagram-generator/blob/main/rag.py): `rag.py`
- **Embedding Service**

### Diagram Generation

- [Diagram Agent](https://github.com/ushasreddy060626/ai-powered-latex-diagram-generator/blob/main/tikz_agent.py): `tikz_agent.py`
- **Granite Text Model**
- **Vision Model**

### Compile and Export

- [TikZ Compiler](https://github.com/ushasreddy060626/ai-powered-latex-diagram-generator/blob/main/tikz_agent.py): `tikz_agent.py`
- **pdflatex**
- [PDF Preview](https://github.com/ushasreddy060626/ai-powered-latex-diagram-generator/blob/main/tikz_agent.py): `tikz_agent.py`
- [PDF and TikZ Export](https://github.com/ushasreddy060626/ai-powered-latex-diagram-generator/blob/main/app.py): `app.py`

### Other components

- **Diagram Author**

## Connections

- Diagram Author → Streamlit Interface: describes diagram (evidence: `README.md`)
- Diagram Author → Sketch Input: uploads sketch (evidence: `README.md`)
- Streamlit Interface → Sketch Input: routes upload (evidence: `README.md`)
- Sketch Input → Vision Model: interprets sketch (evidence: `README.md`)
- Streamlit Interface → Diagram Agent: requests generation (evidence: `README.md`)
- Diagram Agent → Similarity Retrieval: retrieves examples (evidence: `README.md`)
- Similarity Retrieval → Embedding Service: embeds query (evidence: `rag.py`)
- Similarity Retrieval → Verified TikZ Examples: embeds descriptions (evidence: `rag.py`)
- Diagram Agent → Granite Text Model: generates TikZ (evidence: `README.md`)
- Diagram Agent → TikZ Compiler: compiles code (evidence: `README.md`)
- TikZ Compiler → pdflatex: runs compiler (evidence: `README.md`)
- TikZ Compiler → Granite Text Model: requests repair (evidence: `README.md`)
- TikZ Compiler → PDF Preview: converts PDF (evidence: `README.md`)
- Streamlit Interface → Refine and Undo: accepts instructions (evidence: `README.md`)
- Refine and Undo → Diagram Agent: modifies diagram (evidence: `README.md`)
- Streamlit Interface → PDF and TikZ Export: offers downloads (evidence: `README.md`)
- PDF Preview → Streamlit Interface: displays preview (evidence: `README.md`)
