# ritareasciencepark/fastapi-llm architecture

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

- Interactive diagram: https://gitdiagram.com/ritareasciencepark/fastapi-llm
- Repository: https://github.com/ritareasciencepark/fastapi-llm

## Overview

##### Project type and purpose
- From the README (“FastAPI-LLM: A simple web (FastAPI) interface for LLM+database interactions”) and the file tree, this is a lightweight full-stack web application.
- Its goal is to let users submit queries via a form, have the backend call an LLM (and/or vector-search routines), store or retrieve summaries in JSON files, and render results in HTML.

##### File structure
- Top-level scripts:
- main.py – the FastAPI app and route definitions
- elab_api.py – encapsulates the “elaboration” or LLM API calls
- elab_vector.py – handles vectorization or similarity search logic
- playground.py – likely a dev/test harness or interactive notebook script
- query_summary.json & summaries.json – simple file-based “database” of past queries and generated summaries
- Directories:
- static/ – CSS or client-side assets (styles.css)
- templates/ – Jinja2 templates for the HTML views (form.html, response.html, stream_map.html)

##### README for additional insights
- Minimal description but clearly states: “web interface” + “LLM+database interactions.”

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Documentation
    README["README.md"]:::docs

    %% Frontend Layer
    subgraph "Frontend Layer"
        Browser["Client Browser"]:::frontend
        Static["Static Assets"]:::frontend
        Templates["Jinja2 Templates"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        FastAPI["FastAPI App<br/>(main.py)"]:::backend
        ElabAPI["elab_api Module"]:::backend
        ElabVec["elab_vector Module"]:::backend
        Playground["Playground (Dev/Test)"]:::backend
    end

    %% Persistence Layer
    subgraph "Persistence"
        QS["query_summary.json"]:::storage
        Sum["summaries.json"]:::storage
    end

    %% External Services
    ExternalLLM["External LLM Service"]:::external

    %% Connections
    README --> FastAPI

    Browser -->|GET form| FastAPI
    FastAPI -->|serve| Static
    FastAPI -->|render form| Templates
    Templates -->|HTML| Browser

    Browser -->|POST query| FastAPI
    FastAPI -->|invoke| ElabVec
    ElabVec -->|lookup| Sum
    Sum -->|found?| FastAPI
    FastAPI -->|call API| ElabAPI
    ElabAPI -->|request/response| ExternalLLM
    ExternalLLM -->|response| ElabAPI
    ElabAPI -->|return result| FastAPI

    FastAPI -->|store summary| QS
    FastAPI -->|update| Sum
    FastAPI -->|render response| Templates
    Templates -->|HTML| Browser

    Playground -->|test| ElabAPI
    Playground -->|test| ElabVec

    %% Click Events
    click Static "https://github.com/ritareasciencepark/fastapi-llm/tree/main/static/"
    click Templates "https://github.com/ritareasciencepark/fastapi-llm/tree/main/templates/"
    click FastAPI "https://github.com/ritareasciencepark/fastapi-llm/blob/main/main.py"
    click ElabAPI "https://github.com/ritareasciencepark/fastapi-llm/blob/main/elab_api.py"
    click ElabVec "https://github.com/ritareasciencepark/fastapi-llm/blob/main/elab_vector.py"
    click QS "https://github.com/ritareasciencepark/fastapi-llm/blob/main/query_summary.json"
    click Sum "https://github.com/ritareasciencepark/fastapi-llm/blob/main/summaries.json"
    click Playground "https://github.com/ritareasciencepark/fastapi-llm/blob/main/playground.py"
    click README "https://github.com/ritareasciencepark/fastapi-llm/blob/main/README.md"

    %% Styles
    classDef frontend fill:#e0f7fa,stroke:#006064,stroke-width:2px
    classDef backend fill:#e8f5e9,stroke:#1b5e20,stroke-width:2px
    classDef storage fill:#fff3e0,stroke:#e65100,stroke-width:2px,stroke-dasharray: 5 5
    classDef external fill:#fff9c4,stroke:#f57f17,stroke-width:2px
    classDef docs fill:#f3e5f5,stroke:#6a1b9a,stroke-width:2px
```
