# seekdavidlee/all-in-one-chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/seekdavidlee/all-in-one-chatbot
- Repository: https://github.com/seekdavidlee/all-in-one-chatbot

## Overview

##### Main Components
- Ingestion Module:
- Data source ingestion and chunking (reflected in src/Ingestions, e.g., IIngestionDataSource implementations, IngestionProcessor, and specialized classes like LocalDirectoryIngestion, RestApiIngestion).
- Embedding integration (src/Embeddings) with both local model embedding and Azure OpenAI support.
- Indexing/publishing into a vector database (src/VectorDbs, including AzureAISearch and ChromaDbClient).
- Inference Module:
- Core chatbot logic: handles query input, intent determination, document retrieval, and LLM responses (located in src/Inferences, with sub-steps such as DetermineIntentStep, DetermineReplyStep, and RetrievedDocumentsStep).
- HTTP server support (via the HttpChatbotCommand) for handling inference requests over HTTP, probably driven by environment variables and routing to the proper workflow.
- Evaluation Module:
- Ground truth handling and evaluation workflows (in src/Evals), including the evaluation runner, metric workflow, and excel-based ground truth readers.
- Operations for both local and remote evaluations (commands such as local-evals and remote-evals indicate this modularity).
- Command/Orchestration Layer:
- Various commands (as seen in src/Commands, each mapping to a different mode such as ingest, chatbot, delete-search, import-ground-truths, etc.) to trigger the respective workflows.
- Language Model (LLM) Integration:
- Classes under src/Llms represent both Azure OpenAI and local LLM clients, along with supporting models and options.
- Supporting Infrastructure:
- Configuration management (src/Configurations), logging (src/Logging), and the overall Program.cs that initiates the console application.
- Docker configuration (Dockerfile, .dockerignore) and build/deployment scripts (Build.ps1, RunContainerApps.ps1) that illustrate containerization and deployment practices.

##### Relationships and Interactions
- Ingestion Workflow:
- Data flows from various ingestion data sources through the IngestionProcessor. It undergoes text chunking, then the content is embedded (via the IEmbedding implementations), and finally stored/indexed in a vector database via the IVectorDb interface.
- This flow is potentially executed either as a direct process or via a queue (as evidenced by commands like ingest-queue-processing) to enable distributed processing.
- Inference Workflow:
- User queries (from console or HTTP) are processed by the inference engine working through a series of workflow steps (like intent determination, document retrieval, and final response generation).
- The system harnesses either a local inference workflow (with local LLM support) or delegates to an Azure-based LLM.
- The HTTP server component adds an interface layer over this entire inference pipeline.
- Evaluation Workflow:
- Ground truth data (extracted by IGroundTruthReader, primarily from Excel documents) is fed into the EvaluationRunner.
- The workflow compares inference outputs against ground truths, performs metric evaluations, and produces summarized reports (with commands like summarize and show-metric-eval).
- Cross-module Interactions:
- Commands serve as entry points to specific orchestration flows (each command in src/Commands triggers a set of operations from ingestion, inference, or evaluation).
- Common utilities (configurations, logging, error handling) are shared across modules.

##### Architectural Patterns and Design Principles
- Modular separation: Although it is a monolithic codebase, the solution cleanly isolates ingestion, inference, and evaluation concerns into separate namespaces/directories.
- Command Pattern: The different commands encapsulate the behavior required to start various workflows, allowing for decoupling of the main program from specific operations.
- Dependency Injection: Interfaces such as IEmbedding, IVectorDb, ILanguageModel, and IGroundTruthReader suggest that dependency injection is used to keep components loosely coupled.
- Containerization: The provided Dockerfile and container-specific scripts show that the design is optimized for deployment in portable container environments.

##### Technologies and Frameworks
- .NET (with its project file AIOChatbot.csproj) as the core framework.
- Azure OpenAI and Azure services (e.g., Blob storage, Azure AI Search) as external services.
- Local implementations of embeddings and LLM (for scenarios where hosted services are not preferred).
- ChromaDB as an alternative vector database.
- PowerShell scripts for build and deployment automation.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Entry Points
    Program("Console Application (Program.cs)"):::infra
    Logging("Logging & Diagnostics"):::infra
    ConfigManagement("Configuration Management"):::infra
    CommandLayer("Command/Orchestration Layer"):::command

    %% Ingestion Workflow Subgraph
    subgraph "Ingestion Workflow"
        IngestionModule("Ingestion Module"):::module
        DataIngestion("DataSourceIngestion"):::process
        TextChunking("TextChunking"):::process
        EmbeddingIntegration("Embedding Integration"):::module
        VectorDbIntegration("VectorDatabaseIntegration"):::module
        IngestionModule --> DataIngestion
        DataIngestion --> TextChunking
        TextChunking --> EmbeddingIntegration
        EmbeddingIntegration --> VectorDbIntegration
    end

    %% Inference Workflow Subgraph
    subgraph "Inference Workflow"
        InferenceModule("Inference Module"):::module
        QueryInput("QueryInput"):::process
        IntentDetermination("IntentDetermination"):::process
        DocumentRetrieval("DocumentRetrieval"):::process
        LLMProcessing("LLMProcessing"):::module
        ChatbotResponse("ChatbotResponse"):::process
        InferenceModule --> QueryInput
        QueryInput --> IntentDetermination
        IntentDetermination --> DocumentRetrieval
        DocumentRetrieval --> LLMProcessing
        LLMProcessing --> ChatbotResponse
    end

    %% Evaluation Workflow Subgraph
    subgraph "Evaluation Workflow"
        EvaluationModule("Evaluation Module"):::module
        GroundTruth("GroundTruthExtraction"):::process
        EvalRunner("EvaluationRunner"):::process
        MetricCalculation("MetricCalculation"):::process
        SummaryReport("SummaryReport"):::process
        EvaluationModule --> GroundTruth
        GroundTruth --> EvalRunner
        EvalRunner --> MetricCalculation
        MetricCalculation --> SummaryReport
    end

    %% Supporting Module for LLM Integration
    LLMIntegration("LLM Integration"):::module

    %% Containerization & Deployment Subgraph
    subgraph "Containerization & Deployment"
        Docker("Dockerfile"):::deploy
        DockerIgnore(".dockerignore"):::deploy
        BuildScript("Build.ps1"):::deploy
        RunContainer("RunContainerApps.ps1"):::deploy
        Docker --> DockerIgnore
        DockerIgnore --> BuildScript
        BuildScript --> RunContainer
    end

    %% Main Flow Connections
    Program -->|"Starts"| CommandLayer
    CommandLayer -->|"Triggers"| IngestionModule
    CommandLayer -->|"Triggers"| InferenceModule
    CommandLayer -->|"Triggers"| EvaluationModule
    InferenceModule -->|"Uses"| LLMIntegration
    Program -->|"Uses"| ConfigManagement
    Program -->|"Uses"| Logging

    %% Class Definitions for Styling with Colors
    classDef infra fill:#f9e79f,stroke:#d4ac0d,stroke-width:2px;
    classDef module fill:#aed6f1,stroke:#1f618d,stroke-width:2px;
    classDef process fill:#d5f5e3,stroke:#27ae60,stroke-width:2px;
    classDef command fill:#f5b7b1,stroke:#c0392b,stroke-width:2px;
    classDef deploy fill:#fadbd8,stroke:#e74c3c,stroke-width:2px;

    %% Click Events for Component Mapping
    click IngestionModule "https://github.com/seekdavidlee/all-in-one-chatbot/tree/main/src/Ingestions"
    click EmbeddingIntegration "https://github.com/seekdavidlee/all-in-one-chatbot/tree/main/src/Embeddings"
    click VectorDbIntegration "https://github.com/seekdavidlee/all-in-one-chatbot/tree/main/src/VectorDbs"
    click InferenceModule "https://github.com/seekdavidlee/all-in-one-chatbot/tree/main/src/Inferences"
    click EvaluationModule "https://github.com/seekdavidlee/all-in-one-chatbot/tree/main/src/Evals"
    click CommandLayer "https://github.com/seekdavidlee/all-in-one-chatbot/tree/main/src/Commands"
    click LLMIntegration "https://github.com/seekdavidlee/all-in-one-chatbot/tree/main/src/Llms"
    click ConfigManagement "https://github.com/seekdavidlee/all-in-one-chatbot/tree/main/src/Configurations"
    click Logging "https://github.com/seekdavidlee/all-in-one-chatbot/tree/main/src/Logging"
    click Program "https://github.com/seekdavidlee/all-in-one-chatbot/blob/main/src/Program.cs"
    click Docker "https://github.com/seekdavidlee/all-in-one-chatbot/tree/main/src/Dockerfile"
    click DockerIgnore "https://github.com/seekdavidlee/all-in-one-chatbot/blob/main/.dockerignore"
    click BuildScript "https://github.com/seekdavidlee/all-in-one-chatbot/blob/main/Build.ps1"
    click RunContainer "https://github.com/seekdavidlee/all-in-one-chatbot/blob/main/RunContainerApps.ps1"
```
