# isec-ahu/llm4workflow architecture

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

- Interactive diagram: https://gitdiagram.com/isec-ahu/llm4workflow
- Repository: https://github.com/isec-ahu/llm4workflow

## Overview

##### Project type and purpose
- LLM4Workflow is a full-stack, LLM-driven web application that ingests a user’s natural-language workflow description, uses an LLM (OpenAI) and a vector store to generate and refine a workflow model, stores/retrieves API knowledge in Postgres, then emits an executable workflow in XML for deployment (e.g., on EdgeWorkflow).

##### File structure
- Top-level “backend” directory: Python LangChain service with
- server.py (FastAPI or LangChain serve entry point)
- db.py (Postgres interactions)
- vectorStore.py (embeddings storage/retrieval)
- create_game.py, rag.py, json_loader.py, write_xml.py, write_dag.py (pipeline stages)
- schema.py (Pydantic/OpenAPI schemas), utils.py
- init.sql, api.json (metadata)
- Docker-Compose for Postgres
- Top-level “frontend” directory: React + Vite + TypeScript app
- API layer under src/api
- Hooks under src/hooks
- Views/components under src/view
- Assets, styles, renderer utilities
- Tailwind config, ESLint, tsconfig, Vite config

##### README for additional insights
- Four main backend stages:
1) One-time API Knowledge Base Preparation
2) Task Extraction & Rewriting
3) API Retrieval
4) Workflow Model Generation (XML output)
- External dependencies/services:
- OpenAI API (LLM)
- Optional LangSmith tracing
- EdgeWorkflow (runtime evaluation platform)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend" 
        direction TB
        User["User / Browser"]:::frontend
        subgraph "Frontend Application" 
            direction TB
            FE_App["App.tsx"]:::frontend
            subgraph "API Layer"
                direction TB
                API_Service["apiService.ts"]:::frontend
                API_Def["api.ts"]:::frontend
                API_Schema["schema.ts"]:::frontend
            end
            Hooks["useChatLog.ts"]:::frontend
            Views["Views & Components"]:::frontend
            subgraph "Utilities & Styles"
                direction TB
                Utils_Renderer["renderer.ts"]:::frontend
                Utils_Constants["constants.ts"]:::frontend
                GlobalsCSS["globals.css"]:::frontend
                IndexCSS["index.css"]:::frontend
                TailwindConfig["tailwind.config.ts"]:::frontend
                ViteConfig["vite.config.ts"]:::frontend
                TSConfig["tsconfig.json"]:::frontend
            end
        end
    end

    %% Backend Layer
    subgraph "Backend Service" 
        direction TB
        Server["server.py"]:::backend
        API_Metadata["api.json"]:::backend
        subgraph "Pipeline Modules"
            direction TB
            Loader["json_loader.py"]:::backend
            RAG["rag.py"]:::backend
            Chain["create_game.py"]:::backend
            CustomAPI["custom_api.py"]:::backend
            WriteDAG["write_dag.py"]:::backend
            WriteXML["write_xml.py"]:::backend
        end
        subgraph "Persistence & Config"
            direction TB
            DB_Module["db.py"]:::backend
            InitSQL["init.sql"]:::backend
            DockerCompose["docker-compose.yaml"]:::backend
            VectorModule["vectorStore.py"]:::backend
            SchemaDef["schema.py"]:::backend
            UtilsBackend["utils.py"]:::backend
            PyProject["pyproject.toml"]:::backend
            EnvFile[".env"]:::backend
        end
    end

    %% External & Data Stores
    subgraph "Data Stores & Services"
        direction TB
        Postgres["Postgres DB"]:::data
        Vector["Vector Store"]:::data
        OpenAI["OpenAI API"]:::external
        LangSmith["LangSmith Tracing"]:::external
        EdgeWF["EdgeWorkflow Runtime"]:::external
    end

    %% Connections
    User -->|inputs text| FE_App
    FE_App -->|POST /generate-workflow| Server

    Server -->|load metadata| Loader
    Loader -->|reads api.json| API_Metadata
    Loader -->|writes to| Postgres
    Server -->|retrieve embeddings| VectorModule
    VectorModule -->|embeddings lookup| Vector
    VectorModule -->|LLM call| OpenAI
    Server -->|RAG retrieval| RAG
    RAG -->|calls OpenAI| OpenAI
    Server -->|task chain| Chain
    Chain -->|LLM calls| OpenAI
    Chain -->|calls custom APIs| CustomAPI
    Server -->|generate model| WriteDAG
    Server -->|generate XML| WriteXML
    WriteDAG -->|DAG output| FE_App
    WriteXML -->|XML output| FE_App
    FE_App -->|export workflow| EdgeWF

    Server -.->|tracing| LangSmith

    DB_Module -->|connects to| Postgres
    InitSQL -->|initializes| Postgres
    DockerCompose -->|orchestrates| Postgres

    %% Click events
    click FE_App "https://github.com/isec-ahu/llm4workflow/blob/main/frontend/src/App.tsx"
    click API_Service "https://github.com/isec-ahu/llm4workflow/blob/main/frontend/src/api/apiService.ts"
    click API_Def "https://github.com/isec-ahu/llm4workflow/blob/main/frontend/src/api/api.ts"
    click API_Schema "https://github.com/isec-ahu/llm4workflow/blob/main/frontend/src/api/schema.ts"
    click Hooks "https://github.com/isec-ahu/llm4workflow/blob/main/frontend/src/hooks/useChatLog.ts"
    click Views "https://github.com/isec-ahu/llm4workflow/tree/main/frontend/src/view"
    click Utils_Renderer "https://github.com/isec-ahu/llm4workflow/blob/main/frontend/src/utils/renderer.ts"
    click Utils_Constants "https://github.com/isec-ahu/llm4workflow/blob/main/frontend/src/utils/constants.ts"
    click GlobalsCSS "https://github.com/isec-ahu/llm4workflow/blob/main/frontend/src/globals.css"
    click IndexCSS "https://github.com/isec-ahu/llm4workflow/blob/main/frontend/src/index.css"
    click TailwindConfig "https://github.com/isec-ahu/llm4workflow/blob/main/tailwind.config.ts"
    click ViteConfig "https://github.com/isec-ahu/llm4workflow/blob/main/vite.config.ts"
    click TSConfig "https://github.com/isec-ahu/llm4workflow/blob/main/tsconfig.json"
    click Server "https://github.com/isec-ahu/llm4workflow/blob/main/backend/app/server.py"
    click API_Metadata "https://github.com/isec-ahu/llm4workflow/blob/main/backend/app/api.json"
    click DB_Module "https://github.com/isec-ahu/llm4workflow/blob/main/backend/app/db.py"
    click InitSQL "https://github.com/isec-ahu/llm4workflow/blob/main/backend/app/init.sql"
    click DockerCompose "https://github.com/isec-ahu/llm4workflow/blob/main/backend/docker-compose.yaml"
    click VectorModule "https://github.com/isec-ahu/llm4workflow/blob/main/backend/app/vectorStore.py"
    click Loader "https://github.com/isec-ahu/llm4workflow/blob/main/backend/app/json_loader.py"
    click RAG "https://github.com/isec-ahu/llm4workflow/blob/main/backend/app/rag.py"
    click Chain "https://github.com/isec-ahu/llm4workflow/blob/main/backend/app/create_game.py"
    click CustomAPI "https://github.com/isec-ahu/llm4workflow/blob/main/backend/app/custom_api.py"
    click WriteDAG "https://github.com/isec-ahu/llm4workflow/blob/main/backend/app/write_dag.py"
    click WriteXML "https://github.com/isec-ahu/llm4workflow/blob/main/backend/app/write_xml.py"
    click SchemaDef "https://github.com/isec-ahu/llm4workflow/blob/main/backend/app/schema.py"
    click UtilsBackend "https://github.com/isec-ahu/llm4workflow/blob/main/backend/app/utils.py"
    click PyProject "https://github.com/isec-ahu/llm4workflow/blob/main/backend/pyproject.toml"
    click EnvFile "https://github.com/isec-ahu/llm4workflow/blob/main/backend/.env"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px
    classDef external fill:#FFA500,stroke:#000,stroke-width:1px
    classDef data fill:#D3D3D3,stroke:#000,stroke-width:1px
```
