Skip to content

Vertical AI Agent for Finance Operations - Automated invoice processing with Analyst-Critic pattern, Trust Battery system, and Slack "Intern's Desk" interface.

Notifications You must be signed in to change notification settings

Aparnap2/invoicify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Invoicify AI

Vertical AI Agent for Finance Operations - Automated invoice processing with Analyst-Critic pattern, Trust Battery system, and Slack "Intern's Desk" interface.

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        Cloudflare Workers                        β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚   Hono API  β”‚  β”‚    D1 DB    β”‚  β”‚       R2 Storage        β”‚  β”‚
β”‚  β”‚  (Worker)   β”‚  β”‚  (SQLite)   β”‚  β”‚    (Invoice Files)      β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚         β”‚                                                       β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚ Cloudflare  β”‚  β”‚   Workers   β”‚  β”‚     Vision OCR AI       β”‚  β”‚
β”‚  β”‚   AI (Llama)β”‚  β”‚    KV       β”‚  β”‚    (Extraction)         β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚         β”‚                β”‚                      β”‚                β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚      Neo4j Knowledge Graph   β”‚  β”‚   Slack "Intern's Desk"  β”‚  β”‚
β”‚  β”‚    (Temporal Vendor Data)    β”‚  β”‚   (Conversational AI)    β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                                                       β”‚
         β”‚ API (REST)                        β”‚ Slack Events      β”‚
         β–Ό                                                       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      Vite + React SPA                            β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚Dashboard  β”‚  β”‚ HITL Reviewβ”‚  β”‚      Audit Timeline       β”‚  β”‚
β”‚  β”‚  (KPIs)   β”‚  β”‚  (Approve) β”‚  β”‚    (Full History)         β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Tech Stack

Layer Technology
Frontend React 19 + Vite + TanStack Query + Tailwind CSS
Backend Hono.js (Cloudflare Workers)
Database Cloudflare D1 (SQLite)
Storage Cloudflare R2 (S3-compatible)
AI Cloudflare Workers AI (Llama 3.2 Vision)
Validation TypeScript strict mode

Features

Core Processing

  • Invoice Ingestion - Upload or submit invoice data
  • Vision OCR - AI-powered extraction from uploaded files
  • Risk Assessment - Multi-factor fraud detection
  • Auto-Approve - Low-risk invoices auto-approved based on Trust Battery

Analyst-Critic Agent Pattern

  • Analyst Node - Proposes action based on historical patterns and vendor history
  • Critic Node - Safety checks with priority matrix (RUNWAY > STRATEGY > CONTRACT > TRUST > BUDGET)
  • Reasoning Chain - Every decision explained with confidence scores

Human-in-the-Loop (HITL)

  • High-risk invoices flagged for review
  • Approve/reject with comments
  • Audit trail for all decisions
  • Slack integration with interactive buttons

Trust Battery System

  • Tracks vendor trust over time
  • Auto-approve thresholds per vendor level
  • Levels: Probation β†’ Standard β†’ Core

Slack "Intern's Desk" Interface

Conversational AI that lives in Slack - no dashboard required.

Proactive Alerts (The "Tap on the Shoulder"):

@finance-intern blocked a $12k invoice from NewVendor.
It looks like a duplicate of one we paid last week.
[Approve Override] [Reject]

Conversational Queries (The "Shout Across the Room"):

Founder: "How much runway do we have?"
Intern:  "Current cash $450k. Burn ~$50k/mo. Runway: ~9 months.
         (Note: We have a large tax bill due next month.)"

Founder: "Did we pay Acme yet?"
Intern:  "Yes! $2,450 on Jan 10. It was auto-approved because
         Acme is a Core vendor with 100% accuracy."

Episode Creation (Memory Injection):

Founder: "@finance-intern, from now on, auto-approve Vercel invoices under $500"
Intern:  "Understood. I've updated the Vercel trust policy and
         logged this instruction to my memory."

Temporal Knowledge Graph (Neo4j)

  • Vendor invoice history as temporal relationships
  • Trust score evolution over time
  • Pattern detection for recurring invoices

Getting Started

Prerequisites

  • Node.js 22+
  • pnpm
  • Cloudflare account with D1 and R2 enabled
  • Wrangler CLI (npm install -g wrangler)

Environment Setup

  1. Clone and install:
git clone <repo>
cd invoicify
  1. Configure environment:
# Worker environment
cd worker
cp .env.example .env
# Edit .env with your API keys:
# - STRIPE_TEST_KEY
# - QUICKBOOKS_CLIENT_ID
# - QUICKBOOKS_CLIENT_SECRET
# - QUICKBOOKS_REFRESH_TOKEN
# - QUICKBOOKS_REALM_ID

# Frontend environment
cd ../fullstack
cp .env.example .env.local
# Set VITE_API_URL=http://localhost:8787/api/v1 (dev)
  1. Start development:
# Terminal 1: Start Worker (with local D1)
cd worker
pnpm dev

# Terminal 2: Start Frontend
cd fullstack
pnpm dev
  1. Access:

Production Deployment

# Build frontend
cd fullstack
pnpm build

# Deploy to Cloudflare
cd worker
npx wrangler deploy

API Reference

Invoices

Method Endpoint Description
GET /api/v1/invoices List invoices (paginated)
GET /api/v1/invoices/:id Get invoice details
POST /api/v1/invoices Create invoice
PUT /api/v1/invoices/:id Update invoice
PATCH /api/v1/invoices/:id/status Update status
POST /api/v1/invoices/:id/approve HITL approve/reject

Risk

Method Endpoint Description
GET /api/v1/risk/:invoiceId Get risk assessment
POST /api/v1/risk/:invoiceId/analyze Re-run analysis
GET /api/v1/risk/list/high-risk List high-risk invoices
POST /api/v1/risk/feedback Submit feedback

Workflow

Method Endpoint Description
POST /api/v1/workflow/start Start invoice processing
POST /api/v1/workflow/:id/approve Continue after HITL

Slack Intern ("The Intern's Desk")

Method Endpoint Description
POST /api/v1/slack/intern/command Slash command /intern handler
POST /api/v1/slack/intern/events Event subscriptions (app_mention)
POST /api/v1/slack/interactions Button click interactions

Supported Queries:

  • "How much runway do we have?" - Returns runway calculation with context
  • "What's our burn rate?" - Monthly spending breakdown
  • "How much cash do we have?" - Current cash balance
  • "How much did we pay to [Vendor]?" - Vendor spend history
  • "What's pending?" - List of pending invoices
  • "Help" - Show available commands

Supported Instructions:

  • "From now on, auto-approve [Vendor] under $500" - Trust policy
  • "Always flag [Vendor] for review" - Review rule

QuickBooks

Method Endpoint Description
GET /api/v1/quickbooks/auth Get OAuth URL
GET /api/v1/quickbooks/callback OAuth callback

Environment Variables

Worker (worker/.env)

Variable Required Description
STRIPE_TEST_KEY Yes Stripe test API key
QUICKBOOKS_CLIENT_ID Yes QuickBooks OAuth client ID
QUICKBOOKS_CLIENT_SECRET Yes QuickBooks OAuth secret
QUICKBOOKS_REFRESH_TOKEN Yes QuickBooks refresh token
QUICKBOOKS_REALM_ID Yes QuickBooks company ID

Frontend (fullstack/.env.local)

Variable Required Description
VITE_API_URL Yes API base URL

Project Structure

invoicify/
β”œβ”€β”€ ai/                    # Python AI service (FastAPI)
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ agents/       # Analyst, Critic agents
β”‚   β”‚   β”œβ”€β”€ graphs/       # LangGraph workflows
β”‚   β”‚   β”œβ”€β”€ services/     # Trust Battery, Reconciliation
β”‚   β”‚   └── clients/      # Ollama, Neo4j clients
β”‚   └── tests/
β”œβ”€β”€ worker/                # Cloudflare Worker (Hono)
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ routes/       # API endpoints
β”‚   β”‚   β”‚   β”œβ”€β”€ slack.ts  # Slack Intern & HITL
β”‚   β”‚   β”‚   β”œβ”€β”€ workflow.ts # Agent workflow
β”‚   β”‚   β”‚   └── ...
β”‚   β”‚   β”œβ”€β”€ lib/          # Business logic
β”‚   β”‚   β”‚   β”œβ”€β”€ slack-intern.ts  # "Intern's Desk" logic
β”‚   β”‚   β”‚   β”œβ”€β”€ slack.ts         # HITL messages
β”‚   β”‚   β”‚   β”œβ”€β”€ workflow.ts      # State machine
β”‚   β”‚   β”‚   β”œβ”€β”€ neo4j.ts         # Knowledge graph
β”‚   β”‚   β”‚   └── audit-tracer.ts  # Audit trail
β”‚   β”‚   └── db/           # D1 schema
β”‚   β”œβ”€β”€ drizzle/          # DB migrations
β”‚   β”œβ”€β”€ wrangler.toml     # Worker config
β”‚   └── slack-manifest.json # Slack App Manifest
β”œβ”€β”€ fullstack/            # React SPA (Vite)
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/   # React components
β”‚   β”‚   β”œβ”€β”€ hooks/        # Custom hooks
β”‚   β”‚   └── types/        # TypeScript types
β”‚   └── dist/             # Built assets
β”œβ”€β”€ prd.md                # Product Requirements Document
└── SECURITY_AUDIT_REPORT.md

Security

See SECURITY_AUDIT_REPORT.md for:

  • Known vulnerabilities
  • Mitigation strategies
  • Audit findings and fixes

License

MIT

About

Vertical AI Agent for Finance Operations - Automated invoice processing with Analyst-Critic pattern, Trust Battery system, and Slack "Intern's Desk" interface.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •