# satishgunjal/botbuilder-samples architecture

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

- Interactive diagram: https://gitdiagram.com/satishgunjal/botbuilder-samples
- Repository: https://github.com/satishgunjal/botbuilder-samples

## Overview

##### Project Type and Purpose
- This is a monorepo of Bot Framework “task-focused” sample bots, implemented in two language stacks (C# and Node.js).
- Each sample is a standalone, web-hosted bot application that demonstrates a specific feature or integration (e.g., channels, attachments, LUIS, Cognitive Services, DirectLine, etc.).
- The README groups them into four categories—Core, Cards, Intelligence, Demo—making the repository more of a “catalog” of micro-services (individual bots) than a single cohesive product.

##### File-Structure Analysis
- Top level: two primary folders, “CSharp” and “Node”, each containing many subfolders named by sample (e.g., core-SendAttachment, cards-RichCards, intelligence-LUIS, demo-ContosoFlowers).
- Under each sample:
- A web-server project (ASP.NET Web API for C#; Express or similar for Node).
- Configuration files (Web.config/Web.Debug/Web.Release.json, .env, package.json, csproj/sln files).
- Controllers (MessagesController or app.js routes) that expose the `/api/messages` endpoint.
- Dialog or service modules (Dialogs folder in C#, dialogs/*.js in Node) to orchestrate conversation flows.
- Models, Helpers or Services folders for domain or Cognitive-services integration.
- Azure deployment templates (azuredeploy.json) for provisioning resources.
- Common cross-cutting concerns: authentication middleware, state storage (Bot state API or custom provider), telemetry (AppInsights), channel-specific payloads (ChannelData), and custom connectors (DirectLine, Skype Calling).

##### Insights from README
- Confirms the samples are independent deployments, each illustrating a Bot Framework SDK feature.
- Reinforces the pattern: Channel → Bot Framework Connector → Sample Bot App → Dialog Stack → External Services/Storage.

a. Main Components (template for any single sample):
- User/Channel (e.g., Web Chat, Facebook Messenger, Skype)
- Bot Framework Connector (Azure Bot Service runtime)
- Sample Bot Web App:
- HTTP Listener (ASP.NET Web API or Node.js Express)
- MessagesController / Route Handler
- Bot Adapter / Middleware (authentication, telemetry)
- Dialog Stack Module
- Service Integrations (LUIS, Bing Speech, Computer Vision, Azure Search, etc.)
- State Storage (in-memory, Azure Blob/Table, or custom)
- Azure Resources (App Service, Cognitive Services, Application Insights)

b. Relationships and Interactions:
1. User sends a message via Channel UI
2. Channel forwards message through Bot Connector to the Bot App’s HTTP endpoint
3. Middleware processes/authenticates the incoming activity
4. Controller hands off to Bot Adapter which invokes the root Dialog
5. Dialogs coordinate conversational logic, optionally calling out to:
– LUIS for NLP intent resolution
– Cognitive APIs for vision, speech, search
– Custom services (e.g., OrderService, Repository)
6. Bot App updates or reads state storage as needed
7. Bot App sends an Activity response back through Bot Connector to the Channel

c. Architectural Patterns and Principles:
- MVC/Web API for request routing (Controller → Adapter)
- Dialog-centric pipeline (Chain of Responsibility + Middleware)
- Dependency Injection (services and LUIS models are injected or resolved by factories)
- Layered separation: transport layer (HTTP → Controller), application logic (Dialogs/Services), infrastructure (Storage, External APIs)

d. Key Technologies, Frameworks, Libraries:
- C#: ASP.NET Web API, Bot Builder SDK v3 or v4, Newtonsoft.Json, Application Insights SDK
- Node.js: Express, Bot Builder SDK for Node, dotenv for config, package.json dependencies
- External: LUIS.ai, Bing Speech/Cognitive Services, Azure Search Client, DirectLine API

##### Final Recommendations
- Follow with a “generic bot architecture” template.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User and Channel
    User["User"]:::user
    Channel["Channel UI"]:::channel
    User -->|sends message| Channel
    Channel -->|forwards message| Connector["Azure Bot Connector"]:::connector

    %% Bot Apps
    Connector -->|POST /api/messages| BotAppC["Bot App (C#)"]:::botapp
    Connector -->|POST /api/messages| BotAppN["Bot App (Node.js)"]:::botapp

    %% C# Bot App Internals
    subgraph "Bot App Internals (C#)"
        HC["HTTP Listener<br/>MessagesController"]:::controller
        MA["Middleware / Telemetry"]:::middleware
        DS["Dialog Stack<br/>ChannelDataDialog"]:::dialog
        SS["State Storage<br/>StateDialog"]:::storage
        CS["Service Integrations"]:::service
    end
    BotAppC --> HC --> MA --> DS --> CS
    DS --> SS

    %% Node.js Bot App Internals
    subgraph "Bot App Internals (Node.js)"
        HN["HTTP Listener<br/>app.js"]:::controller
        MN["Middleware / Telemetry"]:::middleware
        DN["Dialog Stack<br/>facebook-channeldata.js"]:::dialog
        SN["State Storage<br/>In-Memory State"]:::storage
        CN["Service Integrations"]:::service
    end
    BotAppN --> HN --> MN --> DN --> CN
    DN --> SN

    %% External Services
    CS -->|calls LUIS| LUISC["LUIS Integration Service<br/>BingSpellCheckService"]:::external
    CS -->|calls Vision| VisCSharp["Cognitive Vision Service<br/>MicrosoftCognitiveCaptionService"]:::external
    CN -->|calls LUIS| LUINode["LUIS Integration Service<br/>spell-service"]:::external
    CN -->|calls Vision| VisNode["Cognitive Vision Service<br/>caption-service"]:::external
    SS -->|reads/writes| Storage["In-Memory / Azure Blob Storage"]:::storage

    %% Responses back to Channel
    CS -->|Activity response| Connector
    CN -->|Activity response| Connector

    %% Click Events
    click HC "https://github.com/satishgunjal/botbuilder-samples/blob/master/CSharp/core-ChannelData/Controllers/MessagesController.cs"
    click HN "https://github.com/satishgunjal/botbuilder-samples/blob/master/Node/core-ChannelData/app.js"
    click DS "https://github.com/satishgunjal/botbuilder-samples/blob/master/CSharp/core-ChannelData/ChannelDataDialog.cs"
    click DN "https://github.com/satishgunjal/botbuilder-samples/blob/master/Node/core-ChannelData/facebook-channeldata.js"
    click MA "https://github.com/satishgunjal/botbuilder-samples/blob/master/CSharp/core-AppInsights/TelemetryExtensions.cs"
    click MN "https://github.com/satishgunjal/botbuilder-samples/blob/master/Node/core-AppInsights/telemetry-module.js"
    click SS "https://github.com/satishgunjal/botbuilder-samples/blob/master/CSharp/core-CustomState/StateDialog.cs"
    click SN "https://github.com/satishgunjal/botbuilder-samples/blob/master/Node/core-CustomState/app.js"
    click LUISC "https://github.com/satishgunjal/botbuilder-samples/blob/master/CSharp/intelligence-LUIS/Services/BingSpellCheckService.cs"
    click LUINode "https://github.com/satishgunjal/botbuilder-samples/blob/master/Node/intelligence-LUIS/spell-service.js"
    click VisCSharp "https://github.com/satishgunjal/botbuilder-samples/blob/master/CSharp/intelligence-ImageCaption/Services/MicrosoftCognitiveCaptionService.cs"
    click VisNode "https://github.com/satishgunjal/botbuilder-samples/blob/master/Node/intelligence-ImageCaption/caption-service.js"

    %% Styles
    classDef user fill:#E3F2FD,stroke:#90CAF9,color:#0D47A1;
    classDef channel fill:#BBDEFB,stroke:#64B5F6,color:#0D47A1;
    classDef connector fill:#E1BEE7,stroke:#BA68C8,color:#4A148C;
    classDef botapp fill:#C8E6C9,stroke:#81C784,color:#1B5E20;
    classDef controller fill:#A5D6A7,stroke:#66BB6A,color:#1B5E20;
    classDef middleware fill:#AED581,stroke:#9CCC65,color:#33691E;
    classDef dialog fill:#DCE775,stroke:#D4E157,color:#827717;
    classDef storage fill:#CFD8DC,stroke:#B0BEC5,color:#37474F;
    classDef service fill:#FFE082,stroke:#FFD54F,color:#E65100;
    classDef external fill:#FFCCBC,stroke:#FF8A65,color:#BF360C;
```
