# cutc-mt/web_proxy architecture

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

- Interactive diagram: https://gitdiagram.com/cutc-mt/web_proxy
- Repository: https://github.com/cutc-mt/web_proxy

## Overview

##### Main Components
- Frontend/UI:
- Represented by main.py as the entry point and the pages directory (with modules like chat.py, settings.py, and simple_qa.py), which together form the interactive Streamlit web interface.
- Backend/Logic:
- Core Python processing contained within main.py and various modules in the utils directory—such as api_utils.py (for API calls), and helper utilities like enhance_prompt.py and kwmatch.py.
- Incorporate the chat_backends submodule, which integrates external chat services (like those referencing Azure OpenAI) through files azure_openai.py, azure_openai_legacy.py, and manager.py.
- Mock Server:
- Represented by mock_server.py, which is a FastAPI server acting as a simulated backend for handling or mimicking API interactions.
- Data Storage:
- Although not directly visible as a physical file, the README informs us that SQLite is used for persistent storage with supporting utility functions in db_utils.py.

##### Interactions and Relationships
- The front-end (Streamlit UI) interacts directly with the backend logic when a user submits a web request.
- The backend may rely on utility functions (in utils/) to prepare request data, enhance prompts, or perform keyword matching.
- When a request is made, the system may contact the mock server (via network calls) for simulated response processing.
- Data flow between the UI, backend logic, and database (SQLite) should be highlighted, showing how POST data is saved, retrieved, and exported.
- Integration points with external services (i.e., Azure OpenAI) via the chat_backends modules should also be depicted, representing how they extend core functionality.

##### Architectural Patterns and Design Principles
- Separation of concerns: Different directories (pages for UI, utils for business logic, and a separate file for the mock server) show clear module separation.
- Modular design: The usage of specialized modules for chat backends and database utilities allows for extensibility and easy maintenance.
- Proxy-based communication: Highlight that web requests are managed through a proxy setup with detailed configuration settings.
- The single entry point (main.py) for the Streamlit app and an isolated FastAPI service (in mock_server.py) indicate a loosely coupled architecture allowing independent development/testing of components.

##### Relevant Technologies and Frameworks
- Streamlit for the web interface.
- Python for backend processing.
- FastAPI used in the mock server.
- SQLite (accessed via db_utils.py) for data storage.
- Azure OpenAI integrations (as per the azure_openai modules) for possible chat functionality.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend/UI Cluster
    subgraph "Frontend/UI"
        UI_Main("main.py"):::ui
        UI_Chat("chat.py"):::ui
        UI_Settings("settings.py"):::ui
        UI_SimpleQA("simple_qa.py"):::ui
    end

    %% Backend/Logic Cluster
    subgraph "Backend/Logic"
        API_Utils("api_utils.py"):::backend
        Enhance_Prompt("enhance_prompt.py"):::backend
        KWMatch("kwmatch.py"):::backend
    end

    %% Chat Backends Cluster
    subgraph "Chat Backends"
        Azure_OpenAI("azure_openai.py"):::chat
        Azure_OpenAI_Legacy("azure_openai_legacy.py"):::chat
        Chat_Manager("manager.py"):::chat
    end

    %% External Components
    Mock_Server("mock_server.py"):::mockServer
    SQLite_DB("SQLite (db_utils.py)"):::database

    %% Connections
    UI_Main -->|"submit_request"| API_Utils
    UI_Main -->|"update_UI"| API_Utils
    API_Utils -->|"simulate_request"| Mock_Server
    API_Utils -->|"store_data"| SQLite_DB
    API_Utils -->|"chat_integration"| Azure_OpenAI
    API_Utils -->|"chat_integration"| Azure_OpenAI_Legacy
    API_Utils -->|"chat_integration"| Chat_Manager

    %% Styles
    classDef ui fill:#DDEEFF,stroke:#0000FF,stroke-width:2px;
    classDef backend fill:#CCFFCC,stroke:#008000,stroke-width:2px;
    classDef chat fill:#FFCCFF,stroke:#800080,stroke-width:2px;
    classDef mockServer fill:#F0F0F0,stroke:#808080,stroke-width:2px;
    classDef database fill:#FFF2CC,stroke:#D2691E,stroke-width:2px;

    %% Click Events
    click UI_Main "https://github.com/cutc-mt/web_proxy/blob/main/main.py"
    click UI_Chat "https://github.com/cutc-mt/web_proxy/blob/main/pages/chat.py"
    click UI_Settings "https://github.com/cutc-mt/web_proxy/blob/main/pages/settings.py"
    click UI_SimpleQA "https://github.com/cutc-mt/web_proxy/blob/main/pages/simple_qa.py"
    
    click API_Utils "https://github.com/cutc-mt/web_proxy/blob/main/utils/api_utils.py"
    click Enhance_Prompt "https://github.com/cutc-mt/web_proxy/blob/main/utils/enhance_prompt.py"
    click KWMatch "https://github.com/cutc-mt/web_proxy/blob/main/utils/kwmatch.py"
    
    click Azure_OpenAI "https://github.com/cutc-mt/web_proxy/blob/main/utils/chat_backends/azure_openai.py"
    click Azure_OpenAI_Legacy "https://github.com/cutc-mt/web_proxy/blob/main/utils/chat_backends/azure_openai_legacy.py"
    click Chat_Manager "https://github.com/cutc-mt/web_proxy/blob/main/utils/chat_backends/manager.py"
    
    click Mock_Server "https://github.com/cutc-mt/web_proxy/blob/main/mock_server.py"
    click SQLite_DB "https://github.com/cutc-mt/web_proxy/blob/main/utils/db_utils.py"
```
