# chyhsu/vizthinker architecture

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

- Interactive diagram: https://gitdiagram.com/chyhsu/vizthinker
- Repository: https://github.com/chyhsu/vizthinker

## Overview

##### Project type and purpose
- VizThinker AI is a full-stack desktop application that replaces a linear chat interface with a node-based graph for LLM-driven conversations.
- The frontend is implemented in React/TypeScript (built with Vite), and the backend is a Python server that persists data in SQLite and proxies requests to external LLM providers (Google Generative AI, Ollama).

##### File structure
- Top-level:
- config/ – TypeScript and Vite build configs
- server/ – Python modules:
– main.py: entry point, starts HTTP server & handles requests
– route.py: defines REST endpoints for chat operations
– dao/sqlite.py: Data Access Object for persisting/restoring graphs
– llm.py: adapter layer for different LLM providers
– logger.py: centralized logging
– scheme/ – data models for chat nodes
- src/ – React frontend:
– asset/ – static images and graph templates
– constants/, typejs/ – global constants and TypeScript type declarations
– react/ – UI components (ChatLayout, ChatNode, HeaderBar, Settings, etc.) and context
– styles.css, index.css, main.tsx: entry point
- res/requirements.txt & pyproject.toml – Python dependencies
- package.json & tsconfig.json – Node.js dependencies and TS config
- Makefile – orchestrates install, build, run

##### README for additional insights
- Confirms node-based chat graph, LLM integration, persistent local sessions, desktop native packaging
- Describes major features: branching logic, dynamic graph canvas, settings modal, multi-provider support

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Desktop Wrapper
    Wrapper["Electron/Tauri Wrapper"]:::wrapper
    click Wrapper "https://github.com/chyhsu/vizthinker/tree/master/Makefile"

    %% UX Layer
    subgraph "UX Layer (React/Vite Frontend)"
        direction TB
        FE_Entry["main.tsx"]:::ui
        click FE_Entry "https://github.com/chyhsu/vizthinker/blob/master/src/react/main.tsx"

        subgraph "UI Components"
            direction TB
            App["App.tsx"]:::ui
            click App "https://github.com/chyhsu/vizthinker/blob/master/src/react/App.tsx"
            BranchEdge["BranchEdge.tsx"]:::ui
            click BranchEdge "https://github.com/chyhsu/vizthinker/blob/master/src/react/BranchEdge.tsx"
            ChatLayout["ChatLayout.tsx"]:::ui
            click ChatLayout "https://github.com/chyhsu/vizthinker/blob/master/src/react/ChatLayout.tsx"
            ChatNode["ChatNode.tsx"]:::ui
            click ChatNode "https://github.com/chyhsu/vizthinker/blob/master/src/react/ChatNode.tsx"
            ChatWindow["ChatWindow.tsx"]:::ui
            click ChatWindow "https://github.com/chyhsu/vizthinker/blob/master/src/react/ChatWindow.tsx"
            ExportModal["ExportModal.tsx"]:::ui
            click ExportModal "https://github.com/chyhsu/vizthinker/blob/master/src/react/ExportModal.tsx"
            ExtendedNode["ExtendedNode.tsx"]:::ui
            click ExtendedNode "https://github.com/chyhsu/vizthinker/blob/master/src/react/ExtendedNode.tsx"
            HeaderBar["HeaderBar.tsx"]:::ui
            click HeaderBar "https://github.com/chyhsu/vizthinker/blob/master/src/react/HeaderBar.tsx"
            Settings["Settings.tsx"]:::ui
            click Settings "https://github.com/chyhsu/vizthinker/blob/master/src/react/Settings.tsx"
            SettingsContext["SettingsContext.tsx"]:::ui
            click SettingsContext "https://github.com/chyhsu/vizthinker/blob/master/src/react/SettingsContext.tsx"
        end

        Styles["styles.css & index.css"]:::ui
        click Styles "https://github.com/chyhsu/vizthinker/blob/master/src/styles.css"
        click Styles "https://github.com/chyhsu/vizthinker/blob/master/src/index.css"

        Assets["asset/ (images, templates)"]:::ui
        click Assets "https://github.com/chyhsu/vizthinker/tree/master/src/asset/"

        Constants["constants & types"]:::ui
        click Constants "https://github.com/chyhsu/vizthinker/blob/master/src/constants/settingsConstants.ts"
        click Constants "https://github.com/chyhsu/vizthinker/tree/master/src/typejs/"

        Config_FE["vite.config.ts, tsconfig.json, package.json"]:::ui
        click Config_FE "https://github.com/chyhsu/vizthinker/blob/master/config/vite.config.ts"
        click Config_FE "https://github.com/chyhsu/vizthinker/blob/master/config/tsconfig.json"
        click Config_FE "https://github.com/chyhsu/vizthinker/blob/master/package.json"
    end

    %% API Layer
    subgraph "API Layer (Python Server)"
        direction TB
        ServerEntry["main.py"]:::backend
        click ServerEntry "https://github.com/chyhsu/vizthinker/blob/master/server/main.py"

        Routes["route.py"]:::backend
        click Routes "https://github.com/chyhsu/vizthinker/blob/master/server/route.py"

        Logger["logger.py"]:::backend
        click Logger "https://github.com/chyhsu/vizthinker/blob/master/server/logger.py"

        LLMAdapter["llm.py"]:::backend
        click LLMAdapter "https://github.com/chyhsu/vizthinker/blob/master/server/llm.py"

        DAO["sqlite.py"]:::persistence
        click DAO "https://github.com/chyhsu/vizthinker/blob/master/server/dao/sqlite.py"

        DataModel["chatNode.py"]:::backend
        click DataModel "https://github.com/chyhsu/vizthinker/blob/master/server/scheme/chatNode.py"

        Config_Py["pyproject.toml & requirements.txt"]:::backend
        click Config_Py "https://github.com/chyhsu/vizthinker/blob/master/pyproject.toml"
        click Config_Py "https://github.com/chyhsu/vizthinker/blob/master/res/requirements.txt"
    end

    %% Persistence Layer
    DB["SQLite Database"]:::persistence

    %% External Services
    subgraph "External LLM Services"
        direction TB
        Google["Google Generative AI"]:::external
        Ollama["Ollama"]:::external
    end

    %% Interactions
    Wrapper -->|launches| FE_Entry
    Wrapper -->|starts| ServerEntry

    FE_Entry -->|"POST /chat/node, GET /chat/session"| ServerEntry
    FE_Entry -->|uses| Routes

    Routes -->|reads/writes| DAO
    DAO -->|SQL queries| DB

    Routes -->|invokes| LLMAdapter
    LLMAdapter -->|gRPC/REST calls| Google
    LLMAdapter -->|REST calls| Ollama

    LLMAdapter -->|returns response| Routes
    Routes -->|response node| FE_Entry

    %% Logging
    ServerEntry -.->|logs events| Logger
    Routes -.->|logs requests| Logger
    DAO -.->|logs queries| Logger
    LLMAdapter -.->|logs calls| Logger

    %% Styles & Orchestration
    CLI["Makefile"]:::backend
    click CLI "https://github.com/chyhsu/vizthinker/tree/master/Makefile"
    CLI -->|build & run| FE_Entry
    CLI -->|build & run| ServerEntry

    %% Class Definitions
    classDef ui fill:#ccf,stroke:#333,stroke-width:1px
    classDef backend fill:#cfc,stroke:#333,stroke-width:1px
    classDef persistence fill:#fc9,stroke:#333,stroke-width:1px
    classDef external fill:#c9f,stroke:#333,stroke-width:1px
    classDef wrapper fill:#cff,stroke:#333,stroke-width:1px
```
