# txoka/openanswer architecture

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

- Interactive diagram: https://gitdiagram.com/txoka/openanswer
- Repository: https://github.com/txoka/openanswer

## Overview

##### Main Components Identification

a) Frontend Layer:
- React-based web application (indicated by the frontend structure)
- Tailwind CSS for styling
- Real-time streaming interface (planned feature)

b) Backend Layer:
- Python-based API server
- LLM (Language Model) integration
- Web research capabilities
- Rate limiting system

c) External Services:
- Redis (for rate limiting)
- LLM Service (likely an external API)
- Web Crawling Service

**Client Layer**

**Frontend Layer**

**Backend Layer**

**External Services Layer**

##### Component Relationships

a) Frontend ↔ Backend Interactions:
- API calls for web research
- Real-time streaming connections
- Rate limit status updates

b) Backend ↔ External Services:
- Redis rate limiting checks
- LLM API calls
- Web crawling operations

##### Specific Components

Frontend Components:
- Main React Application
- Theme System
- Real-time Stream Handler
- URL Metadata Display
- Rate Limit Message Handler

Backend Components:
- Main API Server
- Rate Limiter (with Redis Lua Scripts)
- LLM Operations Handler
- Web Research Module
- Prompt Management System
- URL Selection Service
- Data Extraction Service

External Services:
- Redis Instance
- LLM API Service
- Web Crawling Service

##### Important Flows to Highlight

a) Main Application Flow:
##### Results → Frontend Display

b) Rate Limiting Flow:

##### Additional Elements

A section showing:
- Configuration management
- Environment variables
- Docker container boundaries
- API endpoints

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef frontend fill:#3b82f6,color:white
    classDef backend fill:#22c55e,color:white
    classDef external fill:#eab308,color:white
    classDef ratelimit fill:#ef4444,color:white
    classDef llm fill:#a855f7,color:white
    classDef config fill:#64748b,color:white
    classDef prompt fill:#0d9488,color:white

    %% Frontend Layer
    subgraph Frontend
        App["React App"]:::frontend
        UI["UI Components"]:::frontend
        Tailwind["Tailwind CSS"]:::frontend
        Theme["Theme Switcher"]:::frontend
        RateUI["Rate Limit UI"]:::frontend
        
        App --> UI
        App --> Theme
        UI --> RateUI
        Tailwind -.-> UI
    end

    %% Backend Layer
    subgraph Backend
        FastAPI["FastAPI Server"]:::backend
        LLM["LLM Operations"]:::llm
        WebResearch["Web Research"]:::backend
        RateLimit["Rate Limiter"]:::ratelimit
        Config["Configuration"]:::config
        Utils["Utilities"]:::backend
        
        FastAPI --> LLM
        FastAPI --> WebResearch
        FastAPI --> RateLimit
        Config --> FastAPI
        Utils --> FastAPI
    end

    %% Prompt Management
    subgraph Prompts
        AnswerPrompt["Answer Prompts"]:::prompt
        ExtractionPrompt["Extraction Prompts"]:::prompt
        SearchPrompt["Search Term Prompts"]:::prompt
        URLPrompt["URL Selection Prompts"]:::prompt
        
        LLM --> AnswerPrompt
        LLM --> ExtractionPrompt
        LLM --> SearchPrompt
        LLM --> URLPrompt
    end

    %% External Services
    subgraph External
        Redis["Redis Cache"]:::external
        LLMService["LLM Service"]:::external
        WebServices["Web Services"]:::external
        
        RateLimit --> Redis
        LLM --> LLMService
        WebResearch --> WebServices
    end

    %% Main Flow
    UI --> FastAPI
    
    %% Click Events
    click App "https://github.com/Txoka/OpenAnswer/blob/main/frontend/src/App.js"
    click Tailwind "https://github.com/Txoka/OpenAnswer/blob/main/frontend/tailwind.config.js"
    click FastAPI "https://github.com/Txoka/OpenAnswer/blob/main/backend/main.py"
    click LLM "https://github.com/Txoka/OpenAnswer/blob/main/backend/llm_operations.py"
    click WebResearch "https://github.com/Txoka/OpenAnswer/blob/main/backend/web_research.py"
    click RateLimit "https://github.com/Txoka/OpenAnswer/blob/main/backend/rate_limiter.py"
    click Config "https://github.com/Txoka/OpenAnswer/blob/main/backend/config.py"
    click Utils "https://github.com/Txoka/OpenAnswer/blob/main/backend/utils.py"
    click AnswerPrompt "https://github.com/Txoka/OpenAnswer/blob/main/backend/prompts/answer.yaml"
    click ExtractionPrompt "https://github.com/Txoka/OpenAnswer/blob/main/backend/prompts/extraction.yaml"
    click SearchPrompt "https://github.com/Txoka/OpenAnswer/blob/main/backend/prompts/search_term.yaml"
    click URLPrompt "https://github.com/Txoka/OpenAnswer/blob/main/backend/prompts/url_selection.yaml"

    %% Legend
    subgraph Legend
        Frontend_L["Frontend"]:::frontend
        Backend_L["Backend"]:::backend
        External_L["External Services"]:::external
        RateLimit_L["Rate Limiting"]:::ratelimit
        LLM_L["LLM Operations"]:::llm
        Config_L["Configuration"]:::config
        Prompt_L["Prompts"]:::prompt
    end
```
