vgtc-api / README.md
vora-sonnet's picture
Upload folder using huggingface_hub
0d3f7cc verified
|
Raw
History Blame Contribute Delete
14.7 kB
---
title: VGTC Compliance API
emoji: 🌐
colorFrom: blue
colorTo: green
sdk: docker
app_port: 7860
pinned: true
---
<div align="center">
# VGTC
### **AI Trade Compliance Platform**
**Automate import compliance. From document to audit trail in seconds.**
Upload a document or connect your ERP β†’ Get HS codes, sanctions screening, and a compliance report with full audit trail.
[![Tests](https://img.shields.io/badge/tests-175%20passing-brightgreen?style=flat-square)]()
[![Python](https://img.shields.io/badge/python-3.11+-blue?style=flat-square)]()
[![License](https://img.shields.io/badge/license-Source%20Available-red?style=flat-square)]()
[![Backend](https://img.shields.io/badge/backend-Render.com-orange?style=flat-square)]()
[![Frontend](https://img.shields.io/badge/frontend-Cloudflare%20Pages-blue?style=flat-square)]()
[Try Live](https://vgtc.voraprotocol.com) β€’ [API Docs](https://vgtc.onrender.com/docs) β€’ [Contact](vedkumar755@gmail.com)
</div>
---
## The Problem
Import compliance takes 2-4 hours per document. Manual HS code lookups, sanctions checks, duty calculations. One misclassification = millions in penalties.
## The Solution
VGTC automates it end-to-end.
| Metric | Manual | VGTC |
|:-------|:------:|:----:|
| Time per document | 2-4 hours | **30 seconds** |
| Cost per check | $50-100 | **$0.50** |
| Setup time | 6-18 months | **10 minutes** |
| HS classification accuracy | ~70% | **75%+ (LLM-backed)** |
| Sanctions coverage | Partial | **OFAC SDN + EU Consolidated (local, free)** |
---
## Live Deployment
| Component | URL | Stack |
|:----------|:----|:------|
| Frontend | `https://vgtc.voraprotocol.com` | Next.js β†’ Cloudflare Pages |
| Backend API | `https://vgtc.onrender.com` | FastAPI β†’ Docker β†’ Render |
| API Docs | `https://vgtc.onrender.com/docs` | Swagger UI |
---
## Workflow
```
1. Upload document / Connect ERP β†’ PDF, SAP S/4HANA, Odoo
2. AI extracts data β†’ Products, quantities, values, origins
3. HS code classification β†’ pyhscodes (6,940+ WCO) + DeepSeek LLM
4. Sanctions screening β†’ OFAC SDN + EU Consolidated (local, public domain)
5. Compliance report β†’ Full audit trail with SHA-256 hash chain
6. Human review β†’ Dashboard with approve/reject workflow
```
---
## Architecture
```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Cloudflare Pages β”‚
β”‚ vgtc.voraprotocol.com (frontend) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚ HTTPS
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Render.com (Docker) β”‚
β”‚ vgtc.onrender.com (backend) β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ FastAPI Server (server.py) β”‚
β”‚ β”œβ”€β”€ POST /api/v1/compliance/check ← PDF upload pipeline β”‚
β”‚ β”œβ”€β”€ POST /api/v1/integration/sap/trigger ← SAP OData β”‚
β”‚ β”œβ”€β”€ POST /api/v1/integration/odoo/trigger ← Odoo JSON-RPC β”‚
β”‚ β”œβ”€β”€ GET /api/v1/dashboard/queue ← Review queue β”‚
β”‚ └── POST /api/v1/dashboard/action ← Approve/reject β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Core Engines β”‚
β”‚ β”œβ”€β”€ HS Classifier (1,405 lines) ← pyhscodes + LLM hybrid β”‚
β”‚ β”œβ”€β”€ Sanctions Engine (1,237 lines) ← 8-layer phonetic match β”‚
β”‚ β”œβ”€β”€ PDF Parser (807 lines) ← pypdf extraction β”‚
β”‚ β”œβ”€β”€ Dashboard Service (1,720 lines) ← PostgreSQL-backed queue β”‚
β”‚ └── ERP Connector (726 lines) ← SAP + Odoo integration β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Database: PostgreSQL (Render) β”‚
β”‚ β”œβ”€β”€ compliance_review_items ← Review items β”‚
β”‚ └── compliance_audit_chain ← SHA-256 hash chain β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```
---
## Core Engines
### HS Code Classifier (`hs_classifier.py` β€” 1,405 lines)
Hybrid classification engine with 3-tier caching:
| Tier | Source | Latency | Cost |
|:-----|:-------|:--------|:-----|
| 1 | In-memory LRU cache (2,048 entries) | ~0ms | Free |
| 2 | PostgreSQL ILIKE fuzzy match | ~5ms | Free |
| 3 | pyhscodes (6,940+ WCO codes) | ~10ms | Free (LGPL-2.1) |
| 4 | LLM (DeepSeek V4 Flash via OpenCode) | ~30-70s | Free tier |
**Enterprise features:**
- `classify_batch()` β€” async batch classification with `asyncio.Semaphore(5)` concurrency control
- Cross-validation between pyhscodes and LLM (LLM wins when confidence gap > 15%)
- Automatic dot/dash normalization in LLM responses
- Markdown code block stripping for raw LLM output
- Human review flagging for ambiguous terms
**Supported LLM providers:** DeepSeek, Qwen, OpenAI, Anthropic, Google Gemini
### Sanctions Engine (`sanctions.py` β€” 1,237 lines)
8-layer phonetic matching engine β€” no external API dependency:
| Layer | Method | Purpose |
|:------|:-------|:--------|
| 1 | Exact match | Perfect match |
| 2 | Normalized exact | Case/punctuation insensitive |
| 3 | Token sort | Word order variation |
| 4 | Partial match | Substring containment |
| 5 | Phonetic (Soundex) | Homophone matching |
| 6 | Phonetic (Metaphone) | Sound-alike matching |
| 7 | Levenshtein distance | Fuzzy spelling |
| 8 | Jaro-Winkler | Similarity scoring |
**Data sources:** OFAC SDN CSV + EU Consolidated XML (public domain, auto-downloaded)
### ERP Integration (`erp_connector.py` β€” 726 lines)
| ERP | Adapter | Lines | Protocol |
|:----|:--------|:------|:---------|
| SAP S/4HANA | `sap_adapter.py` | 891 | OData v2 |
| Odoo | `odoo_adapter.py` | 832 | JSON-RPC |
**Pipeline flow:** ERP β†’ line items β†’ async batch HS classification β†’ sanctions screening β†’ PostgreSQL persistence (ComplianceReviewItem + AuditChain)
**Mock mode:** Automatic when ERP credentials are missing β€” returns realistic sample data.
### Dashboard Service (`dashboard.py` β€” 1,720 lines)
PostgreSQL-backed review queue with:
- Tenant isolation (X-Tenant-ID header)
- Optimistic locking for concurrent updates
- SHA-256 hash chain audit trail
- In-memory fallback when database is unavailable
---
## Quick Start
```bash
# Clone
git clone https://github.com/mysterious75/VGTC.git
cd VGTC
# Install
pip install -e .
# Run demo (uses DeepSeek LLM β€” requires API key in .env)
python demo.py
# Run with your PDF
python demo.py --file your_invoice.pdf
```
### Configuration (`.env`)
```bash
# LLM β€” DeepSeek V4 Flash via OpenCode (free tier)
MODEL_PROVIDER=opencode
MODEL_API_KEY=sk-...
MODEL_NAME=deepseek-v4-flash
MODEL_BASE_URL=https://opencode.ai/zen/go/v1
# Database (Render PostgreSQL)
DATABASE_URL=postgresql+asyncpg://...
# Security
SECURITY_API_KEY=vgk_...
SECURITY_SECRET_KEY=...
```
---
## Tech Stack
| Layer | Technology |
|:------|:-----------|
| Language | Python 3.11+ |
| API Framework | FastAPI |
| HS Classification | pyhscodes (LGPL-2.1) + DeepSeek LLM |
| Phonetics | jellyfish (BSD-3) |
| PDF Parsing | pypdf (BSD-3) |
| Sanctions Data | OFAC SDN CSV + EU Consolidated XML |
| Database | PostgreSQL (SQLAlchemy async) |
| Frontend | Next.js 14 (Cloudflare Pages) |
| Backend Hosting | Docker β†’ Render.com |
| DNS | Cloudflare |
| CI/CD | GitHub Actions |
| ERP Adapters | SAP S/4HANA (OData) + Odoo (JSON-RPC) |
---
## Project Structure
```
VGTC/
β”œβ”€β”€ demo.py # One-command demo
β”œβ”€β”€ src/hermes/
β”‚ β”œβ”€β”€ tools/
β”‚ β”‚ β”œβ”€β”€ hs_classifier.py # HS code classification (1,405 lines)
β”‚ β”‚ β”œβ”€β”€ sanctions.py # Sanctions screening (1,237 lines)
β”‚ β”‚ β”œβ”€β”€ pdf_parser.py # PDF extraction (807 lines)
β”‚ β”‚ β”œβ”€β”€ dashboard.py # Review queue (1,720 lines)
β”‚ β”‚ β”œβ”€β”€ erp_connector.py # SAP/Odoo bridge (726 lines)
β”‚ β”‚ β”œβ”€β”€ sanctions_scheduler.py # 24h auto-refresh (197 lines)
β”‚ β”‚ └── __init__.py # CompliancePipeline orchestrator
β”‚ β”œβ”€β”€ api/
β”‚ β”‚ β”œβ”€β”€ server.py # FastAPI server (1,114 lines)
β”‚ β”‚ └── routers/ # API route modules
β”‚ β”œβ”€β”€ database/
β”‚ β”‚ β”œβ”€β”€ models.py # SQLAlchemy models (177 lines)
β”‚ β”‚ └── connection.py # DB connection manager
β”‚ β”œβ”€β”€ config/
β”‚ β”‚ └── settings.py # Pydantic settings
β”‚ β”œβ”€β”€ compliance/
β”‚ β”‚ β”œβ”€β”€ eu_ai_act.py # EU AI Act compliance
β”‚ β”‚ └── gdpr.py # GDPR compliance
β”‚ └── core/
β”‚ β”œβ”€β”€ auth.py # Authentication
β”‚ └── exceptions.py # Exception hierarchy
β”œβ”€β”€ mcp-servers/
β”‚ β”œβ”€β”€ erp-gateway/
β”‚ β”‚ β”œβ”€β”€ sap_adapter.py # SAP S/4HANA adapter (891 lines)
β”‚ β”‚ β”œβ”€β”€ odoo_adapter.py # Odoo adapter (832 lines)
β”‚ β”‚ β”œβ”€β”€ models.py # Shared Pydantic models
β”‚ β”‚ └── server.py # MCP server
β”‚ β”œβ”€β”€ government-portal/ # German gov integration
β”‚ └── trade-solutions/ # Customs & logistics
β”œβ”€β”€ tests/ # 175 tests
β”‚ β”œβ”€β”€ test_hs_classifier.py # 37 tests
β”‚ β”œβ”€β”€ test_sanctions.py # 26 tests
β”‚ β”œβ”€β”€ test_pdf_parser.py # 33 tests
β”‚ β”œβ”€β”€ test_dashboard.py # 31 tests
β”‚ β”œβ”€β”€ test_sanctions_scheduler.py # 14 tests
β”‚ └── test_erp_integrations.py # 34 tests
β”œβ”€β”€ frontend-nextjs/ # Next.js 14 frontend
β”œβ”€β”€ Dockerfile.vgtc # Multi-stage Docker build
β”œβ”€β”€ .github/workflows/
β”‚ └── keep-alive.yml # Render keep-alive (every 25 min)
└── docs/
β”œβ”€β”€ DEPLOYMENT_CLOUDFLARE_PAGES.md
└── DEPLOYMENT_BACKEND_DOCKER.md
```
---
## API Endpoints
| Method | Path | Description | Auth |
|:-------|:-----|:------------|:-----|
| `POST` | `/api/v1/compliance/check` | Full pipeline (PDF β†’ classify β†’ screen) | Bearer + Tenant |
| `POST` | `/api/v1/integration/sap/trigger` | SAP order β†’ compliance check | Bearer + Tenant |
| `POST` | `/api/v1/integration/odoo/trigger` | Odoo invoice β†’ compliance check | Bearer + Tenant |
| `GET` | `/api/v1/dashboard/queue` | Review queue (paginated) | Bearer + Tenant |
| `POST` | `/api/v1/dashboard/action/{item_id}` | Approve/reject/request_info | Bearer + Tenant |
| `GET` | `/docs` | Swagger UI | None |
| `GET` | `/health` | Health check | None |
---
## Data Sources
| Source | Coverage | License | Cost |
|:-------|:---------|:--------|:-----|
| OFAC SDN | US Specially Designated Nationals | Public Domain | Free |
| EU Consolidated | EU Sanctions List | Open Data | Free |
| pyhscodes | 6,940+ WCO HS Codes | LGPL-2.1 | Free |
| UK HMT OFSI | UK Sanctions | Open Government | Free |
| UNSC | UN Security Council | UN Open Data | Free |
**Note:** OpenSanctions (CC BY-NC) is NOT used β€” commercial use requires paid license ($3,000+/year). All sanctions data is sourced directly from government databases (public domain).
---
## Development
```bash
# Run tests
python -m pytest tests/ -x -q
# Run specific engine tests
python -m pytest tests/test_hs_classifier.py -x -q
python -m pytest tests/test_sanctions.py -x -q
python -m pytest tests/test_erp_integrations.py -x -q
# Start dev server
uvicorn hermes.api.server:server --reload --port 8000
```
---
## Deployment
**Backend (Render):**
```bash
docker build -f Dockerfile.vgtc -t vgtc .
docker run -p 8000:8000 vgtc
```
- Auto-deployed from `main` branch
- Keep-alive via GitHub Actions (every 25 min)
- Auto-SSL, 512 MB RAM, shared CPU
**Frontend (Cloudflare Pages):**
- Static HTML from `frontend-nextjs/out/`
- Custom domain: `vgtc.voraprotocol.com`
- Global CDN, DDoS protection
---
## Roadmap
- [x] HS code classification (pyhscodes + LLM)
- [x] Sanctions screening (OFAC + EU local engine)
- [x] PDF parsing (pypdf, AGPL-free)
- [x] FastAPI server with auth
- [x] Compliance dashboard (PostgreSQL-backed)
- [x] SAP S/4HANA integration
- [x] Odoo integration
- [x] Async batch classification (Semaphore-5)
- [x] Semantic caching (memory + DB)
- [x] SHA-256 audit trail
- [x] Docker deployment
- [x] Cloudflare Pages frontend
- [x] Render.com backend
- [x] 175 tests passing
- [ ] PDF report generation
- [ ] EU TARIC live duty rates
- [ ] Multi-language support
- [ ] Webhook notifications
- [ ] SSO / SAML integration
---
## License
**Source Available License**
Code is visible for review. Commercial use requires written permission.
Built by [Ved Kumar](https://github.com/mysterious75) β€’ vedkumar755@gmail.com
[![GitHub](https://img.shields.io/badge/GitHub-Medium-181717?style=for-the-badge&logo=github)](https://github.com/mysterious75/VGTC)
</div>