# panoskolyvakis/ai-to-latex architecture

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

- Interactive diagram: https://gitdiagram.com/panoskolyvakis/ai-to-latex
- Repository: https://github.com/panoskolyvakis/ai-to-latex

## Overview

This Flask application turns a user query into a sourced blog document and downloadable PDF: the browser submits a query, the server searches, selects either ordinary GPT generation or a web-scraping option, and compiles the resulting LaTeX. Users can refine generated content or edit the TeX and recompile. The README also documents search, GPT, LaTeX templates, and PDF delivery. Edges reflect shown routes and calls; the scraping-to-generator call is omitted because the relevant implementation is not excerpted.

Main entry points: [`app.py`](https://github.com/panoskolyvakis/ai-to-latex/blob/main/app.py) (Flask routes), [`templates/script.js`](https://github.com/panoskolyvakis/ai-to-latex/blob/main/templates/script.js) (Browser controls), [`response.py`](https://github.com/panoskolyvakis/ai-to-latex/blob/main/response.py) (GPT generation), [`LaTeXprocessing.py`](https://github.com/panoskolyvakis/ai-to-latex/blob/main/LaTeXprocessing.py) (PDF compilation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web interface"]
  node_browser["Browser controls<br/>[script.js]"]
  node_home["Web page<br/>[index.html]"]
end

subgraph group_workflow["Document workflow"]
  node_flask["Flask routes<br/>[app.py]"]
end

subgraph group_content["Content sources"]
  node_search["Google search<br/>[response.py]"]
  node_scrape["Page scraper<br/>[WebScrapper.py]"]
  node_gpt["GPT generation<br/>[response.py]"]
  node_refine["Document refinement<br/>[response.py]"]
end

subgraph group_render["LaTeX output"]
  node_templates["Document templates<br/>[LaTeXprocessing.py]"]
  node_tex["TeX authoring<br/>[response.py]"]
  node_compile["PDF compilation<br/>[LaTeXprocessing.py]"]
  node_pdf["Generated PDF<br/>[LaTeXprocessing.py]"]
end

node_user(("User"))
node_google{{"Google CSE"}}
node_openai{{"OpenAI API"}}
node_websites{{"Source websites"}}
node_pdflatex{{"pdflatex"}}

node_user -->|"enters query"| node_browser
node_browser -->|"uses page"| node_home
node_browser -->|"submits requests"| node_flask
node_flask -->|"returns responses"| node_browser
node_flask -->|"searches query"| node_search
node_search -->|"queries"| node_google
node_flask -->|"selects template"| node_templates
node_flask -->|"generates content"| node_gpt
node_gpt -->|"requests completion"| node_openai
node_flask -.->|"selects scrape mode"| node_scrape
node_scrape -->|"fetches pages"| node_websites
node_flask -->|"submits refinement"| node_refine
node_refine -->|"requests revision"| node_openai
node_gpt -->|"writes TeX"| node_tex
node_refine -->|"updates TeX"| node_tex
node_flask -->|"compiles document"| node_compile
node_compile -->|"runs compiler"| node_pdflatex
node_compile -->|"produces PDF"| node_pdf
node_browser -->|"requests PDF status"| node_flask
node_flask -->|"serves download"| node_pdf

click node_browser "https://github.com/panoskolyvakis/ai-to-latex/blob/main/templates/script.js"
click node_home "https://github.com/panoskolyvakis/ai-to-latex/blob/main/templates/index.html"
click node_flask "https://github.com/panoskolyvakis/ai-to-latex/blob/main/app.py"
click node_search "https://github.com/panoskolyvakis/ai-to-latex/blob/main/response.py"
click node_scrape "https://github.com/panoskolyvakis/ai-to-latex/blob/main/WebScrapper.py"
click node_gpt "https://github.com/panoskolyvakis/ai-to-latex/blob/main/response.py"
click node_refine "https://github.com/panoskolyvakis/ai-to-latex/blob/main/response.py"
click node_templates "https://github.com/panoskolyvakis/ai-to-latex/blob/main/LaTeXprocessing.py"
click node_tex "https://github.com/panoskolyvakis/ai-to-latex/blob/main/response.py"
click node_compile "https://github.com/panoskolyvakis/ai-to-latex/blob/main/LaTeXprocessing.py"
click node_pdf "https://github.com/panoskolyvakis/ai-to-latex/blob/main/LaTeXprocessing.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_browser,node_home,node_user toneBlue
class node_flask toneAmber
class node_search,node_scrape,node_gpt,node_refine,node_openai toneMint
class node_templates,node_tex,node_compile,node_pdf toneRose
class node_google,node_websites,node_pdflatex toneIndigo
```

## Components

### Web interface

- [Browser controls](https://github.com/panoskolyvakis/ai-to-latex/blob/main/templates/script.js): `templates/script.js`
- [Web page](https://github.com/panoskolyvakis/ai-to-latex/blob/main/templates/index.html): `templates/index.html`

### Document workflow

- [Flask routes](https://github.com/panoskolyvakis/ai-to-latex/blob/main/app.py): `app.py`

### Content sources

- [Google search](https://github.com/panoskolyvakis/ai-to-latex/blob/main/response.py): `response.py`
- [Page scraper](https://github.com/panoskolyvakis/ai-to-latex/blob/main/WebScrapper.py): `WebScrapper.py`
- [GPT generation](https://github.com/panoskolyvakis/ai-to-latex/blob/main/response.py): `response.py`
- [Document refinement](https://github.com/panoskolyvakis/ai-to-latex/blob/main/response.py): `response.py`

### LaTeX output

- [Document templates](https://github.com/panoskolyvakis/ai-to-latex/blob/main/LaTeXprocessing.py): `LaTeXprocessing.py`
- [TeX authoring](https://github.com/panoskolyvakis/ai-to-latex/blob/main/response.py): `response.py`
- [PDF compilation](https://github.com/panoskolyvakis/ai-to-latex/blob/main/LaTeXprocessing.py): `LaTeXprocessing.py`
- [Generated PDF](https://github.com/panoskolyvakis/ai-to-latex/blob/main/LaTeXprocessing.py): `LaTeXprocessing.py`

### Other components

- **User**
- **Google CSE**
- **OpenAI API**
- **Source websites**
- **pdflatex**

## Connections

- User → Browser controls: enters query (evidence: `README.md`)
- Browser controls → Web page: uses page (evidence: `templates/script.js`)
- Browser controls → Flask routes: submits requests (evidence: `templates/script.js`)
- Flask routes → Browser controls: returns responses (evidence: `app.py`)
- Flask routes → Google search: searches query (evidence: `app.py`)
- Google search → Google CSE: queries (evidence: `response.py`)
- Flask routes → Document templates: selects template (evidence: `app.py`)
- Flask routes → GPT generation: generates content (evidence: `app.py`)
- GPT generation → OpenAI API: requests completion (evidence: `response.py`)
- Flask routes → Page scraper: selects scrape mode
- Page scraper → Source websites: fetches pages (evidence: `WebScrapper.py`)
- Flask routes → Document refinement: submits refinement (evidence: `app.py`)
- Document refinement → OpenAI API: requests revision (evidence: `response.py`)
- GPT generation → TeX authoring: writes TeX (evidence: `response.py`)
- Document refinement → TeX authoring: updates TeX (evidence: `response.py`)
- Flask routes → PDF compilation: compiles document (evidence: `app.py`)
- PDF compilation → pdflatex: runs compiler (evidence: `LaTeXprocessing.py`)
- PDF compilation → Generated PDF: produces PDF (evidence: `LaTeXprocessing.py`)
- Browser controls → Flask routes: requests PDF status (evidence: `templates/script.js`)
- Flask routes → Generated PDF: serves download (evidence: `app.py`)
