# azure-samples/document-intelligence-code-samples architecture

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

- Interactive diagram: https://gitdiagram.com/azure-samples/document-intelligence-code-samples
- Repository: https://github.com/azure-samples/document-intelligence-code-samples

## Overview

##### Main Components
- Language-specific sample projects: The repository is divided into multiple directories for each supported language (.NET(v4.0), Python(v4.0), Java(v4.0), JavaScript(v4.0)). Each of these includes projects and sample code demonstrating how to call the Azure Document Intelligence client libraries.
- Feature-specific samples: Within each language folder, there are further subdivisions that separate different models (for example, “Prebuilt models”, “Custom models”, “Read model”, “Layout model”, and “Add-on capabilities” in Python).
- Data and Schema: The repository contains a “Data” folder housing sample documents (e.g., invoices, IDs, contracts) and a “schema” folder defining document formats and model configurations used to process these documents.
- Quickstarts and Helper Libraries: For .NET, there is a “Quickstarts” directory which includes helper code, assets (like PDFs and configurations), and sample programs that guide new users.

##### Interrelationships and Data Flow
- Clients (sample applications) in the language-specific directories illustrate how to interact with the Azure AI Document Intelligence service.
- The client applications use SDKs (provided or installed via package managers like pip for Python or NuGet for .NET) to communicate with the backend cloud service.
- Documents—from the “Data” directory—are used as inputs for the different analysis models. They feed into requests made by the sample applications.
- The responses (often structured as JSON and defined by the “schema”) flow back from the Azure service to the client code. This represents the data transformation and processing chain.
- For advanced functionalities like retrieval augmented generation (RAG) and add-on capabilities, there is a further processing layer demonstrated in the Python folder where postprocessing scripts (notebooks and scripts) perform additional data refinement.

##### Architectural Patterns and Design Principles
- Modular and Language-Agnostic Approach: The samples are organized by language, yet they all demonstrate similar functionality using the Azure AI Document Intelligence service. This separation makes it easier to update or add samples for new SDKs or functionalities.
- Separation of Concerns: The division between sample code, data, schema, and helper scripts clearly delineates where the domain logic (request construction, response handling), business rules, and data examples reside.
- Reusability: The common patterns (e.g., sending requests, processing responses) are abstracted out into helper modules (such as Utils.cs in .NET or helper scripts in Python) which are reused across different samples.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data and Schema Nodes
    dataIn["Data / Document Inputs"]:::data
    schemaDef["Schema Definitions"]:::data

    %% Aggregated Language Sample Clients
    dotnetAgg[".NET Samples Aggregate"]:::sample
    pythonAgg["Python Samples Aggregate"]:::sample
    java["Java Samples"]:::sample
    javascript["JavaScript Samples"]:::sample

    %% Central Azure Service
    azure["Azure AI Document Intelligence Service"]:::azure

    %% .NET Subgraph
    subgraph ".NET Samples"
        dotnetCM23[".NET Custom Models (2023)"]:::sample
        dotnetCM24[".NET Custom Models (2024)"]:::sample
        dotnetDA23[".NET Document Analysis (2023)"]:::sample
        dotnetDA24[".NET Document Analysis (2024)"]:::sample
        dotnetPB23[".NET Prebuilt Models (2023)"]:::sample
        dotnetPB24[".NET Prebuilt Models (2024)"]:::sample
        dotnetQuick[".NET Quickstarts"]:::helper
        dotnetHelper[".NET Quickstarts Helper"]:::helper
    end

    %% Python Subgraph
    subgraph "Python Samples"
        pythonAdd["Python Add-on Capabilities"]:::sample
        pythonCustom["Python Custom Models"]:::sample
        pythonLayout["Python Layout Model"]:::sample
        pythonRead["Python Read Model"]:::sample
        pythonRAG["Python RAG Samples"]:::sample
    end

    %% Grouping Relationships
    %% Indicate that subgraph components are part of the aggregates
    dotnetCM23 ---|"partof"| dotnetAgg
    pythonAdd ---|"partof"| pythonAgg

    %% Data flows into the Sample Clients
    dataIn --> dotnetAgg
    dataIn --> pythonAgg
    dataIn --> java
    dataIn --> javascript

    %% Sample Clients make API Requests to Azure Service
    dotnetAgg -->|"APIRequest"| azure
    pythonAgg -->|"APIRequest"| azure
    java -->|"APIRequest"| azure
    javascript -->|"APIRequest"| azure

    %% Azure Service Returns Responses to Sample Clients
    azure -->|"Response"| dotnetAgg
    azure -->|"Response"| pythonAgg
    azure -->|"Response"| java
    azure -->|"Response"| javascript

    %% Schema Definitions feed into Azure Service
    schemaDef -->|"ResponseSchema"| azure

    %% Class Definitions for Color Coding
    classDef sample fill:#AED6F1,stroke:#2980B9,stroke-width:2px;
    classDef azure fill:#F1948A,stroke:#C0392B,stroke-width:2px;
    classDef data fill:#ABEBC6,stroke:#27AE60,stroke-width:2px;
    classDef helper fill:#F7DC6F,stroke:#F1C40F,stroke-width:2px;

    %% Click Events for Aggregated Language Sample Clients
    click dotnetAgg "https://github.com/azure-samples/document-intelligence-code-samples/blob/main/.NET(v4.0) directory"
    click pythonAgg "https://github.com/azure-samples/document-intelligence-code-samples/blob/main/Python(v4.0) directory"
    click java "https://github.com/azure-samples/document-intelligence-code-samples/blob/main/Java(v4.0) directory"
    click javascript "https://github.com/azure-samples/document-intelligence-code-samples/blob/main/JavaScript(v4.0) directory"

    %% Click Events for .NET Subcomponents
    click dotnetCM23 "https://github.com/azure-samples/document-intelligence-code-samples/tree/main/.NET(v4.0)/CodeSnippetForApiVer_2023-10-31_Preview/Custom models"
    click dotnetCM24 "https://github.com/azure-samples/document-intelligence-code-samples/tree/main/.NET(v4.0)/CodeSnippetForApiVer_2024-02-29_Preview/Custom models"
    click dotnetDA23 "https://github.com/azure-samples/document-intelligence-code-samples/tree/main/.NET(v4.0)/CodeSnippetForApiVer_2023-10-31_Preview/Document analysis"
    click dotnetDA24 "https://github.com/azure-samples/document-intelligence-code-samples/tree/main/.NET(v4.0)/CodeSnippetForApiVer_2024-02-29_Preview/Document analysis"
    click dotnetPB23 "https://github.com/azure-samples/document-intelligence-code-samples/tree/main/.NET(v4.0)/CodeSnippetForApiVer_2023-10-31_Preview/Prebuilt models"
    click dotnetPB24 "https://github.com/azure-samples/document-intelligence-code-samples/tree/main/.NET(v4.0)/CodeSnippetForApiVer_2024-02-29_Preview/Prebuilt models"
    click dotnetQuick "https://github.com/azure-samples/document-intelligence-code-samples/tree/main/.NET(v4.0)/Quickstarts"
    click dotnetHelper "https://github.com/azure-samples/document-intelligence-code-samples/tree/main/.NET(v4.0)/Quickstarts/Helper"

    %% Click Events for Python Subcomponents
    click pythonAdd "https://github.com/azure-samples/document-intelligence-code-samples/tree/main/Python(v4.0)/Add-on_capabilities"
    click pythonCustom "https://github.com/azure-samples/document-intelligence-code-samples/tree/main/Python(v4.0)/Custom_model"
    click pythonLayout "https://github.com/azure-samples/document-intelligence-code-samples/tree/main/Python(v4.0)/Layout_model"
    click pythonRead "https://github.com/azure-samples/document-intelligence-code-samples/tree/main/Python(v4.0)/Read_model"
    click pythonRAG "https://github.com/azure-samples/document-intelligence-code-samples/tree/main/Python(v4.0)/Retrieval_Augmented_Generation_(RAG)_samples"

    %% Click Events for Data and Schema Nodes
    click dataIn "https://github.com/azure-samples/document-intelligence-code-samples/tree/main/Data directory"
    click schemaDef "https://github.com/azure-samples/document-intelligence-code-samples/tree/main/schema directory"
```
