# nestor20193767/testmedgan architecture

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

- Interactive diagram: https://gitdiagram.com/nestor20193767/testmedgan
- Repository: https://github.com/nestor20193767/testmedgan

## Overview

##### Project type and purpose
- This is a lightweight, single‐page Streamlit application for document question answering.
- Users upload a document; the app processes it, queries OpenAI’s GPT‐3.5, and returns answers.

##### File structure
- Top‐level:
- streamlit_app.py – main entry point (UI + backend logic)
- modelos/modelo_entrenado.pth – a local PyTorch model (e.g., for embeddings or preprocessing)
- config.toml & .streamlit/config.toml – Streamlit and app configuration
- requirements.txt – Python dependencies (including streamlit, torch, openai)
- .devcontainer – dev environment definition
- No separate “frontend” vs. “backend” folders; the code is monolithic but logically splits into UI (Streamlit) and processing layers.

##### README for additional insights
- Confirms: install requirements, run `streamlit run streamlit_app.py`.
- Uses OpenAI GPT-3.5 via API.
- No DB or caching; ephemeral in‐memory flow.

##### Main components & interactions
a. Streamlit UI Layer (streamlit_app.py)
- File‐upload widget
- Of questions and answers
b. Document Processing Pipeline
- File parser (PDF/TXT reader)
- Text chunking & vectorization (using modelo_entrenado.pth)
c. Query Engine
- Calls OpenAI API with context + user question
d. Configuration Layer
- Reads API keys and settings from config.toml / environment
e. External Service
- OpenAI GPT‐3.5
f. (Optional) Local Model Store
- modelos/modelo_entrenado.pth

##### Relationships & data flow
- User → Streamlit UI → Document parser → Chunker/Embedder → Query Engine → OpenAI API → Streamlit UI → User
- Config read occurs at startup and feeds both embedding and OpenAI calls.
- The local model is loaded once into memory and used by the pipeline.

##### Architectural patterns & design principles
- Monolithic but logically layered: presentation, processing, external integration.
- Single responsibility per module: UI vs. parsing vs. API client.
- Configuration‐driven (via TOML) for environment‐specific overrides.
- Containerized dev environment for reproducibility (.devcontainer).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User
    U[/User/] 

    %% Streamlit App Boundary
    subgraph "Streamlit App"
        UI["Streamlit UI Layer"]:::frontend
        Parser["Document Parser"]:::backend
        Embedder["Chunker & Embedder"]:::backend
        Query["Query Engine"]:::backend
        Config["⚙ Configuration"]:::config
        Model["Local Model Store"]:::modelstore
        Deps["requirements.txt"]:::storage
        DevC[".devcontainer"]:::storage
        Repo["README.md & LICENSE"]:::storage
    end

    %% External Service
    External{{"OpenAI GPT-3.5"}}:::external

    %% Data Flow
    U -->|"uploads document"| UI
    UI -->|"send raw file"| Parser
    Parser -->|"chunks text"| Embedder
    Embedder -->|"embeddings + context"| Query
    Query -->|"API call"| External
    External -->|"response"| Query
    Query -->|"answer"| UI
    UI -->|"display answer"| U

    %% Config and Model dependencies
    Config --> UI
    Config --> Parser
    Config --> Embedder
    Config --> Query
    Model --> Embedder

    %% Dev & Repo
    Deps -.-> UI
    DevC -.-> UI
    Repo -.-> UI

    %% Click Events
    click UI "https://github.com/nestor20193767/testmedgan/blob/main/streamlit_app.py"
    click Parser "https://github.com/nestor20193767/testmedgan/blob/main/streamlit_app.py"
    click Embedder "https://github.com/nestor20193767/testmedgan/blob/main/streamlit_app.py"
    click Query "https://github.com/nestor20193767/testmedgan/blob/main/streamlit_app.py"
    click Config "https://github.com/nestor20193767/testmedgan/blob/main/config.toml"
    click Config "https://github.com/nestor20193767/testmedgan/blob/main/.streamlit/config.toml"
    click Model "https://github.com/nestor20193767/testmedgan/blob/main/modelos/modelo_entrenado.pth"
    click Deps "https://github.com/nestor20193767/testmedgan/blob/main/requirements.txt"
    click DevC "https://github.com/nestor20193767/testmedgan/blob/main/.devcontainer/devcontainer.json"
    click Repo "https://github.com/nestor20193767/testmedgan/blob/main/README.md"
    click Repo "https://github.com/nestor20193767/testmedgan/tree/main/LICENSE"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef backend fill:#87CEFA,stroke:#333,stroke-width:1px
    classDef modelstore fill:#98FB98,stroke:#333,stroke-width:1px
    classDef external fill:#FFA500,stroke:#333,stroke-width:1px
    classDef config fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef storage fill:#f5f5dc,stroke:#333,stroke-width:1px
```
