# solalbaudoincs/slidestotex architecture

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

- Interactive diagram: https://gitdiagram.com/solalbaudoincs/slidestotex
- Repository: https://github.com/solalbaudoincs/slidestotex

## Overview

##### Main Components
- PDF Input & Conversion: Represents the component that accepts a PDF file and converts it into a set of images. Although this conversion logic might be embedded within the execution of src/slidetotex, it is crucial to capture it as the first processing step.
- Incremental Slide Detection: A key component that uses algorithms (SSIM, difference analysis) to detect which slides are essentially incremental versions of previous ones. This component is essential to reduce the number of AI processing calls.
- AI Processing Module: This part, primarily implemented in src/ai_processing.py, sends images (or parts thereof) to a Vision-Language Model (like GPT-4o) with a configurable prompt (found in files like prompts/example_prompt.txt) to retrieve well-formatted LaTeX output.
- Configuration & Prompt Management: The src/config.py and prompt files provide the parameters (API keys, image width, model name, etc.) and customization of the prompt for the conversion process.
- Storage & Persistence: Managed in src/storage.py, this component saves the converted LaTeX outputs and potentially tracks the results with their corresponding PDFs.
- Web Interface: The project includes a web server (src/interface.py) along with HTML templates (in src/templates) and static resources (CSS, JS under src/static) that allow users to view and interact with the processed PDFs and LaTeX outputs in their browser.
- Experimentation & Research: The experiments directory holds additional scripts and images that support testing and tuning (e.g., the experiments/experiments.py and images under experiments) but can be considered auxiliary to the main processing flow.

##### Relationships and Data Flow
- → PDF Conversion: This input is processed to extract images from the PDF.
- → Incremental Slide Detection: The images are then analyzed to detect which slides show significant changes (filtering out incremental updates).
- → AI Processing: Only the identified unique slides are sent to the AI module (using the configured prompt), which connects to the external VLM (GPT-4o) to obtain LaTeX translations.
- → Storage: The result (LaTeX code and any meta information) is stored locally via src/storage.py for future retrieval.
- → Web Interface: Optionally, users can launch the web server to view the processed slides and corresponding LaTeX output with interactive features.

##### Architectural Patterns and Design Principles
- Modular Design: Each stage (conversion, detection, AI processing, storage, and user interface) is separated into distinct modules/files (as seen in the src folder), making it easier to reason about data flow and maintenance.
- Separation of Concerns: CLI commands (invoked via src/slidetotex) are separated from the web interface (src/interface), ensuring that presentation logic and processing logic remain independent.
- Configurability: The use of a configuration file (src/config.py) and external prompt files indicates a design principle that favors user customization and flexibility.

##### Technologies and Frameworks
- Python: The whole application is developed in Python.
- GPT-4o / VLM: External AI service for image to LaTeX conversion.
- Web Framework: Likely a lightweight framework (e.g., Flask) given the file structure (templates and static files) in the src folder.
- Frontend Assets: Custom CSS and JavaScript (located in src/static) to support the web interface functionalities such as a PDF viewer.

##### Overall Detailing
- Emphasis on cost-effectiveness through the incremental slide detection algorithm, and highlight that the processing pipeline reduces redundant API calls.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Processing Pipeline
    subgraph "Processing Pipeline"
        U["User Input (PDF Upload)"]:::user
        PDF["PDF Input & Conversion"]:::processing
        DET["Incremental Slide Detection"]:::processing
        AI["AI Processing Module (GPT-4o)"]:::processing
        ST["Storage & Persistence"]:::storage
    end

    %% Configuration & Prompt Management
    subgraph "Configuration & Management"
        CFG["Configuration"]:::config
        PROMPT["Prompt Management"]:::config
    end

    %% Web Interface
    subgraph "Web Interface"
        WEB["Web Server"]:::web
        TEMP["HTML Templates"]:::web
        STAT["Static Assets (CSS/JS)"]:::web
    end

    %% Experiments
    subgraph "Experiments"
        EXP["Experimentation & Research"]:::experiments
    end

    %% Data Flow Connections
    U -->|"submits PDF"| PDF
    PDF -->|"converts PDF to images"| DET
    DET -->|"filters unique slides"| AI
    CFG -->|"configures"| AI
    PROMPT -->|"provides prompt"| AI
    AI -->|"generates LaTeX"| ST
    ST -->|"serves data to"| WEB
    WEB -->|"renders"| TEMP
    WEB --> STAT

    %% Click Events
    click PDF "https://github.com/solalbaudoincs/slidestotex/blob/master/src/slidetotex.py"
    click DET "https://github.com/solalbaudoincs/slidestotex/blob/master/src/image_utils.py"
    click AI "https://github.com/solalbaudoincs/slidestotex/blob/master/src/ai_processing.py"
    click CFG "https://github.com/solalbaudoincs/slidestotex/blob/master/src/config.py"
    click PROMPT "https://github.com/solalbaudoincs/slidestotex/blob/master/prompts/example_prompt.txt"
    click ST "https://github.com/solalbaudoincs/slidestotex/blob/master/src/storage.py"
    click WEB "https://github.com/solalbaudoincs/slidestotex/blob/master/src/interface.py"
    click TEMP "https://github.com/solalbaudoincs/slidestotex/tree/master/src/templates"
    click STAT "https://github.com/solalbaudoincs/slidestotex/tree/master/src/static"
    click EXP "https://github.com/solalbaudoincs/slidestotex/tree/master/experiments"

    %% Styling
    classDef user fill:#E1BEE7,stroke:#333,stroke-width:2px;
    classDef processing fill:#BBDEFB,stroke:#333,stroke-width:2px;
    classDef storage fill:#FFF9C4,stroke:#333,stroke-width:2px;
    classDef config fill:#D1C4E9,stroke:#333,stroke-width:2px;
    classDef web fill:#C8E6C9,stroke:#333,stroke-width:2px;
    classDef experiments fill:#FFCDD2,stroke:#333,stroke-width:2px;
```
