Skip to navigation

TaxDoc Extractor Service

๐Ÿ“˜ Project Overview

Repository Name: poc-autoextract-platform-taxdoc-extractor-service

๐Ÿ“Œ Overview

The Document Extraction Service is a containerized Node.js application that listens to Azure Service Bus messages on the classified-file topic. Upon receiving a message, it orchestrates a local workflow to:

Download and prepare a PDF document from Azure Blob Storage. Submit the document to Azure Cognitive Services for analysis. Poll for the result. Publish a success message to the extracted-result topic. This replaces the Camunda BPMN-based orchestration with a lightweight, in-code orchestration model. The service is deployed to Azure Kubernetes Service (AKS) using Spacelift for infrastructure automation.

Follow the Framework V2 format for all components

๐Ÿงฉ Components

๐Ÿ” Low-Level Design (LLD)

1. Message Handling

  • Subscriber: Listens to classified-file topic.
  • Payload:
{
"eventType": "file.classified",
"fileId": "uuid",
"parentUrl": "https://...",
"childUrl": "https://...",
"clientApplicationId": "uuid",
"classifications": ["TaxDoc"]
}

2. Orchestration Flow

prepareDocument():

Downloads the PDF from childUrl. Filters pages based on docType mapping. Uploads the filtered PDF to a prepared folder.

extractDocument():

Streams the prepared PDF. Submits it to Azure Cognitive Services. Retrieves the operation-location.

pollForResult():

Polls the operation-location until status === succeeded. Extracts and stores the analyzeResult.

publishResult():

Sends a message to extracted-result topic:

{
"eventType": "result.extracted",
"fileId": "uuid",
"clientApplicationId": "uuid",
"resultUrl": "https://.../results/<fileId>",
"timestamp": "ISO8601"
}

3. Error Handling

Centralized retry logic with exponential backoff. Graceful failure publishing (optional dead-letter queue). Logging and alerting for diagnostics.

๐Ÿ—‚๏ธ File Layout

๐Ÿ“ poc-autoextract-platform-taxdoc-extractor-service/
โ”œโ”€โ”€ ๐Ÿ“ src/
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ orchestrators/
โ”‚ โ”‚ โ””โ”€โ”€ documentOrchestrator.js # Main orchestration logic
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ services/
โ”‚ โ”‚ โ”œโ”€โ”€ blobStorageApiService.js # Azure Blob Storage interaction
โ”‚ โ”‚ โ”œโ”€โ”€ cognitiveServicesApiService.js # Submit and poll document analysis
โ”‚ โ”‚ โ””โ”€โ”€ serviceBusPublisher.js # Publishes to 'extracted-result'
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ subscribers/
โ”‚ โ”‚ โ””โ”€โ”€ classifiedFileSubscriber.js # Listens to 'classified-file' topic
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ tasks/
โ”‚ โ”‚ โ”œโ”€โ”€ prepareDocument.js # Filters and uploads PDF
โ”‚ โ”‚ โ””โ”€โ”€ extractDocument.js # Submits PDF to Cognitive Services
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ utilities/
โ”‚ โ”‚ โ”œโ”€โ”€ errorHandling.js # Retry and error logic
โ”‚ โ”‚ โ”œโ”€โ”€ mappingUtils.js # Maps docType to model/phrases
โ”‚ โ”‚ โ”œโ”€โ”€ pathUtils.js # Folder name helpers
โ”‚ โ”‚ โ””โ”€โ”€ constants.js # Shared constants
โ”‚ โ””โ”€โ”€ index.js # Entry point: initializes subscriber
โ”œโ”€โ”€ ๐Ÿ“ config/
โ”‚ โ”œโ”€โ”€ default.json # Default config (topics, retries)
โ”‚ โ””โ”€โ”€ production.json # Production overrides
โ”œโ”€โ”€ ๐Ÿ“ deployment/
โ”‚ โ”œโ”€โ”€ Dockerfile # Container definition
โ”‚ โ”œโ”€โ”€ deployment.yaml # Kubernetes deployment spec
โ”‚ โ”œโ”€โ”€ service.yaml # Kubernetes service spec (if needed)
โ”‚ โ””โ”€โ”€ spacelift-stack.yaml # Spacelift stack configuration
โ”œโ”€โ”€ .env # Environment variables
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ package.json
โ””โ”€โ”€ README.md

๐Ÿงช 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