> ## Documentation Index
> Fetch the complete documentation index at: https://docs.khanhng.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 2.1 Building Block View

> Building Block View for ReportGeneratorTool.

## 2.1.1 Level 1 - System Whitebox

![2.1  Building Block View](https://cs210032002b3e09a5d.blob.core.windows.net/tech-doc/diagrams/LVL1_Whitebox-ReportingGeneratorTool-001.png)

#### Container responsibilities

| Container | Responsibility | Technology | Owned data | Inbound | Outbound |
| - | - | - | - | - | - |
| Azure Function App | Accept requests, run orchestration and activities, automate the portal, calculate metrics, render PDF, and send email | Node.js, Azure Functions, Durable Functions, Puppeteer, Nodemailer | Transient request and file data | Report request | Portal, Azure Storage, email provider |
| Azure Storage | Maintain Durable Functions state and generated PDF blobs | Azure Storage and Blob Storage SDK | Orchestration state and report files | Function App writes | Function App reads |

## 2.1.2 Level 2 - Component view

A Component view adds value because orchestration, automation, data processing, storage, templating, and delivery have distinct maintenance risks.

![2.1  Building Block View](https://cs210032002b3e09a5d.blob.core.windows.net/tech-doc/diagrams/LVL2_ComponentView-ReportingGeneratorTool-001.png)

## 2.1.3 Level 3 - Report Service Code

```mermaid theme={null}
classDiagram
    direction LR

    class reportService_js {
        <<Code Module>>
        +runReportScript(request, context)
        -launchBrowser()
        -loginToDevicePortal()
        -selectDevice()
        -downloadDeviceData()
        -captureChart()
        -generatePdf()
        -uploadPdf()
    }

    class puppeteer_core {
        <<External Library>>
        +launch()
        +newPage()
        +goto()
        +click()
        +screenshot()
    }

    class processCSVService_js {
        <<Code Module>>
        +processCSV(context, assetDir, device)
        -readCsvFile()
        -parseCsvRows()
        -calculateTemperatureMetrics()
        -calculateAlarmCounts()
        -calculateAlarmDurations()
        -deleteCsvFile()
    }

    class reportTemplateService_js {
        <<Code Module>>
        +generateDeviceReport(clientInfo, device, dataUrl, csvResult, fromDate, toDate)
        -formatAlarmDuration()
        -buildHtmlDocument()
        -buildSummary()
        -buildAlarmTables()
        -buildSignoffSection()
    }

    class blobStorageService_js {
        <<Code Module>>
        +getBlobServiceClient()
    }

    class AzureBlobServiceClient {
        <<Azure SDK>>
        +getContainerClient()
        +getBlockBlobClient()
        +uploadFile()
    }

    class localTempStorage {
        <<Runtime Resource>>
        +storeCsvFile()
        +storeChartImage()
        +storePdfFile()
    }

    reportService_js ..> puppeteer_core : Uses for browser automation
    reportService_js ..> processCSVService_js : Calls processCSV()
    reportService_js ..> reportTemplateService_js : Calls generateDeviceReport()
    reportService_js ..> blobStorageService_js : Calls getBlobServiceClient()
    reportService_js ..> localTempStorage : Reads and writes temporary files

    blobStorageService_js ..> AzureBlobServiceClient : Creates client
    AzureBlobServiceClient ..> localTempStorage : Uploads generated PDF
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.