# microsoft/dstoolkit-labelling-app architecture

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

- Interactive diagram: https://gitdiagram.com/microsoft/dstoolkit-labelling-app
- Repository: https://github.com/microsoft/dstoolkit-labelling-app

## Overview

##### Project Type and Purpose
- This is a monolithic Streamlit-based web application, packaged in a Docker container, used to collect SME feedback on ML outputs and provide a data analysis dashboard.
- It handles user sessions, form rendering, result persistence, and analytics—all in one codebase.

##### Main Components
a. Client / Browser
b. Streamlit Web Application (Docker Container)
– Entry point: `src/webpage/main.py`
– Web modules:
- Form Handling (various `form_handling/*.py` handlers)
- Labelling Page (`labelling_page.py`)
- Data Analysis View (`data_analysis/ds_view.py`)
- Session & User Management (`manage_user_session.py`, `user_management.py`)
– Utilities:
- Azure Blob Utils (`azure_blob_utils.py`)
- Secret Manager (`secret_manager.py`)
- Config Loader (`config.py`)
- Logger (`logger.py`)
– Assets & Config:
- `config.yaml`, `.env` template, `labelling_instructions.md`, sample data JSON
c. External Services / Storage
– Azure Blob Storage (data and results container)
– (Indirect) Streamlit-Authenticator for in-app auth
– (Optional) Azure App Service or reverse proxy for external security
d. Development / Deployment
– Dockerfile → Container
– Azure Pipeline → ACR & App Service

##### Relationships & Data Flow
- In-App:
1. On startup, `main.py` reads environment variables via `secret_manager.py` and `config.py`.
2. Loads labeling data (`load_data.py`) from Azure Blob.
3. Renders forms via `form_handling` modules.
4. On save, writes results back to Azure Blob via `azure_blob_utils.py`.
5. Users with `data_scientist` role trigger Data Analysis code (`ds_view.py`), which reads saved results from Blob, computes stats, renders charts.
- Errors and events flow into `logger.py`.

##### Architectural Patterns / Principles
- Modular layering: UI layer (Streamlit pages), Business logic (form handlers, analysis), Infrastructure (blob utils, secrets)
- Single-container monolith: no microservices, but clear separation of concerns in code modules
- Externalized configuration via YAML and environment variables
- Role-based feature toggle (Data Analysis View)

##### Essential Elements
- Clear labels: “Streamlit UI Layer”, “Form Handling Module”, “Azure Blob Storage”.

## Diagram (Mermaid)

```mermaid
flowchart TB
    Browser["Browser"]:::external

    subgraph "Docker Container (Streamlit App)"
        subgraph "UI Layer"
            Main["src/webpage/main.py"]:::app
            Labelling["src/webpage/labelling_page.py"]:::app
            subgraph "Form Handling Module"
                CustomFH["custom_form_handler.py"]:::app
                ErrorFH["error_feedback_handler.py"]:::app
                GTFH["ground_truth_handler.py"]:::app
                LabellingFormHandlers["labelling_form_handlers.py"]:::app
                LabellingHandlers["labelling_handlers.py"]:::app
                QualityFH["quality_feedback_handler.py"]:::app
            end
            LoadData["src/webpage/load_data.py"]:::app
            DownloadSave["src/webpage/download_and_save_results.py"]:::app
            ReloadResults["src/webpage/reload_saved_results.py"]:::app
            ManageSession["src/webpage/manage_user_session.py"]:::app
            UserMgmt["src/webpage/user_management.py"]:::app
        end

        subgraph "Business Logic"
            DSView["src/webpage/data_analysis/ds_view.py"]:::app
            subgraph "Data Analysis Utils"
                LoadResults["src/webpage/data_analysis/load_labelling_results.py"]:::app
                Summary["src/webpage/data_analysis/results_summary.py"]:::app
                Consts["src/webpage/data_analysis/analysis_consts.py"]:::app
            end
        end

        subgraph "Infrastructure & Config"
            AzureUtils["src/utils/azure_blob_utils.py"]:::infra
            SecretMgr["src/utils/secret_manager.py"]:::infra
            Logger["src/utils/logger.py"]:::infra
            STUtils["src/utils/st_utils.py"]:::infra
            ConfigLoader["src/config.py"]:::infra
            subgraph "Assets & Docs"
                CFGYAML["src/assets/config.yaml"]:::config
                SampleData["src/assets/data_sample.json"]:::config
                Instructions["src/assets/labelling_instructions.md"]:::config
                EnvTemplate["src/.env.template"]:::config
                Guide["src/doc/custom_forms_guide.md"]:::config
            end
        end
    end

    AzureBlob["Azure Blob Storage"]:::storage

    subgraph "Deployment"
        DockerScripts["Dockerfile & Scripts"]:::infra
        Pipeline["Azure Pipeline"]:::external
        ACR["ACR & App Service"]:::external
    end

    %% Relationships
    Browser -->|"HTTP(S) Request"| Main
    Main -->|"reads env"| SecretMgr
    Main -->|"loads config"| ConfigLoader
    Main -->|"loads label data"| LoadData
    LoadData -->|"Azure SDK Read"| AzureUtils
    AzureUtils -->|"Blob Read/Write"| AzureBlob

    Main -->|"renders labelling UI"| Labelling
    Labelling -->|"uses handlers"| LabellingFormHandlers
    LabellingFormHandlers -->|"on save"| DownloadSave
    DownloadSave -->|"write results"| AzureUtils

    LabellingFormHandlers -->|"reload results"| ReloadResults
    ReloadResults -->|"read results"| AzureUtils

    Main -->|"init session"| ManageSession
    Main -->|"user mgmt"| UserMgmt

    Main -->|"role check"| DSView
    DSView -->|"loads results"| LoadResults
    LoadResults -->|"Azure SDK Read"| AzureUtils
    LoadResults --> Summary
    Summary --> DSView

    Main -->|"logs events/errors"| Logger
    AzureUtils --> Logger
    SecretMgr --> Logger

    Main --> DockerScripts
    DockerScripts --> Pipeline
    Pipeline --> ACR

    %% Click Events
    click Main "https://github.com/microsoft/dstoolkit-labelling-app/blob/main/src/webpage/main.py"
    click Labelling "https://github.com/microsoft/dstoolkit-labelling-app/blob/main/src/webpage/labelling_page.py"
    click CustomFH "https://github.com/microsoft/dstoolkit-labelling-app/blob/main/src/webpage/form_handling/custom_form_handler.py"
    click ErrorFH "https://github.com/microsoft/dstoolkit-labelling-app/blob/main/src/webpage/form_handling/error_feedback_handler.py"
    click GTFH "https://github.com/microsoft/dstoolkit-labelling-app/blob/main/src/webpage/form_handling/ground_truth_handler.py"
    click LabellingFormHandlers "https://github.com/microsoft/dstoolkit-labelling-app/blob/main/src/webpage/form_handling/labelling_form_handlers.py"
    click LabellingHandlers "https://github.com/microsoft/dstoolkit-labelling-app/blob/main/src/webpage/form_handling/labelling_handlers.py"
    click QualityFH "https://github.com/microsoft/dstoolkit-labelling-app/blob/main/src/webpage/form_handling/quality_feedback_handler.py"
    click DSView "https://github.com/microsoft/dstoolkit-labelling-app/blob/main/src/webpage/data_analysis/ds_view.py"
    click LoadResults "https://github.com/microsoft/dstoolkit-labelling-app/blob/main/src/webpage/data_analysis/load_labelling_results.py"
    click Summary "https://github.com/microsoft/dstoolkit-labelling-app/blob/main/src/webpage/data_analysis/results_summary.py"
    click Consts "https://github.com/microsoft/dstoolkit-labelling-app/blob/main/src/webpage/data_analysis/analysis_consts.py"
    click LoadData "https://github.com/microsoft/dstoolkit-labelling-app/blob/main/src/webpage/load_data.py"
    click DownloadSave "https://github.com/microsoft/dstoolkit-labelling-app/blob/main/src/webpage/download_and_save_results.py"
    click ReloadResults "https://github.com/microsoft/dstoolkit-labelling-app/blob/main/src/webpage/reload_saved_results.py"
    click ManageSession "https://github.com/microsoft/dstoolkit-labelling-app/blob/main/src/webpage/manage_user_session.py"
    click UserMgmt "https://github.com/microsoft/dstoolkit-labelling-app/blob/main/src/webpage/user_management.py"
    click AzureUtils "https://github.com/microsoft/dstoolkit-labelling-app/blob/main/src/utils/azure_blob_utils.py"
    click SecretMgr "https://github.com/microsoft/dstoolkit-labelling-app/blob/main/src/utils/secret_manager.py"
    click Logger "https://github.com/microsoft/dstoolkit-labelling-app/blob/main/src/utils/logger.py"
    click STUtils "https://github.com/microsoft/dstoolkit-labelling-app/blob/main/src/utils/st_utils.py"
    click ConfigLoader "https://github.com/microsoft/dstoolkit-labelling-app/blob/main/src/config.py"
    click CFGYAML "https://github.com/microsoft/dstoolkit-labelling-app/blob/main/src/assets/config.yaml"
    click SampleData "https://github.com/microsoft/dstoolkit-labelling-app/blob/main/src/assets/data_sample.json"
    click Instructions "https://github.com/microsoft/dstoolkit-labelling-app/blob/main/src/assets/labelling_instructions.md"
    click EnvTemplate "https://github.com/microsoft/dstoolkit-labelling-app/blob/main/src/.env.template"
    click Guide "https://github.com/microsoft/dstoolkit-labelling-app/blob/main/src/doc/custom_forms_guide.md"

    %% Styles
    classDef external fill:#cce5ff,stroke:#004085,color:#004085;
    classDef app fill:#d4edda,stroke:#155724,color:#155724;
    classDef infra fill:#e2e3e5,stroke:#6c757d,color:#383d41;
    classDef config fill:#fefefe,stroke:#d6d8db,color:#818182;
    classDef storage fill:#bee5eb,stroke:#0c5460,color:#0c5460;
```
