# kareenabeniwal-atlascopco/extract-content-from-excel-document-intelligence architecture

> Architecture diagram of the GitHub repository kareenabeniwal-atlascopco/extract-content-from-excel-document-intelligence, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kareenabeniwal-atlascopco/extract-content-from-excel-document-intelligence
- Repository: https://github.com/kareenabeniwal-atlascopco/extract-content-from-excel-document-intelligence

## Overview

##### Project Type and Purpose
- This is a simple, single‐service batch processing tool written in Python.
- It reads Excel files from a local directory, sends them to Azure Document Intelligence (ADI) for extraction, and writes the results as JSON into another local directory.
- There is no traditional frontend or database; the only external dependency is the Azure Document Intelligence API.

##### Main Components to Illustrate
a. File System – Input
- “input_documents” folder containing .xlsx files
b. Environment Configuration
- `.env` file holding ADI_ENDPOINT and ADI_API_KEY
c. Processing Engine
- `1_excel_to_json.py` Python script
- Key libraries: `dotenv` (env loader), `requests` (HTTP calls), `json` (serialization)
d. External Service
- Azure Document Intelligence “prebuilt-layout” model endpoint
e. File System – Output
- “content_json” folder where extracted JSON is saved

##### Relationships and Data Flow
1. The user invokes `python 1_excel_to_json.py`
2. The script loads environment variables from `.env`
3. The script enumerates all `.xlsx` files in `input_documents/`
4. For each file:
– The script reads binary data
– Sends an HTTP POST to the ADI endpoint with the file payload and API key
– Receives a 202 Accepted response with an `Operation-Location` URL
– Polls that URL (with GET) until the status is “succeeded”
– Receives the full extraction result as JSON
– Writes the JSON result to `content_json/<filename>.json`
5. Script exits once all files are processed

##### Architectural Patterns & Design Principles
- Batch Pipeline Pattern: file ingestion → external processing → file export
- Single Responsibility: the Python script handles orchestration, API communication, and I/O
- Configuration Isolation: secrets and endpoints stored outside code in `.env`
- Polling Loop: simple retry/polling mechanism rather than event-driven callbacks

##### Technologies & Frameworks
- Python 3.6+ runtime
- dotenv for env var management
- requests for HTTP interactions
- Azure Document Intelligence REST API

##### Final Advice
- Be explicit about every directory and HTTP interaction.
- Error/polling loop as a small sub‐flow detail around the ADI API call.

## Diagram (Mermaid)

```mermaid
flowchart TD
    classDef local fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef config fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef processing fill:#98FB98,stroke:#333,stroke-width:1px
    classDef externalService fill:#FFA500,stroke:#333,stroke-width:1px
    classDef external fill:#CCCCCC,stroke:#333,stroke-width:1px

    User["User / CLI"]:::external
    Script["1_excel_to_json.py\ndotenv, requests, json"]:::processing
    Env[".env"]:::config
    Input["input_documents\n(.xlsx files)"]:::local
    InputFile["test_adi_table.xlsx"]:::local
    Azure["Azure Document Intelligence\nprebuilt-layout"]:::externalService
    Output["content_json\n(.json files)"]:::local
    OutputFile["test_adi_table.json"]:::local
    Meta["Project Metadata"]:::local
    README["README.md"]:::local
    License["LICENSE"]:::local

    User -->|"Invoke script"| Script
    Script -->|"Load ADI_ENDPOINT & ADI_API_KEY"| Env
    Script -->|"Read .xlsx files"| Input
    Input --> InputFile
    Script -->|"POST file; poll status"| Azure
    Azure -->|"202 Accepted & Operation-Location"| Script
    Script -->|"Write JSON files"| Output
    Output --> OutputFile
    Script -->|"Reference metadata"| Meta
    Meta --> README
    Meta --> License

    %% Click Events
    click Input "https://github.com/kareenabeniwal-atlascopco/extract-content-from-excel-document-intelligence/tree/main/input_documents/"
    click Env "https://github.com/kareenabeniwal-atlascopco/extract-content-from-excel-document-intelligence/blob/main/.env"
    click Script "https://github.com/kareenabeniwal-atlascopco/extract-content-from-excel-document-intelligence/blob/main/1_excel_to_json.py"
    click InputFile "https://github.com/kareenabeniwal-atlascopco/extract-content-from-excel-document-intelligence/blob/main/input_documents/test_adi_table.xlsx"
    click Azure "https://github.com/kareenabeniwal-atlascopco/extract-content-from-excel-document-intelligence/tree/main/ "
    click Output "https://github.com/kareenabeniwal-atlascopco/extract-content-from-excel-document-intelligence/tree/main/content_json/"
    click OutputFile "https://github.com/kareenabeniwal-atlascopco/extract-content-from-excel-document-intelligence/blob/main/content_json/test_adi_table.json"
    click README "https://github.com/kareenabeniwal-atlascopco/extract-content-from-excel-document-intelligence/blob/main/README.md"
    click License "https://github.com/kareenabeniwal-atlascopco/extract-content-from-excel-document-intelligence/tree/main/LICENSE"
```
