System Architecture

Edge-Native
Sovereign Stack

Zero servers. Zero npm dependencies. Three worker modules totaling ~2,000 lines of pure JavaScript running on Cloudflare's global edge — backed by XRPL mainnet blockchain anchoring and IPFS content-addressed storage.

Architecture

System Diagram

┌───────────────────────────────────────────────────────────────┐ │ CLOUDFLARE EDGE LAYER │ │ Workers · Pages · KV · Workers AI · Cron Triggers │ │ docs.unykorn.org · Global CDN · TLS │ └──────────────────────────&boxt;────────────────────────────────────┘ ┌──────────────────────┴───────────────────────┐ ┌──────────────────────┐ ┌──────────────────────┐ │ CLOUDFLARE PAGES │ │ CLOUDFLARE WORKER │ │ Static Frontend │ │ doc-intel-api │ │ │ │ v2.1.0 │ │ 12 HTML Pages │ │ api.js (router) │ │ AI Hub · Company │ │ ai-agents.js (AI) │ │ Architecture · etc │ │ xrpl.js (chain) │ └──────────────────────┘ └────&boxt;─────&boxt;─────&boxt;─────┘ ┌────────────────────────────┘ ┌──────────────┐ ┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐ │ WORKERS AI │ │ XRPL MAINNET │ │ IPFS / KUBO │ │ LLM + Embeddings│ │ Blockchain │ │ v0.39.0 │ │ │ │ │ │ │ │ Llama 3.1 8B │ │ Ed25519 Signing │ │ Docker Container│ │ BGE Base v1.5 │ │ AccountSet+Memo │ │ Cloudflare Tun. │ │ 5 AI Agents │ │ Contract Proofs │ │ CID Anchoring │ └──────────────────┘ └──────────────────┘ └──────────────────┘ ┌──────────────────────┐ │ CLOUDFLARE KV │ │ DOC_INTEL_KV │ │ │ │ Contract Proofs │ │ Company Profiles │ │ RAG Embeddings │ │ Session Data │ └──────────────────────┘
Intelligence Layer

6-Agent AI Pipeline

Every document passes through a multi-agent chain — each agent is purpose-built with its own system prompt, temperature, and validation logic.

🔍 Agent 1

Extractor

Reads raw document text, extracts ALL structured fields into clean JSON — parties, dates, financial terms, risk flags, jurisdiction.

📝 Agent 2

Drafter

Generates professional legal documents from 13 templates with company profile injection, governing law, signature blocks, and compliance language.

⚖️ Agent 3

Compliance

Reviews against ESIGN, UETA, SEC Reg D, FINRA rules, KYC/AML, CCPA/GDPR. Max 8 findings, CRITICAL-first severity ordering.

✅ Agent 4

Reviewer

Final quality pass — catches issues other agents missed. Checks completeness, internal consistency, legal soundness, and enforceability.

💬 Agent 5

Chat

Conversational interface with full RAG context. Answers questions about uploaded documents, explains clauses, suggests improvements.

🏦 Agent 6

Capital Compliance

Specialized banking & trade finance review. Validates against UCC Article 5/9, ICC UCP 600, ISP98, URDG 758, Basel III/IV, SEC 144/144A, ISDA, Dodd-Frank, AML/BSA, OFAC.

Proof Pipeline

Contract Anchoring — 8 Steps

Every generated contract is cryptographically fingerprinted and anchored to the XRPL mainnet blockchain. Immutable. Verifiable. Sovereign.

#StageOperationOutput
01InputAccept PDF upload, text input, or template selection via AI HubRaw Content
02AI GenerateDrafter Agent produces document from template + company profile + instructionsContract Text
03ComplianceCompliance Agent reviews for ESIGN/UETA/SEC/FINRA — flags issues by severityReviewed
04SHA-256 HashDeterministic fingerprint of contract content → 64-char hex hashHash + Contract ID
05XRPL AnchorAccountSet transaction with structured Memo (v2 format) signed via Ed25519TX Hash
06KV StoreDual-indexed proof record: by contract_id and by hash (reverse lookup)Proof Record
07IPFS PinContent-addressed push to Kubo node via Cloudflare TunnelCID
08VerifyPublic verification via /api/contract/verify?id= or ?hash= — full proof chainImmutable
Module Inventory

3 Worker Modules · ~2,000 Lines · Zero Dependencies

api.js · ~1,100 lines

API Router

20+ endpoint handlers, CORS, request routing, cron self-healing queue, health monitoring. Routes: /api/health, /api/ai/generate, /api/ai/extract, /api/ai/comply, /api/ai/chat, /api/batch, /api/contract/verify, /api/contract/list, /api/company/*, /api/anchor/*, and more.

ai-agents.js · ~750 lines

AI Agent System

6 agents (Extractor, Drafter, Compliance, Reviewer, Chat, Capital Compliance), 13 document templates (8 standard + 5 capital instruments), RAG pipeline with embeddings, company profiles, contract hashing + proof storage, capital compliance review with banking/UCC/ICC/Basel expertise.

xrpl.js · ~312 lines

XRPL Blockchain

Pure JavaScript XRPL binary codec + Ed25519 signing. Zero npm dependencies. Builds, signs, and submits AccountSet transactions with structured Memo payloads to XRPL mainnet. Self-contained cryptographic stack.

Templates

13 Document Templates

Each template defines required fields and injects company profile data automatically.

TemplateDescriptionKey Fields
Standard Templates
NDANon-Disclosure Agreementparties, effective_date, confidentiality_period, jurisdiction
LOILetter of Intentparties, transaction_description, exclusivity_period, due_diligence
SUBSCRIPTIONSecurities Subscription (Reg D)investment_amount, security_type, accreditation_status, risk_acknowledgment
CONSULTINGProfessional Services Engagementscope_of_work, compensation, term, ip_ownership, non_compete
TERM_SHEETInvestment / Deal Termsvaluation, investment_amount, equity_percentage, liquidation_preference
SIDE_LETTERSupplemental Agreementreference_agreement, modifications, effective_date
BROKER_AGREEMENTCommission / Referral Arrangementcommission_rate, payment_terms, exclusivity, finra_disclosures
OPERATING_AGREEMENTLLC Governancemembers, capital_contributions, profit_distribution, management_structure
🏦 Capital Instruments
SBLCStandby Letter of Creditissuing_bank, beneficiary, amount, expiry_date, icc_reference
MTNMedium Term Noteissuer, face_value, coupon_rate, maturity_date, isin
CAPITAL_TERM_SHEETPre-Funding Capital Termsinstrument_type, principal_amount, yield, term, governing_law
FUNDING_RIDERSupplemental Funding Mechanicsfunding_source, disbursement_schedule, conditions_precedent
COLLATERAL_VERIFICATIONThird-Party Asset Verificationasset_description, custodian, verification_method, valuation_date
Infrastructure

All Edge. All Serverless.

ServiceTechnologyExposure
Worker APICloudflare Workers · doc-intel-api v2.3.0docs.unykorn.org/api/*
Pages FrontendCloudflare Pages · 12 static HTML pagesdocs.unykorn.org
Workers AILlama 3.1 8B (chat) · BGE Base v1.5 (embed)Internal binding
KV StoreCloudflare KV · DOC_INTEL_KVInternal binding
XRPL MainnetPure JS Ed25519 · AccountSet + Memos1.ripple.com (submit)
IPFS NodeKubo v0.39.0 · Docker · gtp_ipfsCloudflare Tunnel
Cron Trigger*/5 * * * * · Self-healing anchor queueInternal trigger

No origin servers. No npm dependencies. No Docker in production. The Worker runs entirely on Cloudflare's global edge network. IPFS node is tunneled through Cloudflare for sovereignty anchoring only.

API Surface

20+ Endpoints

MethodEndpointPurpose
GET/api/healthSystem health, version, service connectivity
POST/api/ai/generateGenerate document + auto-anchor to XRPL
POST/api/ai/extractAI extraction of structured fields from document
POST/api/ai/complyCompliance review (ESIGN/UETA/SEC/FINRA) — auto-routes capital types
POST/api/ai/capital-complyCapital compliance (UCC/ICC/Basel/ISDA/OFAC)
POST/api/ai/scoreDeterministic 0–100 compliance score + grade + risk level
POST/api/ai/chatConversational chat with RAG context
POST/api/batchBatch document generation + per-doc anchoring
GET/api/contract/verifyVerify contract proof by ID or hash
GET/api/contract/listList all anchored contract proofs
POST/api/companySave company profile for template injection
GET/api/company/:idRetrieve company profile
POST/api/anchorDirect XRPL anchor (manual)
POST/api/anchor/ipfsIPFS pin + XRPL dual anchor