Skip to navigation

1040 Tax Classifier Service

๐Ÿ“˜ Project Overview

Repository Name:ย poc-autoextract-platform-1040-tax-classifier

Purpose:ย Automate classification and verification of tax-related PDF documents using Azure Document Intelligence, deployed on Azure Kubernetes Service (AKS) with Spacelift for GitOps-based CI/CD.

##ย ๐ŸŽฏย Objective Buildย andย deployย aย scalable,ย event-drivenย PDFย classificationย serviceย that:

  • Follow the Framework V2 format for all components
  • Listensย toย Azureย Serviceย Busย topicย accepted-file
  • Classifiesย andย verifiesย taxย documentsย usingย Azureย Documentย Intelligence
  • Publishesย resultsย toย theย classified-fileย topic
  • Isย deployedย toย Azureย Kubernetesย Serviceย (AKS)ย usingย Spaceliftย forย ADOย automation

##ย ๐Ÿงฑย Systemย Architecture

+-----------------------------+
|ย ย ย ย ย Azureย Serviceย Busย ย ย ย ย ย |
|---------------------------|
|ย accepted-fileย (topic)ย ย ย ย ย |
|ย classified-fileย (topic)ย ย ย |
+-------------+-------------+
ย ย ย ย ย ย ย ย ย ย ย ย ย ย |
ย ย ย ย ย ย ย ย ย ย ย ย ย ย v
+-----------------------------+
|ย Azureย Kubernetesย Serviceย ย ย ย |
|-----------------------------|
|ย Classifierย Podย (Node.js)ย ย ย ย |
|ย -ย Listensย toย accepted-fileย ย |
|ย -ย Classifiesย PDFsย ย ย ย ย ย ย ย ย ย ย |
|ย -ย Publishesย classified-fileย |
+-------------+---------------+
ย ย ย ย ย ย ย ย ย ย ย ย ย ย |
ย ย ย ย ย ย ย ย ย ย ย ย ย ย v
+-----------------------------+
|ย Azureย Blobย Storageย ย ย ย ย ย ย ย ย ย |
|ย -ย Originalย PDFsย ย ย ย ย ย ย ย ย ย ย ย ย |
|ย -ย Splitย PDFsย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย |
+-------------+---------------+
ย ย ย ย ย ย ย ย ย ย ย ย ย ย |
ย ย ย ย ย ย ย ย ย ย ย ย ย ย v
+-----------------------------+
|ย Azureย Documentย Intelligenceย |
|ย -ย Classificationย ย ย ย ย ย ย ย ย ย ย ย |
|ย -ย Verificationย ย ย ย ย ย ย ย ย ย ย ย ย ย |
+-----------------------------+
ย ย ย ย ย ย ย ย ย ย ย ย ย ย โ–ฒ
ย ย ย ย ย ย ย ย ย ย ย ย ย ย |
+-----------------------------+
|ย ย ย ย ย ย ย ย Spaceliftย ย ย ย ย ย ย ย ย ย ย ย |
|ย -ย ADOย CI/CDย ย ย ย ย ย ย ย ย ย ย ย ย ย |
|ย -ย Deploysย toย AKSย ย ย ย ย ย ย ย ย ย ย ย |
|ย -ย Monitorsย ADOย repoย ย ย ย ย ย ย ย ย |
|ย ย ย `poc-1040-tax-classifier`ย |
+-----------------------------+

๐Ÿ” Workflow Summary

  1. Trigger: A new message is published to theย accepted-fileย topic.
  2. Listener: The Node.js service running in AKS receives the message.
  3. Processing:
    • Downloads the PDF from Azure Blob Storage.
    • Classifies and verifies it using Azure Document Intelligence.
    • Splits and uploads the resulting PDFs.
  4. Output: Publishes a message to theย classified-fileย topic.
  5. CI/CD: Spacelift watches theย poc-1040-tax-classifierย repo and deploys changes to AKS automatically.

๐Ÿงฉ Low-Level Design

๐Ÿ“ Project Structure

poc-1040-tax-classifier/
โ”œโ”€โ”€ Dockerfile
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ tsconfig.json
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ src/
โ”‚ โ”œโ”€โ”€ index.ts
โ”‚ โ”œโ”€โ”€ listeners/
โ”‚ โ”‚ โ””โ”€โ”€ acceptedFileListener.ts
โ”‚ โ”œโ”€โ”€ orchestrators/
โ”‚ โ”‚ โ””โ”€โ”€ classifier.ts
โ”‚ โ”œโ”€โ”€ services/
โ”‚ โ”‚ โ”œโ”€โ”€ blobService.ts
โ”‚ โ”‚ โ”œโ”€โ”€ documentIntelligence.ts
โ”‚ โ”‚ โ”œโ”€โ”€ pdfProcessor.ts
โ”‚ โ”‚ โ””โ”€โ”€ serviceBus.ts
โ”‚ โ”œโ”€โ”€ models/
โ”‚ โ”‚ โ”œโ”€โ”€ acceptedFileEvent.ts
โ”‚ โ”‚ โ””โ”€โ”€ classifiedFileEvent.ts
โ”‚ โ”œโ”€โ”€ utils/
โ”‚ โ”‚ โ””โ”€โ”€ logger.ts
โ”‚ โ””โ”€โ”€ config/
โ”‚ โ””โ”€โ”€ env.ts
โ”œโ”€โ”€ infra/
โ”‚ โ””โ”€โ”€ spacelift/
โ”‚ โ”œโ”€โ”€ main.tf
โ”‚ โ”œโ”€โ”€ variables.tf
โ”‚ โ””โ”€โ”€ kubernetes/
โ”‚ โ”œโ”€โ”€ deployment.yaml
โ”‚ โ”œโ”€โ”€ service.yaml
โ”‚ โ””โ”€โ”€ configmap.yaml

Component Responsibilities


ComponentDescription
acceptedFileListener.tsSubscribes to accepted-file topic and triggers classification
classifier.tsOrchestrates classification, verification, and messaging
documentIntelligence.tsWraps Azure Document Intelligence SDK
pdfProcessor.tsSplits and annotates PDFs using pdf-lib
blobService.tsUploads/downloads PDFs from Azure Blob Storage
serviceBus.tsSends messages to classified-file topic
main.tfSpacelift-managed Terraform for AKS deployment
deployment.yamlKubernetes deployment manifest for classifier pod

๐Ÿ“ฌ Message Flow


Incoming Message:ย accepted-file

{
ย ย "eventType":ย "file.accepted",
ย ย "fileId":ย "43434343-4343-4343-4343-434343434343",
ย ย "internalUrl":ย "https://azure.blobs.com/internal/43434343.pdf",
ย ย "clientApplicationId":ย "123e4567-e89b-12d3-a456-426614174000",
ย ย "timestamp":ย "2025-04-21T14:44:53Z"
}

Outgoing Message:ย classified-file

{
ย  "eventType": "file.classified",
ย  "fileId": "43434343-4343-4343-4343-434343435555",
ย  "parentUrl": "https://azure.blobs.com/internal/43434343.pdf",
ย  "childUrl": "https://azure.blobs.com/internal/434343435555.pdf",
ย  "clientApplicationId": "123e4567-e89b-12d3-a456-426614174000",
ย  "classifications": ["1099Gov", "1099NonGov", "Custom"],

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