Skip to navigation

Consolidated 1099 Extractor Service

๐Ÿ“„ 1099B-NonGovt-Extractor-Service Design

๐Ÿ“˜ Project Overview

Repository Name: poc-autoextract-platform-consolidated-1099-Extractor-Service

๐Ÿงญ Overview

Theย `Consolidated-1099-Extractor-Serviceย is a cloud-native Node.js microservice deployed on Azure Kubernetes Service (AKS). It automates the extraction of structured data from Consolidated 199 tax documents using Azure Document Intelligence and OpenAI. The service is triggered by messages from Azure Service Bus and publishes results to a downstream topic once processing is complete. Follow the Framework V2 format for all components

๐Ÿ”„ Workflow Summary

  1. Trigger: Listens to theย classified-fileย topic on Azure Service Bus.
{
"eventType": "file.classified",
"fileId": "uuid",
"parentUrl": "https://...",
"childUrl": "https://...",
"clientApplicationId": "uuid",
"classifications": ["1099Gov"]
}
  1. Download: Retrieves the document from Azure Blob Storage.
  2. Analyze: Uses Azure Document Intelligence and OpenAI to extract structured data.
  3. Merge: Combines outputs from both services into a unified JSON format.
  4. Upload: Stores the result back in Blob Storage.
  5. Notify: Publishes a message to theย extracted-resultย topic with a result URL.
{
"eventType": "result.extracted",
"fileId": "uuid",
"clientApplicationId": "uuid",
"resultUrl": "https://.../results/<fileId>",
"timestamp": "ISO8601"
}

๐Ÿงฉ Component List

ComponentDescription
Azure Service Bus SubscriberListens to the classified-file topic and initiates the extraction pipeline.
Blob DownloaderDownloads the original document from Azure Blob Storage.
PDF ParserParses the PDF using a Node.js library (e.g., pdf-lib or pdf2json) to extract raw text and tables.
Azure Document Intelligence ClientSends the document to Azure Form Recognizer for structured analysis.
OpenAI ClientSends extracted text to Azure OpenAI for LLM-based interpretation and validation.
Result MergerMerges outputs from Document Intelligence and OpenAI into a single JSON structure.
Blob UploaderUploads the final result JSON to a designated Blob Storage container.
Azure Service Bus PublisherSends a message to the extracted-result topic with metadata and result URL.
AKS DeploymentHosts the Node.js service in a scalable containerized environment.
Spacelift AutomationManages infrastructure provisioning and deployment pipelines for AKS, Service Bus, and Key Vault.
Azure Key Vault + CSI DriverSecurely injects secrets (API keys, connection strings) into the AKS pods.

โš™๏ธ Infrastructure

  • Platform: Azure Kubernetes Service (AKS)
  • Automation:ย https://spacelift.io/ย (manages AKS, Azure Service Bus, Key Vault, and Helm deployments)
  • Secrets: Azure Key Vault + CSI Driver
  • Observability: Azure Monitor, Application Insights

๐Ÿ“ File Structure

1099B-NonGovt-Extractor-Service/ โ”œโ”€โ”€ src/ โ”‚ โ”œโ”€โ”€ index.js โ”‚ โ”œโ”€โ”€ config/ โ”‚ โ”‚ โ””โ”€โ”€ env.js โ”‚ โ”œโ”€โ”€ messaging/ โ”‚ โ”‚ โ”œโ”€โ”€ subscriber.js โ”‚ โ”‚ โ””โ”€โ”€ publisher.js โ”‚ โ”œโ”€โ”€ services/ โ”‚ โ”‚ โ”œโ”€โ”€ blobService.js โ”‚ โ”‚ โ”œโ”€โ”€ pdfParser.js โ”‚ โ”‚ โ”œโ”€โ”€ documentAI.js โ”‚ โ”‚ โ”œโ”€โ”€ openAIExtractor.js โ”‚ โ”‚ โ””โ”€โ”€ resultMerger.js โ”‚ โ””โ”€โ”€ utils/ โ”‚ โ””โ”€โ”€ logger.js โ”œโ”€โ”€ Dockerfile โ”œโ”€โ”€ helm/ โ”‚ โ””โ”€โ”€ chart.yaml โ”œโ”€โ”€ spacelift/ โ”‚ โ”œโ”€โ”€ stacks/ โ”‚ โ”‚ โ””โ”€โ”€ aks-stack.yaml โ”‚ โ””โ”€โ”€ modules/ โ”‚ โ””โ”€โ”€ azure-kubernetes/ โ”‚ โ””โ”€โ”€ main.tf โ”œโ”€โ”€ package.json โ””โ”€โ”€ README.md


๐Ÿงฉ Module Responsibilities

index.js

  • Entry point
  • Initializes environment and starts the subscriber

config/env.js

  • Loads and validates environment variables

messaging/subscriber.js

  • Subscribes toย classified-fileย topic
  • Parses incoming payload:

messaging/publisher.js

  • Publishes toย extracted-resultย topic:

services/blobService.js

  • Downloads and uploads blobs from Azure Blob Storage

services/pdfParser.js

  • Parses PDF usingย pdf-libย orย pdf2json
  • Extracts tables and text

services/documentAI.js

  • Calls Azure Document Intelligence with custom model

services/openAIExtractor.js

  • Sends prompt to Azure OpenAI
  • Validates and refines LLM output

services/resultMerger.js

  • Merges Document AI and LLM results
  • Formats final JSON output

utils/logger.js

  • Centralized logging with context and correlation IDs

๐Ÿงช Testing Strategy

  • Unit Tests: Jest for all service modules
  • Integration Tests: Mock Azure SDKs and Service Bus
  • E2E Tests: Simulate full message flow in AKS dev cluster

๐Ÿš€ Deployment

  • CI/CD: GitHub Actions โ†’ Spacelift โ†’ AKS
  • Helm: Used for Kubernetes manifests
  • Spacelift:
    • Stack:ย aks-stack.yaml
    • Modules:ย azure-kubernetes/main.tf
    • Triggers: GitHub PRs and merges toย main
    • Secrets: Managed via Spacelift + Azure Key Vault