# sirigireddyreddaiahh/blus-invoice-agent architecture

> Architecture diagram of the GitHub repository sirigireddyreddaiahh/blus-invoice-agent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sirigireddyreddaiahh/blus-invoice-agent
- Repository: https://github.com/sirigireddyreddaiahh/blus-invoice-agent

## Overview

This is an accounts-payable invoice fraud detection and review application. A clerk uploads invoices or imports S/4 data; documents are parsed into invoice records, checked by fraud rules and ledger/SAP matching, then exposed for review, audit, and posting. Batch jobs, exports, alerts, and the assistant are substantial capabilities alongside that workflow. The excerpts show key backend calls and imports; UI-to-service wiring and several subsystem internals were not sampled, so those links are omitted or marked unverified.

Main entry points: [`srv/fraud-service.js`](https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/fraud-service.js) (Fraud service), [`srv/lib/document-processor.js`](https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/lib/document-processor.js) (Document processor), [`app/app.js`](https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/app/app.js) (Web application), [`srv/lib/queue.js`](https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/lib/queue.js) (Batch queue)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Review experience"]
  node_web["Web application<br/>[app.js]"]
  node_checks["Check views<br/>[Component.js]"]
  node_alerts["Alert views<br/>[Component.js]"]
  node_assistant["Invoice assistant"]
end

subgraph group_processing["Invoice processing"]
  node_documents["Document processor"]
  node_filevalidation["File validation<br/>[extract.js]"]
  node_pdftext["PDF text extraction<br/>[pdftext.js]"]
  node_pdfimage["PDF image and QR<br/>[pdfimage.js]"]
  node_ocr["OCR<br/>[ocr.js]"]
  node_csv["CSV and S4 parsing<br/>[csv.js]"]
  node_ai["AI extraction<br/>[ai-extract.js]"]
end

subgraph group_controls["Fraud controls"]
  node_rulesengine["Rules engine<br/>[engine.js]"]
  node_rulecatalog["Fraud rule catalog<br/>[rules.js]"]
  node_ledgerlogic["Ledger matching<br/>[ledger.js]"]
  node_lookup["Vendor lookup<br/>[index.js]"]
end

subgraph group_services["Application services"]
  node_service["Fraud service<br/>[fraud-service.js]"]
  node_http["HTTP endpoints<br/>[server.js]"]
  node_batch["Batch queue<br/>[queue.js]"]
  node_pagination["History and summaries<br/>[pagination.js]"]
  node_exports["Data exports<br/>[export.js]"]
  node_agenttools["Assistant tools<br/>[agent-tools.js]"]
end

subgraph group_persistence["Persistence and integrations"]
  node_sap["SAP connector<br/>[sap.js]"]
  node_db[("Invoice and audit store<br/>[schema.cds]")]
end

node_clerk(("AP clerk"))
node_sapservice["SAP S4 system"]

node_clerk -.->|"uses"| node_web
node_web -.->|"submits invoices"| node_service
node_web -.->|"opens checks"| node_checks
node_web -.->|"reviews alerts"| node_alerts
node_web -.->|"asks questions"| node_assistant
node_http -.->|"routes requests"| node_service
node_service -->|"processes uploads"| node_documents
node_documents -->|"validates files"| node_filevalidation
node_documents -->|"extracts PDF text"| node_pdftext
node_documents -->|"renders pages and QR"| node_pdfimage
node_documents -->|"runs OCR"| node_ocr
node_documents -->|"parses CSV"| node_csv
node_documents -->|"uses extraction"| node_ai
node_service -->|"runs checks"| node_rulesengine
node_rulesengine -->|"evaluates rules"| node_rulecatalog
node_service -->|"checks ledger"| node_ledgerlogic
node_service -->|"enriches invoices"| node_lookup
node_service -.->|"manages batch jobs"| node_batch
node_batch -->|"checks invoices"| node_rulesengine
node_batch -->|"loads ledger"| node_ledgerlogic
node_batch -->|"uses SAP connector"| node_sap
node_service -->|"builds history views"| node_pagination
node_http -->|"streams exports"| node_exports
node_service -->|"provides assistant tools"| node_agenttools
node_service -->|"queries SAP"| node_sap
node_sap -->|"fetches invoices"| node_sapservice
node_ledgerlogic -->|"reads and writes ledger"| node_db
node_pagination -->|"queries history"| node_db
node_service -->|"writes audit log"| node_db

click node_web "https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/app/app.js"
click node_checks "https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/app/checks/Component.js"
click node_alerts "https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/app/alerts/Component.js"
click node_assistant "https://github.com/sirigireddyreddaiahh/blus-invoice-agent/tree/main/app/assistant"
click node_service "https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/fraud-service.js"
click node_http "https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/server.js"
click node_documents "https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/lib/document-processor.js"
click node_filevalidation "https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/lib/extract.js"
click node_pdftext "https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/lib/pdftext.js"
click node_pdfimage "https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/lib/pdfimage.js"
click node_ocr "https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/lib/ocr.js"
click node_csv "https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/lib/csv.js"
click node_ai "https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/lib/ai-extract.js"
click node_rulesengine "https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/rules/engine.js"
click node_rulecatalog "https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/rules/rules.js"
click node_ledgerlogic "https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/lib/ledger.js"
click node_lookup "https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/lib/lookup/index.js"
click node_batch "https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/lib/queue.js"
click node_pagination "https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/lib/pagination.js"
click node_exports "https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/lib/export.js"
click node_agenttools "https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/lib/agent-tools.js"
click node_sap "https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/lib/sap.js"
click node_db "https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/db/schema.cds"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_web,node_checks,node_alerts,node_assistant toneBlue
class node_documents,node_filevalidation,node_pdftext,node_pdfimage,node_ocr,node_csv,node_ai toneAmber
class node_rulesengine,node_rulecatalog,node_ledgerlogic,node_lookup toneMint
class node_service,node_http,node_batch,node_pagination,node_exports,node_agenttools toneRose
class node_sap,node_db,node_clerk,node_sapservice toneIndigo
```

## Components

### Review experience

- [Web application](https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/app/app.js): `app/app.js`
- [Check views](https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/app/checks/Component.js): `app/checks/Component.js`
- [Alert views](https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/app/alerts/Component.js): `app/alerts/Component.js`
- [Invoice assistant](https://github.com/sirigireddyreddaiahh/blus-invoice-agent/tree/main/app/assistant): `app/assistant`

### Invoice processing

- [Document processor](https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/lib/document-processor.js): `srv/lib/document-processor.js`
- [File validation](https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/lib/extract.js): `srv/lib/extract.js`
- [PDF text extraction](https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/lib/pdftext.js): `srv/lib/pdftext.js`
- [PDF image and QR](https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/lib/pdfimage.js): `srv/lib/pdfimage.js`
- [OCR](https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/lib/ocr.js): `srv/lib/ocr.js`
- [CSV and S4 parsing](https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/lib/csv.js): `srv/lib/csv.js`
- [AI extraction](https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/lib/ai-extract.js): `srv/lib/ai-extract.js`

### Fraud controls

- [Rules engine](https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/rules/engine.js): `srv/rules/engine.js`
- [Fraud rule catalog](https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/rules/rules.js): `srv/rules/rules.js`
- [Ledger matching](https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/lib/ledger.js): `srv/lib/ledger.js`
- [Vendor lookup](https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/lib/lookup/index.js): `srv/lib/lookup/index.js`

### Application services

- [Fraud service](https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/fraud-service.js): `srv/fraud-service.js`
- [HTTP endpoints](https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/server.js): `server.js`
- [Batch queue](https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/lib/queue.js): `srv/lib/queue.js`
- [History and summaries](https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/lib/pagination.js): `srv/lib/pagination.js`
- [Data exports](https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/lib/export.js): `srv/lib/export.js`
- [Assistant tools](https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/lib/agent-tools.js): `srv/lib/agent-tools.js`

### Persistence and integrations

- [SAP connector](https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/srv/lib/sap.js): `srv/lib/sap.js`
- [Invoice and audit store](https://github.com/sirigireddyreddaiahh/blus-invoice-agent/blob/main/db/schema.cds): `db/schema.cds`

### Other components

- **AP clerk**
- **SAP S4 system**

## Connections

- AP clerk → Web application: uses
- Web application → Fraud service: submits invoices
- Web application → Check views: opens checks
- Web application → Alert views: reviews alerts
- Web application → Invoice assistant: asks questions
- HTTP endpoints → Fraud service: routes requests
- Fraud service → Document processor: processes uploads (evidence: `srv/fraud-service.js`)
- Document processor → File validation: validates files (evidence: `srv/lib/document-processor.js`)
- Document processor → PDF text extraction: extracts PDF text (evidence: `srv/lib/document-processor.js`)
- Document processor → PDF image and QR: renders pages and QR (evidence: `srv/lib/document-processor.js`)
- Document processor → OCR: runs OCR (evidence: `srv/lib/document-processor.js`)
- Document processor → CSV and S4 parsing: parses CSV (evidence: `srv/lib/document-processor.js`)
- Document processor → AI extraction: uses extraction (evidence: `srv/lib/document-processor.js`)
- Fraud service → Rules engine: runs checks (evidence: `srv/fraud-service.js`)
- Rules engine → Fraud rule catalog: evaluates rules (evidence: `srv/rules/engine.js`)
- Fraud service → Ledger matching: checks ledger (evidence: `srv/fraud-service.js`)
- Fraud service → Vendor lookup: enriches invoices (evidence: `srv/fraud-service.js`)
- Fraud service → Batch queue: manages batch jobs (evidence: `srv/fraud-service.js`)
- Batch queue → Rules engine: checks invoices (evidence: `srv/lib/queue.js`)
- Batch queue → Ledger matching: loads ledger (evidence: `srv/lib/queue.js`)
- Batch queue → SAP connector: uses SAP connector (evidence: `srv/lib/queue.js`)
- Fraud service → History and summaries: builds history views (evidence: `srv/fraud-service.js`)
- HTTP endpoints → Data exports: streams exports (evidence: `server.js`)
- Fraud service → Assistant tools: provides assistant tools (evidence: `srv/fraud-service.js`)
- Fraud service → SAP connector: queries SAP (evidence: `srv/fraud-service.js`)
- SAP connector → SAP S4 system: fetches invoices (evidence: `srv/lib/sap.js`)
- Ledger matching → Invoice and audit store: reads and writes ledger (evidence: `srv/lib/ledger.js`)
- History and summaries → Invoice and audit store: queries history (evidence: `srv/lib/pagination.js`)
- Fraud service → Invoice and audit store: writes audit log (evidence: `srv/fraud-service.js`)
