# microsoft/botbuilder-dotnet architecture

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

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

## Overview

##### Project Type & Purpose
- This is a mono-repo containing a suite of .NET libraries that together form the Microsoft Bot Framework SDK.
- It is not a single runnable application but rather a set of NuGet-packaged components (core SDK, adapters, AI recognizers, integrations, parsers, generators, etc.) designed for building conversational bots.
- The README confirms the purpose: model conversation, connect to channels, use LUIS/QnA services, store state in Azure, generate language with LG, run tests, and publish packages.

##### High-Level File Structure
- Top‐level:
– Microsoft.Bot.Builder.sln (solution)
– Directory.Build.props, global.json, build scripts, CI/CD pipeline YAML under /build & /.github/workflows
– /libraries – each subfolder is one packaged library (e.g., Adapters.Facebook, AI.LUIS, Dialogs.Adaptive, Integration.AspNet.Core, LanguageGeneration, Parsers.LU, TemplateManager, etc.)
– /tests – parallel test projects exercising each library and sample/test bots
– /generators – code templates for bot projects
– /FunctionalTests – end-to-end tests using real channels/services

##### Key Components
- Core SDK (Microsoft.Bot.Builder)
- Adapters layer (Facebook, Slack, Twilio, Webex, TestAdapter)
- Connector & Streaming layer (Microsoft.Bot.Connector & Microsoft.Bot.Streaming)
- Dialog system (Microsoft.Bot.Builder.Dialogs and Dialogs.Adaptive, Dialogs.Declarative, Dialogs.Debugging, Dialogs.Testing)
- AI Recognizers (LUIS, QnA Maker, Orchestrator)
- Language Generation (LG – Microsoft.Bot.Builder.LanguageGeneration)
- Template Manager (Microsoft.Bot.Builder.TemplateManager)
- Parsers (Microsoft.Bot.Builder.Parsers.LU)
- Integrations (ApplicationInsights, AspNet.Core, AspNet.WebApi, Azure Storage & Blobs, Queues)
- BotState & Storage (in-memory, Azure Blob/Cosmos/Queue storage)
- External cloud services: Azure Bot Service, LUIS endpoint, QnA Maker service, Application Insights, Azure Blob/CosmosDB
- CI/CD pipelines and package feeds (Azure Artifacts, MyGet)

##### Relationships & Interactions
- A Bot App → uses the BotFrameworkAdapter (in Integration.AspNet.Core/WebApi)
- Adapter → routes incoming HTTP/streaming requests to BotAdapter core → fires TurnContext → Bot logic (Dialogs)
- Dialogs read/write BotState → pass through Storage implementations (Memory, Azure Blobs/Queues, Cosmos)
- Dialogs can call Recognizers → HTTP calls to LUIS, QnA Maker, Orchestrator
- Responses pass through LanguageGeneration to produce rich messages
- Adapters serialize Activity objects via Connector/Streaming libraries
- Telemetry middleware sends events to ApplicationInsights
- CI/CD build scripts assemble outputs and publish NuGet packages

##### Architectural Patterns & Principles
- Modular, package-per-concern design (“libraries” directory)
- Dependency Injection / BotComponent registration for extensibility
- Adapter pattern for channel abstraction
- Decorator/Middleware pattern for Turn pipeline (logging, telemetry, storage)
- Declarative configuration and templates for bots and dialogs
- Separation of concerns: core, dialogs, AI, adapters, storage, integrations

##### Essential Elements to Capture
- Clear component names matching folder or package names
- A note on CI/CD and package publishing pipelines for completeness
- Keep it detailed but readable: group dozens of low-level test projects under “/tests” aggregate

- Top: Bot Application (developer’s code)
- Next: Integration layer (HTTP/Streaming Adapters)
- Core: Microsoft.Bot.Builder + Dialog modules + Middleware
- AI: Recognizers calling LUIS/QnA/Orchestrator
- Storage: BotState with Memory or Azure stores
- Generation: LG & TemplateManager
- Underpinning: Connector/Streaming, Parsers.LU
- Side: CI/CD pipeline, package outputs
- Clouds: Azure services, MyGet/Azure Artifacts feeds

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Developer Bot App"
        BotApp["Bot Application"]:::app
    end

    subgraph "Integration Layer"
        FB["Facebook Adapter"]:::adapter
        SL["Slack Adapter"]:::adapter
        TW["Twilio Adapter"]:::adapter
        WX["Webex Adapter"]:::adapter
        TA["Test Adapter"]:::adapter
        ASPCORE["AspNet.Core Adapter"]:::infra
        ASPWEB["AspNet.WebApi Adapter"]:::infra
    end

    subgraph "Core SDK"
        Core["Microsoft.Bot.Builder"]:::core
        Connector["Connector Library"]:::connector
        Stream["Streaming Library"]:::connector
    end

    subgraph "Dialogs & Middleware"
        DialogCore["Core Dialogs"]:::core
        DialogAD["Adaptive Dialogs"]:::core
        DialogDB["Declarative Dialogs"]:::core
        DialogDbg["Dialogs Debugging"]:::core
        DialogAT["Adaptive Dialog Testing"]:::core
    end

    subgraph "AI Recognizers"
        LU["LUIS Recognizer"]:::ai
        QNA["QnA Maker"]:::ai
        ORCH["Orchestrator"]:::ai
    end

    subgraph "Language & Templates"
        LG["Language Generation (LG)"]:::lg
        TM["Template Manager"]:::lg
    end

    subgraph "Parsers"
        LUParser["LU Parser"]:::parser
    end

    subgraph "State & Storage"
        Memory["In-Memory Storage"]:::storage
        Blob["Azure Blob Storage"]:::storage
        Queue["Azure Queue Storage"]:::storage
    end

    subgraph "Integrations"
        AIInt["AppInsights Integration"]:::infra
    end

    subgraph "External Services"
        AzureBot["Azure Bot Service"]:::external
        AzureLUIS["LUIS Endpoint"]:::external
        AzureQNA["QnA Maker Service"]:::external
        AzureAI["Application Insights"]:::external
        AzureBlob["Azure Blob/CosmosDB"]:::external
        Artifacts["MyGet/Azure Artifacts"]:::external
    end

    subgraph "CI/CD & Tests"
        Build["Build Scripts / Pipelines"]:::tools
        Tests["/tests & FunctionalTests"]:::tools
    end

    BotApp -->|HTTP/gRPC| FB
    BotApp -->|HTTP/gRPC| SL
    BotApp -->|HTTP/gRPC| TW
    BotApp -->|HTTP/gRPC| WX
    BotApp -->|HTTP/gRPC| TA
    BotApp -->|HTTP| ASPCORE
    BotApp -->|HTTP| ASPWEB

    FB -->|routes to| Core
    SL -->|routes to| Core
    TW -->|routes to| Core
    WX -->|routes to| Core
    TA -->|routes to| Core
    ASPCORE -->|uses Adapter| Core
    ASPWEB -->|uses Adapter| Core

    Core -->|invokes| DialogCore
    DialogCore -->|uses| DialogAD
    DialogAD -->|uses| DialogDB
    DialogAD -->|uses| DialogDbg
    DialogAD -->|tests| DialogAT

    DialogCore -->|state ops| Memory
    DialogCore -->|state ops| Blob
    DialogCore -->|state ops| Queue

    DialogAD -->|recognize| LU
    DialogAD -->|recognize| QNA
    DialogAD -->|recognize| ORCH

    LU -->|HTTP| AzureLUIS
    QNA -->|HTTP| AzureQNA
    ORCH -->|HTTP| AzureLUIS

    Core -->|serialize| Connector
    Connector -->|stream| Stream
    Connector -->|connects to| AzureBot
    Stream -->|connects to| AzureBot

    Core -->|telemetry| AIInt
    AIInt -->|sends events| AzureAI

    DialogCore -->|generate| LG
    LG -->|template| TM

    DialogCore -->|parse| LUParser

    Build -->|publishes| Artifacts
    Build -->|runs| Tests

    classDef app fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef adapter fill:#90EE90,stroke:#333,stroke-width:1px
    classDef core fill:#4682B4,stroke:#333,stroke-width:1px
    classDef connector fill:#20B2AA,stroke:#333,stroke-width:1px
    classDef ai fill:#FFA500,stroke:#333,stroke-width:1px
    classDef lg fill:#9370DB,stroke:#333,stroke-width:1px
    classDef parser fill:#FFB6C1,stroke:#333,stroke-width:1px
    classDef storage fill:#DDA0DD,stroke:#333,stroke-width:1px
    classDef infra fill:#DA70D6,stroke:#333,stroke-width:1px
    classDef external fill:#C0C0C0,stroke:#333,stroke-width:1px
    classDef tools fill:#D3D3D3,stroke:#333,stroke-width:1px

    click Core "https://github.com/microsoft/botbuilder-dotnet/blob/main/libraries/Microsoft.Bot.Builder"
    click FB "https://github.com/microsoft/botbuilder-dotnet/blob/main/libraries/Adapters/Microsoft.Bot.Builder.Adapters.Facebook"
    click SL "https://github.com/microsoft/botbuilder-dotnet/blob/main/libraries/Adapters/Microsoft.Bot.Builder.Adapters.Slack"
    click TW "https://github.com/microsoft/botbuilder-dotnet/blob/main/libraries/Adapters/Microsoft.Bot.Builder.Adapters.Twilio"
    click WX "https://github.com/microsoft/botbuilder-dotnet/blob/main/libraries/Adapters/Microsoft.Bot.Builder.Adapters.Webex"
    click TA "https://github.com/microsoft/botbuilder-dotnet/blob/main/libraries/Microsoft.Bot.Builder/Adapters/TestAdapter.cs"
    click Connector "https://github.com/microsoft/botbuilder-dotnet/blob/main/libraries/Microsoft.Bot.Connector"
    click Stream "https://github.com/microsoft/botbuilder-dotnet/blob/main/libraries/Microsoft.Bot.Connector.Streaming"
    click DialogCore "https://github.com/microsoft/botbuilder-dotnet/blob/main/libraries/Microsoft.Bot.Builder.Dialogs"
    click DialogAD "https://github.com/microsoft/botbuilder-dotnet/blob/main/libraries/Microsoft.Bot.Builder.Dialogs.Adaptive"
    click DialogDB "https://github.com/microsoft/botbuilder-dotnet/blob/main/libraries/Microsoft.Bot.Builder.Dialogs.Declarative"
    click DialogDbg "https://github.com/microsoft/botbuilder-dotnet/blob/main/libraries/Microsoft.Bot.Builder.Dialogs.Debugging"
    click DialogAT "https://github.com/microsoft/botbuilder-dotnet/blob/main/libraries/Microsoft.Bot.Builder.Dialogs.Adaptive.Testing"
    click LU "https://github.com/microsoft/botbuilder-dotnet/blob/main/libraries/Microsoft.Bot.Builder.AI.LUIS"
    click QNA "https://github.com/microsoft/botbuilder-dotnet/blob/main/libraries/Microsoft.Bot.Builder.AI.QnA"
    click ORCH "https://github.com/microsoft/botbuilder-dotnet/blob/main/libraries/Microsoft.Bot.Builder.AI.Orchestrator"
    click LG "https://github.com/microsoft/botbuilder-dotnet/blob/main/libraries/Microsoft.Bot.Builder.LanguageGeneration"
    click TM "https://github.com/microsoft/botbuilder-dotnet/blob/main/libraries/Microsoft.Bot.Builder.TemplateManager"
    click LUParser "https://github.com/microsoft/botbuilder-dotnet/blob/main/libraries/Parsers/Microsoft.Bot.Builder.Parsers.LU"
    click AIInt "https://github.com/microsoft/botbuilder-dotnet/blob/main/libraries/integration/Microsoft.Bot.Builder.Integration.ApplicationInsights.Core"
    click ASPCORE "https://github.com/microsoft/botbuilder-dotnet/blob/main/libraries/integration/Microsoft.Bot.Builder.Integration.AspNet.Core"
    click ASPWEB "https://github.com/microsoft/botbuilder-dotnet/blob/main/libraries/integration/Microsoft.Bot.Builder.Integration.AspNet.WebApi"
    click Memory "https://github.com/microsoft/botbuilder-dotnet/blob/main/libraries/Microsoft.Bot.Builder/MemoryStorage.cs"
    click Blob "https://github.com/microsoft/botbuilder-dotnet/blob/main/libraries/Microsoft.Bot.Builder.Azure.Blobs"
    click Queue "https://github.com/microsoft/botbuilder-dotnet/blob/main/libraries/Microsoft.Bot.Builder.Azure.Queues"
    click Build "https://github.com/microsoft/botbuilder-dotnet/tree/main/build/"
    click Tests "https://github.com/microsoft/botbuilder-dotnet/tree/main/tests/"
```
