# microsoft/pubsec-info-assistant architecture

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

- Interactive diagram: https://gitdiagram.com/microsoft/pubsec-info-assistant
- Repository: https://github.com/microsoft/pubsec-info-assistant

## Overview

##### Project’s Main Components
- Frontend: Located under app/frontend – this is a Vite-based, TypeScript/React application that provides the user interface.
- Backend API: In app/backend – a Flask-based API layer that handles prompt engineering, response generation, and acts as the intermediary between the frontend and Azure services.
- Enrichment Service: In app/enrichment – another Flask-based service dedicated to text enrichment, including translation, embedding, and data ingestion into the Azure AI Search index.
- Azure Functions Pipeline: Found in the functions/ directory – these functions handle document extraction, chunking, logging (via Cosmos DB), and other tasks related to processing various file types.
- Azure Search and AI Integrations: The azure_search/ configuration and references in the README indicate that the solution leverages Azure AI Search (formerly Cognitive Search) alongside Azure OpenAI for the RAG (Retrieval Augmented Generation) workflows.
- Infrastructure-as-Code: Under infra/ – this includes Terraform scripts that deploy all resources (compute, networking, storage, search, etc.) required in the solution.
- CI/CD Pipelines & Deployment Scripts: Directories like pipelines/, scripts/, and configuration files (like Makefile) help automate builds, deployments, and environment configuration.
- Dev & Container Configurations: The .devcontainer/ and related configuration files support local development and GitHub Codespaces setups.

##### Relationships and Interactions
- User Interaction & Presentation: The Frontend (app/frontend) provides the chat UI and controls for selecting response approaches (Grounded, Ungrounded, Work and Web, Assistants).
- API Communication: The frontend makes REST API calls to the backend (app/backend) which, depending on the query, may use one of several response generation approaches.
- Response Generation: The backend implements multiple approaches by integrating:
- Retrieval Augmented Generation using domain data (with citations from Azure AI Search),
- Standard LLM-based ungrounded responses,
- Hybrid approaches comparing responses from web-sourced content.
- Enrichment Pipeline: The enrichment service (app/enrichment) processes files to prepare data for indexing in Azure Search and works alongside other services with Azure Storage queues.
- Functions & Background Processing: Azure Functions process documents and log activities, interacting with other services such as Cosmos DB.
- Infrastructure and Deployment: Terraform scripts in infra/ orchestrate the setup in Azure; pipelines and scripts manage continuous integration/deployment and environment configuration.
- External Services: The overall system leverages Azure OpenAI for language processing and Azure AI Search for indexing and retrieval. It also includes Azure networking, logging, and security as part of its infrastructure.

##### Architectural Patterns and Design Principles
- Microservices / Modular Design: The separation between frontend, backend, enrichment service, and serverless functions shows a modular, loosely-coupled architecture.
- RAG Pattern: Emphasize that the backend implements a retrieval augmented generation pattern which retrieves domain-specific data (through Azure AI Search) before generating responses.
- Containerization & Cloud-Native Deployment: The project supports DevContainers, Docker-based container images (seen in container_images/), and infrastructure managed by Terraform.
- CI/CD Automation: Clearly identify how pipelines, scripts, and Makefile commands automate testing, building, and deployments.
- Extensibility: The architecture is designed to support multiple response generation strategies (grounded, ungrounded, and a hybrid approach) which can be extended.

## Diagram (Mermaid)

```mermaid
flowchart TD
    U["User"]:::external

    subgraph "Presentation Layer"
        FE["Frontend UI (React/Vite)"]:::presentation
    end

    subgraph "Business Logic Layer"
        BE["Backend API (Flask)"]:::business
        EN["Enrichment Service (Flask)"]:::business
    end

    subgraph "Serverless Functions"
        AF["Azure Functions Pipeline"]:::serverless
    end

    subgraph "External Azure Services"
        AO["Azure OpenAI Service"]:::external
        AS["Azure AI Search"]:::external
        Cosmos["Cosmos DB (Logging)"]:::external
    end

    subgraph "Infrastructure & Automation"
        TF["Terraform Scripts"]:::infrastructure
        CP["CI/CD Pipelines"]:::cicd
        DS["Deployment Scripts"]:::cicd
        MF["Makefile"]:::cicd
        DEV["Dev & Container Configurations"]:::dev
    end

    U -->|"uses"| FE
    FE -->|"calls"| BE
    BE -->|"sendsRequest"| EN
    BE -->|"triggers"| AF
    BE -->|"calls_RAG"| AS
    BE -->|"calls_LLM"| AO
    EN -->|"indexesData"| AS
    AF -->|"logsTo"| Cosmos

    TF -->|"provisions"| FE
    TF -->|"provisions"| BE
    TF -->|"provisions"| EN
    TF -->|"provisions"| AF
    TF -->|"provisions"| AO
    TF -->|"provisions"| AS

    CP -->|"deploys"| FE
    CP -->|"deploys"| BE
    CP -->|"deploys"| EN
    CP -->|"deploys"| AF

    DS -->|"deploysScripts"| FE
    DS -->|"deploysScripts"| BE
    DS -->|"deploysScripts"| EN
    DS -->|"deploysScripts"| AF

    MF -->|"orchestrates"| FE
    MF -->|"orchestrates"| BE
    MF -->|"orchestrates"| EN
    MF -->|"orchestrates"| AF

    DEV -->|"supportsDev"| FE

    click FE "https://github.com/microsoft/pubsec-info-assistant/tree/main/app/frontend"
    click BE "https://github.com/microsoft/pubsec-info-assistant/tree/main/app/backend"
    click EN "https://github.com/microsoft/pubsec-info-assistant/tree/main/app/enrichment"
    click AF "https://github.com/microsoft/pubsec-info-assistant/tree/main/functions/"
    click AO "https://github.com/microsoft/pubsec-info-assistant/tree/main/infra/core/ai/openaiservices"
    click AS "https://github.com/microsoft/pubsec-info-assistant/tree/main/infra/core/search"
    click TF "https://github.com/microsoft/pubsec-info-assistant/tree/main/infra/"
    click CP "https://github.com/microsoft/pubsec-info-assistant/tree/main/pipelines/"
    click DS "https://github.com/microsoft/pubsec-info-assistant/tree/main/scripts/"
    click MF "https://github.com/microsoft/pubsec-info-assistant/tree/main/Makefile"
    click DEV "https://github.com/microsoft/pubsec-info-assistant/blob/main/.devcontainer"

    classDef presentation fill:#bbdefb,stroke:#0d47a1,stroke-width:2px
    classDef business fill:#c8e6c9,stroke:#2e7d32,stroke-width:2px
    classDef serverless fill:#ffe082,stroke:#ff6f00,stroke-width:2px
    classDef external fill:#f8bbd0,stroke:#c2185b,stroke-width:2px
    classDef infrastructure fill:#d7ccc8,stroke:#4e342e,stroke-width:2px
    classDef cicd fill:#d1c4e9,stroke:#512da8,stroke-width:2px
    classDef dev fill:#b2dfdb,stroke:#00695c,stroke-width:2px
```
