# zongqianli/reasongraph architecture

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

- Interactive diagram: https://gitdiagram.com/zongqianli/reasongraph
- Repository: https://github.com/zongqianli/reasongraph

## Overview

##### Project Type and Purpose
- Type: Web-based visualization platform.
- Purpose: To provide a visual representation of different reasoning approaches used by LLMs (e.g., Chain-of-Thought, Self-refine, Least-to-most, Beam Search, Tree of Thoughts, etc.). It also allows users to handle extended, long-form reasoning outputs.
- Key features include the integration of over 50 state-of-the-art LLMs, multi-language support (English and Chinese), modular reasoning methods, and an intuitive web interface.

##### Analyzing the File Structure
- At the root we have the README files, a directory called “ReasonGraph” which contains all source code, and a “figures” directory for UI screenshots and examples.
- Inside the “ReasonGraph” directory:
- app.py – the main Flask entry point to run the web application.
- api_base.py and api_keys.json – files that handle communication with various LLM APIs, including key management.
- Multiple reasoning modules – files such as bs_reasoning.py, cot_reasoning.py, l2m_reasoning.py, plain_text_reasoning.py, selfconsistency_reasoning.py, selfrefine_reasoning.py, tot_reasoning.py. These likely encapsulate different algorithms or approaches for handling and visualizing reasoning paths.
- configs.py – configuration settings, likely defining global parameters and model settings.
- static/ (with assets) and templates/ (HTML files for the UI) – which suggest an MVC-like separation: templates for view rendering and the app’s core logic in the Python files.

##### Key Components & Their Relationships
a. Client Side (Frontend/UI):
- Browser interface rendered using HTML templates (index.html and index_cn.html) and static assets (images, CSS, JavaScript).
- Users interact with the visualization interface, select reasoning models, and input API keys.

b. Web Server (Backend):
- The Flask application (app.py) acts as the server entry point, handling HTTP requests and routing.
- It renders the UI templates and coordinates user commands with back-end logic.

c. Reasoning Calculation Module:
- Multiple reasoning method scripts (such as cot_reasoning.py, tot_reasoning.py, bs_reasoning.py, etc.) are integrated.
- These modules encapsulate different reasoning algorithms and processing flows to transform raw text into structured reasoning paths.

d. API Connectivity Layer:
- The api_base.py and api_keys.json files serve to abstract API calls to external LLM providers (OpenAI, Anthropic, Google, Together, etc.).
- They ensure secure management of API keys and provide standardized interfaces for different models and providers.

e. Configuration and Dependency Management:
- The configs.py file centralizes configuration variables that are shared across the reasoning modules and server logic.
- The environment dependencies (Flask, requests, openai, together, etc.) highlight the interactions with external services.

##### Architectural Patterns and Design Principles
- Separation of concerns: Dividing the system into a clear UI layer (templates/static), server logic (app.py), API communications (api_base.py), and individual reasoning modules.
- Modularity: Each reasoning method is implemented as a separate module, making it simpler to add or extend reasoning approaches.
- Extensibility: Standardized APIs and configurations facilitate easy integration of new models or reasoning algorithms.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Side (Frontend/UI)
    subgraph "Client Side (Frontend/UI)"
        TS["Templates (HTML)"]:::frontend
        SA["Static Assets"]:::frontend
        B["Browser UI"]:::frontend
        TS -->|"loads_into"| B
        SA -->|"supports"| B
    end

    %% Web Server (Backend)
    subgraph "Web Server (Backend)"
        FS["Flask Web Server"]:::backend
        CFG["Configuration"]:::backend
        CFG ---|"provides_settings"| FS
    end

    %% Reasoning Modules
    subgraph "Reasoning Modules"
        RC["Chain-of-Thought"]:::module
        RS["Beam Search"]:::module
        RL["Least-to-Most"]:::module
        RP["Plain Text Reasoning"]:::module
        SC["Self-Consistency"]:::module
        SR["Self-Refine"]:::module
        RT["Tree of Thoughts"]:::module
    end

    %% API Connectivity Layer
    subgraph "API Connectivity Layer"
        APB["API Base"]:::api
        APK["API Keys"]:::api
        APB ---|"uses_keys"| APK
    end

    %% External LLM Providers
    EXT["External LLM Providers"]:::external

    %% Data Flow Connections
    B -->|"HTTP_Request"| FS
    FS -->|"selects_reasoning"| RC
    FS -->|"selects_reasoning"| RS
    FS -->|"selects_reasoning"| RL
    FS -->|"selects_reasoning"| RP
    FS -->|"selects_reasoning"| SC
    FS -->|"selects_reasoning"| SR
    FS -->|"selects_reasoning"| RT

    RC -->|"api_request"| APB
    RS -->|"api_request"| APB
    RL -->|"api_request"| APB
    RP -->|"api_request"| APB
    SC -->|"api_request"| APB
    SR -->|"api_request"| APB
    RT -->|"api_request"| APB

    APB -->|"calls"| EXT
    EXT -->|"returns_result"| APB

    APB -->|"response"| RC
    APB -->|"response"| RS
    APB -->|"response"| RL
    APB -->|"response"| RP
    APB -->|"response"| SC
    APB -->|"response"| SR
    APB -->|"response"| RT

    RC -->|"processed_result"| FS
    RS -->|"processed_result"| FS
    RL -->|"processed_result"| FS
    RP -->|"processed_result"| FS
    SC -->|"processed_result"| FS
    SR -->|"processed_result"| FS
    RT -->|"processed_result"| FS

    FS -->|"renders_chart"| B

    %% Click Events
    click TS "https://github.com/zongqianli/reasongraph/tree/main/ReasonGraph/templates"
    click SA "https://github.com/zongqianli/reasongraph/tree/main/ReasonGraph/static/assets"
    click FS "https://github.com/zongqianli/reasongraph/blob/main/ReasonGraph/app.py"
    click CFG "https://github.com/zongqianli/reasongraph/blob/main/ReasonGraph/configs.py"
    click RC "https://github.com/zongqianli/reasongraph/blob/main/ReasonGraph/cot_reasoning.py"
    click RS "https://github.com/zongqianli/reasongraph/blob/main/ReasonGraph/bs_reasoning.py"
    click RL "https://github.com/zongqianli/reasongraph/blob/main/ReasonGraph/l2m_reasoning.py"
    click RP "https://github.com/zongqianli/reasongraph/blob/main/ReasonGraph/plain_text_reasoning.py"
    click SC "https://github.com/zongqianli/reasongraph/blob/main/ReasonGraph/selfconsistency_reasoning.py"
    click SR "https://github.com/zongqianli/reasongraph/blob/main/ReasonGraph/selfrefine_reasoning.py"
    click RT "https://github.com/zongqianli/reasongraph/blob/main/ReasonGraph/tot_reasoning.py"
    click APB "https://github.com/zongqianli/reasongraph/blob/main/ReasonGraph/api_base.py"
    click APK "https://github.com/zongqianli/reasongraph/blob/main/ReasonGraph/api_keys.json"

    %% Styles
    classDef frontend fill:#a6cee3,stroke:#1f78b4,stroke-width:2px;
    classDef backend fill:#b2df8a,stroke:#33a02c,stroke-width:2px;
    classDef module fill:#fdbf6f,stroke:#ff7f00,stroke-width:2px;
    classDef api fill:#fb9a99,stroke:#e31a1c,stroke-width:2px;
    classDef external fill:#cab2d6,stroke:#6a3d9a,stroke-width:2px;
```
