# qtencent7/savor architecture

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

- Interactive diagram: https://gitdiagram.com/qtencent7/savor
- Repository: https://github.com/qtencent7/savor

## Overview

##### Project Type & Purpose
- This is a full-stack application split between a React/TypeScript frontend and a Python backend powered by FastAPI.
- The purpose is to allow users to input a news topic, then run AI-driven query optimization to use search engines (DuckDuckGo or Google) to fetch and analyze news results.

##### File Structure
- The project is clearly separated into two main directories:
- Frontend: Contains React code (with subdirectories for assets, components, styles, and API requests) and configuration files (e.g., tsconfig, vite.config).
- Backend: Contains a simple FastAPI application (app.py), with dependency management using requirements.txt and environment variable configuration.
- Notice additional files for managing environmental settings for proper integration with external APIs (OpenAI, DeepSeek, SERPAPI, etc).

##### Core Components to Highlight
a. Frontend Component
- React application that handles user interaction.
- Submodules like UI Components (e.g., Chat.tsx), API request handling (under src/requests), and styling layers (Less files in src/styles).
- Entry point (main.tsx) and overall state flow managing user input and display.

b. Backend Component
- FastAPI application (app.py) that processes requests from the frontend.
- Endpoints responsible for handling search queries, integrating with the DuckDuckGo/Google APIs, and processing the AI responses.
- Dependency management and configuration details (using .env for API keys and search engine selection).

c. External Services
- DuckDuckGo and Google (for search functionality)
- OpenAI API (for AI-driven query optimization and analysis)
- DeepSeek/SERPAPI (as part of the search process)
- As external components that interact with the backend.

d. Data Flow & Interactions
- The frontend sends the user search input to the backend.
- The backend then communicates with external search engines and the AI services.
- Processed search results return to the backend and then are forwarded to the frontend for display.
- Optionally, future planned components like chat history might be added, so leave room for those extensions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Layer
    U["User Input"]:::user

    %% Frontend Layer
    subgraph "React Frontend"
        FE1["Main (Entry Point)"]:::frontend
        FE2["Chat UI Component"]:::frontend
        FE3["API Request Handling"]:::frontend
        FE4["Styling & Assets"]:::frontend
    end

    %% Backend Layer
    subgraph "Python FastAPI Backend"
        BE1["FastAPI Application"]:::backend
        BE2["Dependency (requirements.txt)"]:::backend
        BE3["Env Configuration (.env)"]:::backend
    end

    %% External Services
    EX1["Search Engines (DuckDuckGo/Google)"]:::external
    EX2["AI APIs (OpenAI,DeepSeek/SERPAPI)"]:::external

    %% Data Flow Connections
    U -->|"submitsQuery"| FE1
    FE1 -->|"APICall"| BE1
    FE3 ---|"handlesAsyncCalls"| BE1
    BE1 -->|"querySearch"| EX1
    BE1 -->|"queryAI"| EX2
    EX1 -->|"returnResults"| BE1
    EX2 -->|"returnAnalyses"| BE1
    BE1 -->|"sendResponse"| FE1

    %% Click Events
    click FE1 "https://github.com/qtencent7/savor/blob/main/frontend/src/main.tsx"
    click FE2 "https://github.com/qtencent7/savor/blob/main/frontend/src/components/Chat.tsx"
    click FE3 "https://github.com/qtencent7/savor/tree/main/frontend/src/requests"
    click FE4 "https://github.com/qtencent7/savor/tree/main/frontend/src/styles"
    click BE1 "https://github.com/qtencent7/savor/blob/main/backend/app.py"
    click BE2 "https://github.com/qtencent7/savor/blob/main/backend/requirements.txt"
    click BE3 "https://github.com/qtencent7/savor/blob/main/backend/.env.example"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#0056b3,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef external fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef user fill:#fff3cd,stroke:#856404,stroke-width:2px;
```
