# microsoft/genaiscript architecture

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

- Interactive diagram: https://gitdiagram.com/microsoft/genaiscript
- Repository: https://github.com/microsoft/genaiscript

## Overview

##### Main Components

a) Core Components:
- LLM Integration Layer
- Script Runtime Engine
- File System Interface
- Tool/Agent System
- Schema Validation System
- Content Safety System

b) Extension Components:
- VS Code Extension
- CLI Interface
- API Layer
- Web Interface

c) External Integrations:
- LLM Providers (OpenAI, Anthropic, GitHub, etc.)
- Container Runtime (Docker)
- Vector Search
- Content Safety Services

##### Component Relationships

**[VS Code Extension] ─┐**
**[CLI Interface]    ─┤**
**[Web Interface]    ─┤**
**[API Layer]        ─┴─→ [Core Runtime] ←→ [File System Interface]**

- → [LLM Integration Layer] ←→ [External LLM Providers]

- → [Tool/Agent System] ←→ [Container Runtime]

- → [Schema Validation]

- → [Content Safety System] ←→ [Safety Services]

##### Component Details

Core Runtime:
- Script execution engine
- Prompt template processing
- File handling and workspace management
- Tool/agent orchestration

LLM Integration Layer:
- Model management
- Provider abstraction
- Response processing
- Token management

Tool/Agent System:
- Tool registration and execution
- Agent lifecycle management
- Container orchestration
- Python code interpreter

##### Data Flow Indicators

- Script/command flow from interfaces to runtime
- Data flow between runtime and file system
- Prompt/response flow with LLM providers
- Tool execution flow with containers
- Safety validation flow

##### Additional Elements

Visual indicators for:
- File formats supported (PDF, DOCX, CSV, etc.)
- Security boundaries
- Caching mechanisms
- Testing/evaluation components

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Interfaces
        VSCode["VS Code Extension"]
        CLI["CLI Interface"]
        Web["Web Interface"]
        API["API Layer"]
    end

    subgraph CoreRuntime["Core Runtime"]
        Runtime["Script Runtime Engine"]
        FileSystem["File System Interface"]
        Tools["Tool/Agent System"]
        Schema["Schema Validation"]
        Safety["Content Safety System"]
    end

    subgraph LLMLayer["LLM Integration Layer"]
        OpenAI["OpenAI Integration"]
        Anthropic["Anthropic Integration"]
        Groq["Groq Integration"]
        Ollama["Ollama Integration"]
    end

    subgraph External["External Services"]
        LLMProviders["LLM Providers"]
        Docker["Container Runtime"]
        SafetyServices["Safety Services"]
    end

    %% Interface connections
    VSCode --> Runtime
    CLI --> Runtime
    Web --> Runtime
    API --> Runtime

    %% Core runtime connections
    Runtime --> FileSystem
    Runtime --> Tools
    Runtime --> Schema
    Runtime --> Safety
    Runtime --> LLMLayer

    %% LLM Layer connections
    LLMLayer --> LLMProviders
    Tools --> Docker
    Safety --> SafetyServices

    %% Styling
    classDef interface fill:#90EE90
    classDef core fill:#87CEEB
    classDef llm fill:#FFB6C6
    classDef external fill:#FFD700
    classDef security fill:#FFA500

    class VSCode,CLI,Web,API interface
    class Runtime,FileSystem,Tools core
    class OpenAI,Anthropic,Groq,Ollama llm
    class LLMProviders,Docker,SafetyServices external
    class Schema,Safety security

    %% Click events
    click VSCode "https://github.com/microsoft/genaiscript/tree/main/packages/vscode/"
    click CLI "https://github.com/microsoft/genaiscript/tree/main/packages/cli/"
    click Web "https://github.com/microsoft/genaiscript/tree/main/packages/web/"
    click API "https://github.com/microsoft/genaiscript/blob/main/packages/core/src/api.ts"
    click Runtime "https://github.com/microsoft/genaiscript/blob/main/packages/core/src/runtime.ts"
    click FileSystem "https://github.com/microsoft/genaiscript/blob/main/packages/core/src/filesystem.ts"
    click Tools "https://github.com/microsoft/genaiscript/blob/main/packages/core/src/tools.ts"
    click Schema "https://github.com/microsoft/genaiscript/blob/main/packages/core/src/schema.ts"
    click Safety "https://github.com/microsoft/genaiscript/blob/main/packages/core/src/azurecontentsafety.ts"
    click OpenAI "https://github.com/microsoft/genaiscript/blob/main/packages/core/src/openai.ts"
    click Anthropic "https://github.com/microsoft/genaiscript/blob/main/packages/core/src/anthropic.ts"
    click Groq "https://github.com/microsoft/genaiscript/blob/main/packages/core/src/groq.ts"
    click Ollama "https://github.com/microsoft/genaiscript/blob/main/packages/core/src/ollama.ts"
```
