# fufankeji/mategen architecture

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

- Interactive diagram: https://gitdiagram.com/fufankeji/mategen
- Repository: https://github.com/fufankeji/mategen

## Overview

##### Project Type and Purpose
- MateGen is a Python SDK library (installed via pip) that provides an interactive, Jupyter‐friendly programming assistant.
- It exposes a client API (the MateGen Python package) that bridges:
- Remote Large Model Services (online LLM APIs)
- Local resources (Python interpreter, documents, databases, image hosts)
- Retrieval‐Augmented Generation (RAG) system for local knowledge Q&A
- Multi‐Function and Parallel Function calling orchestrator

##### File Structure Analysis
- setup.py, MANIFEST.in: Packaging and distribution (PyPI)
- Dockerfile, docker-compose.yml: Containerized deployment of the client or demo server
- docs/: User tutorials (Jupyter notebooks)
- README.md / README_zh.md: Project description, architecture, usage

##### Key Architectural Insights from README
- Client‐Server Separation: The MateGen client (Python package) interacts with a remote service layer hosting large models.
- Threads‐Runs Architecture: On the server/agent side, message histories and multi‐function calls are managed via thread/run constructs.
- RAG System: Local document ingestion + retrieval + QA pipeline.
- Code Interpreter: Connects to the user’s local Python environment for code execution, visualization, SQL execution.
- Multi‐Function Orchestration: One request can spawn multiple function calls (e.g., RAG + NL2SQL + code execution) in parallel or sequence.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Project Files"
        spkg["setup.py"]:::file
        manifest["MANIFEST.in"]:::file
        dockerfile["Dockerfile"]:::file
        compose["docker-compose.yml"]:::file
        tutorials["docs/MateGen使用教程.ipynb"]:::file
        readme["README.md"]:::file
        readme_zh["README_zh.md"]:::file
    end

    subgraph "Client Side" 
        direction TB
        MateGenSDK["MateGen SDK"]:::client
        CodeInterpreter["Local Code Interpreter"]:::client
        RAGRetriever["RAG Retriever"]:::client
        LocalResources["Local Resources\n(File System, MySQL, Image Hosting)"]:::client
    end

    subgraph "Remote Side"
        direction TB
        APIGateway["API Gateway / Authentication"]:::server
        Orchestrator["Agent Orchestrator\n(Intent Parser, Dispatcher)"]:::server
        FunctionExecutors["Function Executors\n(LLM calls, RAG search,\nNL2SQL, Visualization)"]:::server
        LLMProviders["LLM Providers\n(OpenAI, Internal)"]:::external
    end

    subgraph "External Services"
        direction TB
        ImageHost["Cloud Image Hosting"]:::external
        SearchEngine["Search Engine"]:::external
        QABase["Q&A Knowledge Bases"]:::external
    end

    subgraph "Data Stores"
        direction TB
        VectorStore["Vector Database (FAISS)"]:::datastore
        Documents["Document Store"]:::datastore
        MySQLDB["MySQL"]:::datastore
    end

    %% Connections
    MateGenSDK -->|"API_CALL with API-KEY"| APIGateway
    APIGateway -->|"auth & route"| Orchestrator
    Orchestrator -->|"query docs"| RAGRetriever
    RAGRetriever -->|"search"| VectorStore
    Orchestrator -->|"code snippet"| CodeInterpreter
    Orchestrator -->|"generate SQL"| MySQLDB
    CodeInterpreter -->|"upload plot"| ImageHost
    Orchestrator -->|"LLM request"| LLMProviders
    Orchestrator -->|"dispatch tasks"| FunctionExecutors
    FunctionExecutors -->|"parallel/seq results"| Orchestrator
    Orchestrator -->|"response"| MateGenSDK

    %% Click Events
    click spkg "https://github.com/fufankeji/mategen/blob/main/setup.py"
    click manifest "https://github.com/fufankeji/mategen/blob/main/MANIFEST.in"
    click dockerfile "https://github.com/fufankeji/mategen/tree/main/Dockerfile"
    click compose "https://github.com/fufankeji/mategen/blob/main/docker-compose.yml"
    click tutorials "https://github.com/fufankeji/mategen/blob/main/docs/MateGen使用教程.ipynb"
    click readme "https://github.com/fufankeji/mategen/blob/main/README.md"
    click readme_zh "https://github.com/fufankeji/mategen/blob/main/README_zh.md"

    %% Styles
    classDef client fill:#D0E8FF,stroke:#0366d6
    classDef server fill:#D6F9D6,stroke:#228B22
    classDef external fill:#FFE0B2,stroke:#FF8C00
    classDef datastore fill:#FFFBCC,stroke:#B8860B
    classDef file fill:#F0F0F0,stroke:#666,stroke-dasharray: 2 2,font-style:italic
```
