# dotnet/ai-samples architecture

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

- Interactive diagram: https://gitdiagram.com/dotnet/ai-samples
- Repository: https://github.com/dotnet/ai-samples

## Overview

##### Project Type and Purpose
- This is a “monorepo” of .NET AI samples, not a single running application. It illustrates:
- Core AI abstractions via Microsoft.Extensions.AI
- Provider implementations (Azure OpenAI, OpenAI, Azure AI Inference, Ollama, local LLM)
- Evaluation tooling (Microsoft.Extensions.AI.Evaluation / llm-eval)
- Guided quickstarts and tutorials (semantic-kernel, Azure SDK, OpenAI SDK)
- A standalone chat sample for customer support
- Its goal is educational: show developers how to integrate and evaluate AI services in .NET.

##### File Structure Analysis
- Top-level “src” contains first-class folders:
- azure-openai-sdk
- build-2024 (Semantic Kernel tutorials)
- chat (CustomerSupport app)
- llm-eval (evaluation core/data/outputs/tests + QACreator/UserStoryCreator)
- local-models (phi3-llama3 local inference)
- microsoft-extensions-ai (abstractions + provider examples + WebAPIs)
- quickstarts (Azure-openai and OpenAI samples + infra Bicep definitions)
- Each folder is a .NET solution or independent csproj; patterns: sample → Program.cs, README.md.
- Configuration files: Bicep and Azure YAML under quickstarts/infra, devcontainer configs, solution files.

##### Key Architectural Insights from README
- Microsoft.Extensions.AI: core abstractions (chat, embeddings)
- Provider implementations: allow substituting any AI backend
- Evaluation libraries build on top of abstractions
- Tutorials layer demonstrations on top of both abstractions and providers
- Quickstarts include IaC (Bicep) to provision Azure resources

a. Main Components
1. Core Abstraction Layer
– Microsoft.Extensions.AI (abstractions)
2. Provider Implementations
– Azure OpenAI SDK
– OpenAI SDK
– Azure AI Inference
– Ollama
– local-models
3. Evaluation Layer
– Microsoft.Extensions.AI.Evaluation / llm-eval (core, data, outputs, tests)
4. Sample / Tutorial Apps
– Quickstarts (Azure-openai & OpenAI)
– Build-2024 (Semantic Kernel tutorials)
– Chat: CustomerSupport
5. Infrastructure IaC
– Bicep scripts & YAML in quickstarts/infra
6. Dev Environments
– devcontainer definitions (cpu/gpu/ollama variants)
b. Relationships & Data Flow
- Sample Apps → consume → Core Abstractions → call → Provider Implementations → contact → LLM APIs or local runtime
- Evaluation Layer → consumes → Model Outputs → produces → Metrics/Reports
- Quickstarts/Infra IaC → provisions → Azure AI Services → used by Azure-provider samples
- Devcontainer → provides reproducible environment for all samples
c. Architectural Patterns & Principles
- Layered architecture: Abstraction → Implementation → Application
- Inversion of Control / Dependency Injection: swap providers at runtime
- Componentization: each sample is standalone, reusing core libraries
- Monorepo organization for samples by category
d. Relevant Technologies
- .NET 8, C#
- Microsoft.Extensions.AI abstractions
- Azure OpenAI, OpenAI REST SDKs
- Semantic Kernel (build-2024)
- Bicep / Azure Resource Manager (quickstarts/infra)
- Docker / DevContainers

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Core Abstraction Layer"
        A1["Microsoft.Extensions.AI"]:::core
    end

    subgraph "Provider Implementations"
        A2["Azure OpenAI Provider"]:::provider
        A3["OpenAI Provider"]:::provider
        A4["Azure AI Inference Provider"]:::provider
        A5["Ollama Provider"]:::provider
        A6["Local LLM Runtime"]:::provider
    end

    subgraph "Evaluation Layer"
        E1["LLMEval.Core"]:::eval
        E2["LLMEval.Data"]:::eval
        E3["LLMEval.Outputs"]:::eval
        E4["LLMEval.Test"]:::eval
        E5["QACreator Tool"]:::eval
        E6["UserStoryCreator Tool"]:::eval
        E7["QAGenerator Skill"]:::eval
        E8["UserStoryGenerator Skill"]:::eval
        E9["Extensions.AI.Evaluation API Examples"]:::eval
    end

    subgraph "Sample Apps / Tutorials"
        S1["Semantic Kernel Tutorials"]:::sample
        S2["Quickstarts - Extensions.AI (Azure)"]:::sample
        S3["Quickstarts - Extensions.AI (OpenAI)"]:::sample
        S4["Quickstarts - Semantic Kernel (Azure)"]:::sample
        S5["Quickstarts - Semantic Kernel (OpenAI)"]:::sample
        S6["Customer Support Chat"]:::sample
    end

    subgraph "Infrastructure / IaC"
        Infra["Quickstart IaC (Bicep/YAML)"]:::infra
    end

    subgraph "Dev Environments"
        Dev["DevContainer Definitions"]:::infra
    end

    %% Data Flows
    S1 -->|uses| A1
    S2 -->|uses| A1
    S3 -->|uses| A1
    S4 -->|uses| A1
    S5 -->|uses| A1
    S6 -->|uses| A1

    A1 -->|calls| A2
    A1 -->|calls| A3
    A1 -->|calls| A4
    A1 -->|calls| A5
    A1 -->|calls| A6

    A1 -->|evaluates| E1
    E1 -->|models| E2
    E2 -->|reports| E3
    E3 -->|tests| E4
    E1 -->|creates QA| E5
    E1 -->|creates Stories| E6
    E1 -->|skill QA| E7
    E1 -->|skill Stories| E8
    E1 -->|examples| E9

    Infra -->|provisions| A2
    Infra -->|provisions| A4
    Infra -->|provisions| S2
    Infra -->|provisions| S4

    Dev -->|environments| S1
    Dev -->|environments| S2
    Dev -->|environments| S3
    Dev -->|environments| S4
    Dev -->|environments| S5
    Dev -->|environments| S6

    %% Click Events
    click A1 "https://github.com/dotnet/ai-samples/blob/main/src/microsoft-extensions-ai/README.md"
    click A2 "https://github.com/dotnet/ai-samples/tree/main/src/microsoft-extensions-ai/azure-openai"
    click A3 "https://github.com/dotnet/ai-samples/tree/main/src/microsoft-extensions-ai/openai"
    click A4 "https://github.com/dotnet/ai-samples/tree/main/src/microsoft-extensions-ai/azure-ai-inference"
    click A5 "https://github.com/dotnet/ai-samples/tree/main/src/microsoft-extensions-ai/ollama"
    click A6 "https://github.com/dotnet/ai-samples/tree/main/src/local-models/phi3-llama3"
    click E1 "https://github.com/dotnet/ai-samples/blob/main/src/llm-eval/LLMEval.Core"
    click E2 "https://github.com/dotnet/ai-samples/blob/main/src/llm-eval/LLMEval.Data"
    click E3 "https://github.com/dotnet/ai-samples/blob/main/src/llm-eval/LLMEval.Outputs"
    click E4 "https://github.com/dotnet/ai-samples/blob/main/src/llm-eval/LLMEval.Test"
    click E5 "https://github.com/dotnet/ai-samples/tree/main/src/llm-eval/QACreator"
    click E6 "https://github.com/dotnet/ai-samples/tree/main/src/llm-eval/UserStoryCreator"
    click E7 "https://github.com/dotnet/ai-samples/tree/main/src/llm-eval/QAGenerator"
    click E8 "https://github.com/dotnet/ai-samples/tree/main/src/llm-eval/UserStoryGenerator"
    click E9 "https://github.com/dotnet/ai-samples/tree/main/src/microsoft-extensions-ai-evaluation/api"
    click S1 "https://github.com/dotnet/ai-samples/tree/main/src/build-2024"
    click S2 "https://github.com/dotnet/ai-samples/tree/main/src/quickstarts/azure-openai/extensions-ai"
    click S3 "https://github.com/dotnet/ai-samples/tree/main/src/quickstarts/openai/extensions-ai"
    click S4 "https://github.com/dotnet/ai-samples/tree/main/src/quickstarts/azure-openai/semantic-kernel"
    click S5 "https://github.com/dotnet/ai-samples/tree/main/src/quickstarts/openai/semantic-kernel"
    click Infra "https://github.com/dotnet/ai-samples/tree/main/src/quickstarts/azure-openai/infra"
    click S6 "https://github.com/dotnet/ai-samples/tree/main/src/chat/CustomerSupport"
    click Dev "https://github.com/dotnet/ai-samples/blob/main/.devcontainer"

    %% Styles
    classDef core fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef provider fill:#90EE90,stroke:#000,stroke-width:1px
    classDef sample fill:#FFA500,stroke:#000,stroke-width:1px
    classDef eval fill:#DDA0DD,stroke:#000,stroke-width:1px
    classDef infra fill:#D3D3D3,stroke:#000,stroke-width:1px
```
