# tinestaric/evaluateaitoolkit architecture

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

- Interactive diagram: https://gitdiagram.com/tinestaric/evaluateaitoolkit
- Repository: https://github.com/tinestaric/evaluateaitoolkit

## Overview

##### Project type and purpose
- This is a set of Microsoft Dynamics 365 Business Central (BC) AL-based extensions:
- EvaluateAIToolkit: a toolkit that adds prompt testing, validation, schema extraction, and parallel execution of AI prompts within BC.
- SendEmailToCustomer: a sample AI feature extension that uses the toolkit to generate customer emails from posted sales invoices.
- SendEmailToCustomer-Test: a test harness showing how to plug SendEmailToCustomer into the Evaluate AI Framework for large-scale evaluation.
- Purpose: enable rapid prototyping and large-scale validation of AI prompts (e.g., OpenAI completions) inside Business Central, with full history and schema checks.

##### File structure
- Top-level apps under the solution:
- EvaluateAIToolkit/
- SendEmailToCustomer/
- SendEmailToCustomer-Test/
- In EvaluateAIToolkit:
- “PromptDialogs” & “PromptingTesting” & “ResultLog” folders → UI pages & tables for test setup and results.
- “GPTInteractions” → codeunits to build, execute, and validate prompts.
- “CompletionTesters” → pluggable schema testers (JSON, XML, none).
- “Helpers” → AOAIWrapper (the low-level HTTP client to OpenAI) and “Deployments” (implementations for various GPT models).
- “Plugin” & “Registration” → interfaces/enums and codeunits to register new AI features into the toolkit.
- In SendEmailToCustomer:
- “Implementation” → CustEmailGenerationImpl and GPTTokensCountImpl implementing IAIFeature interface.
- “PromptDialog” → pages and table extensions on Sales Invoice to trigger the feature.
- “Register” → registers the feature with the BC Copilot capability and toolkit.
- In SendEmailToCustomer-Test:
- Mirrors “Plugin” & “Test” codeunits to hook the sample feature into the toolkit for automated testing.

##### README for additional insights
- Confirms it’s not a web full-stack but a BC extension suite.
- Emphasizes capabilities: prompt validation, schema inference, alternate user prompts, parallel execution, history tracking.
- Mentions external dependency: OpenAI API (keys supplied at runtime via “Helpers/Deployments” or direct codeunit settings).

##### Be detailed—capture all essential layers
- Major folders as grouped components
- Data flow end-to-end: from “Run Prompt” page to “PromptTestResult” table
- Parallel execution flow (e.g., multiple sessions hitting the wrapper concurrently)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Business Central"
        subgraph "EvaluateAIToolkit"
            subgraph "UI Pages & Tables"
                PromptDialogs["PromptDialogs"]:::ui
                PromptingTesting["PromptingTesting"]:::ui
                ResultLog["ResultLog"]:::ui
            end
            subgraph "Core Logic"
                BCPT["BCPT"]:::logic
                GPTInteractions["GPTInteractions"]:::logic
            end
            subgraph "CompletionTesters"
                ISchemaTester["ISchemaTester.Interface.al"]:::logic
                SchemaTesters["SchemaTesters"]:::logic
                ValidationPromptCheck["ValidationPromptCheck.Codeunit.al"]:::logic
            end
            subgraph "Helpers & Deployments"
                AOAIWrapper["AOAIWrapper.Codeunit.al"]:::infra
                Deployments["Deployments"]:::infra
                IAOAIDeployment["IAOAIDeployment.Interface.al"]:::infra
            end
            subgraph "Plugin & Registration"
                IAIFeature["IAIFeature.Interface.al"]:::logic
                AIFeatureEnum["AIFeature.Enum.al"]:::logic
                AIFeatureNone["AIFeatureNone.Codeunit.al"]:::logic
                RegisterCapability["RegisterCapability.Codeunit.al"]:::logic
                CopilotEnumExt["CopilotCapabilityExtension.EnumExt.al"]:::logic
            end
        end
        subgraph "SendEmailToCustomer"
            subgraph "Implementation"
                CustEmailGen["CustEmailGenerationImpl.Codeunit.al"]:::logic
                TokenCount["GPTTokensCountImpl.Codeunit.al"]:::logic
            end
            subgraph "PromptDialog"
                CustomerEmailPage["CustomerEmailGeneration.Page.al"]:::ui
                GeneratedEmailTable["GeneratedEmail.Table.al"]:::ui
                SalesInvoiceCardExt["SalesInvoiceCardExt.PageExt.al"]:::ui
                SalesInvoiceListExt["SalesInvoiceListExt.PageExt.al"]:::ui
            end
            subgraph "Register"
                SEC_RegisterCapability["RegisterCapability.Codeunit.al"]:::logic
                SEC_CopilotEnumExt["CopilotCapabilityExtension.EnumExt.al"]:::logic
            end
        end
        subgraph "SendEmailToCustomer-Test"
            TestEnumExt["AIFeatureExtension.EnumExt.al"]:::logic
            EmailTestWrapper["EmailTestWrapper.Codeunit.al"]:::logic
        end
    end

    DB["BC SQL Database"]:::db
    OpenAI["OpenAI API"]:::external

    %% Data flows
    PromptDialogs -->|runs tests| BCPT
    PromptingTesting -->|triggers| BCPT
    BCPT -->|uses| SchemaTesters
    BCPT -->|executes| GPTInteractions
    GPTInteractions -->|calls| AOAIWrapper
    AOAIWrapper -->|requests| OpenAI
    BCPT -->|logs results to| DB
    DB -->|shown in| ResultLog

    %% Plugin pattern
    IAIFeature -->|implemented by| CustEmailGen
    IAIFeature -->|implemented by| TokenCount
    IAIFeature -->|discovered by| RegisterCapability
    RegisterCapability -->|registers| IAIFeatureNone
    SEC_RegisterCapability -->|registers| CustEmailGen
    SEC_RegisterCapability -->|registers| TokenCount
    EmailTestWrapper -->|wraps| CustEmailGen
    EmailTestWrapper -->|wraps| TokenCount

    %% Click events
    click PromptDialogs "https://github.com/tinestaric/evaluateaitoolkit/tree/Master/EvaluateAIToolkit/PromptDialogs/"
    click PromptingTesting "https://github.com/tinestaric/evaluateaitoolkit/tree/Master/EvaluateAIToolkit/PromptingTesting/"
    click ResultLog "https://github.com/tinestaric/evaluateaitoolkit/tree/Master/EvaluateAIToolkit/ResultLog/"
    click BCPT "https://github.com/tinestaric/evaluateaitoolkit/tree/Master/EvaluateAIToolkit/BCPT/"
    click GPTInteractions "https://github.com/tinestaric/evaluateaitoolkit/tree/Master/EvaluateAIToolkit/GPTInteractions/"
    click ISchemaTester "https://github.com/tinestaric/evaluateaitoolkit/blob/Master/EvaluateAIToolkit/CompletionTesters/ISchemaTester.Interface.al"
    click SchemaTesters "https://github.com/tinestaric/evaluateaitoolkit/tree/Master/EvaluateAIToolkit/CompletionTesters/SchemaTesters/"
    click ValidationPromptCheck "https://github.com/tinestaric/evaluateaitoolkit/blob/Master/EvaluateAIToolkit/CompletionTesters/ValidationPromptCheck.Codeunit.al"
    click AOAIWrapper "https://github.com/tinestaric/evaluateaitoolkit/blob/Master/EvaluateAIToolkit/Helpers/AOAIWrapper.Codeunit.al"
    click Deployments "https://github.com/tinestaric/evaluateaitoolkit/tree/Master/EvaluateAIToolkit/Helpers/Deployments/"
    click IAOAIDeployment "https://github.com/tinestaric/evaluateaitoolkit/blob/Master/EvaluateAIToolkit/Helpers/IAOAIDeployment.Interface.al"
    click IAIFeature "https://github.com/tinestaric/evaluateaitoolkit/blob/Master/EvaluateAIToolkit/Plugin/IAIFeature.Interface.al"
    click AIFeatureEnum "https://github.com/tinestaric/evaluateaitoolkit/blob/Master/EvaluateAIToolkit/Plugin/AIFeature.Enum.al"
    click AIFeatureNone "https://github.com/tinestaric/evaluateaitoolkit/blob/Master/EvaluateAIToolkit/Plugin/AIFeatureNone.Codeunit.al"
    click RegisterCapability "https://github.com/tinestaric/evaluateaitoolkit/blob/Master/EvaluateAIToolkit/Registration/RegisterCapability.Codeunit.al"
    click CopilotEnumExt "https://github.com/tinestaric/evaluateaitoolkit/blob/Master/EvaluateAIToolkit/Registration/CopilotCapabilityExtension.EnumExt.al"
    click CustEmailGen "https://github.com/tinestaric/evaluateaitoolkit/blob/Master/SendEmailToCustomer/Implementation/CustEmailGenerationImpl.Codeunit.al"
    click TokenCount "https://github.com/tinestaric/evaluateaitoolkit/blob/Master/SendEmailToCustomer/Implementation/GPTTokensCountImpl.Codeunit.al"
    click CustomerEmailPage "https://github.com/tinestaric/evaluateaitoolkit/blob/Master/SendEmailToCustomer/PromptDialog/CustomerEmailGeneration.Page.al"
    click GeneratedEmailTable "https://github.com/tinestaric/evaluateaitoolkit/blob/Master/SendEmailToCustomer/PromptDialog/GeneratedEmail.Table.al"
    click SalesInvoiceCardExt "https://github.com/tinestaric/evaluateaitoolkit/blob/Master/SendEmailToCustomer/PromptDialog/SalesInvoiceCardExt.PageExt.al"
    click SalesInvoiceListExt "https://github.com/tinestaric/evaluateaitoolkit/blob/Master/SendEmailToCustomer/PromptDialog/SalesInvoiceListExt.PageExt.al"
    click SEC_RegisterCapability "https://github.com/tinestaric/evaluateaitoolkit/blob/Master/SendEmailToCustomer/Register/RegisterCapability.Codeunit.al"
    click SEC_CopilotEnumExt "https://github.com/tinestaric/evaluateaitoolkit/blob/Master/SendEmailToCustomer/Register/CopilotCapabilityExtension.EnumExt.al"
    click TestEnumExt "https://github.com/tinestaric/evaluateaitoolkit/blob/Master/SendEmailToCustomer-Test/Test/AIFeatureExtension.EnumExt.al"
    click EmailTestWrapper "https://github.com/tinestaric/evaluateaitoolkit/blob/Master/SendEmailToCustomer-Test/Test/EmailTestWrapper.Codeunit.al"

    classDef ui fill:#cbe4ff,stroke:#0366d6,color:#000
    classDef logic fill:#b7e4c7,stroke:#2f9e44,color:#000
    classDef infra fill:#ffc8a2,stroke:#e8590c,color:#000
    classDef external fill:#e0e0e0,stroke:#6c757d,color:#000,stroke-dasharray: 5 5
    classDef db fill:#d3d3d3,stroke:#343a40,color:#000,stroke-dasharray: 2 2
    class DB db
    class OpenAI external
```
