Architecture
Architecture
RefundKit uses a 3-layer architecture that separates AI agent integrations from core business logic and external payment providers.
Overview
┌─────────────────────────────────────────┐
│ Layer 1: AI Agents & Protocols │
│ Shopping Agents · Agent Frameworks │
│ Commerce Protocols · Support Agents │
│ │
│ ┌──────┐ ┌──────┐ ┌──────────┐ │
│ │ MCP │ │ SDK │ │ REST API │ │
│ │Server│ │(TS) │ │ (HTTP) │ │
│ └──┬───┘ └──┬───┘ └────┬─────┘ │
├─────┼─────────┼───────────┼────────────┤
│ └─────────┴───────────┘ │
│ Layer 2: RefundKit Core │
│ │
│ ┌──────────┐ ┌──────────────────┐ │
│ │ Policy │ │ Return Lifecycle │ │
│ │ Engine │ │ Management │ │
│ └──────────┘ └──────────────────┘ │
│ ┌──────────┐ ┌──────────────────┐ │
│ │ Fraud & │ │ Approval │ │
│ │ Disputes │ │ Workflows │ │
│ └──────────┘ └──────────────────┘ │
│ ┌──────────┐ ┌──────────────────┐ │
│ │ Webhook │ │ Processor │ │
│ │ System │ │ Router │ │
│ └──────────┘ └──────────────────┘ │
├────────────────────────────────────────┤
│ Layer 3: Payment Providers │
│ ┌────────┐ ┌────────┐ ┌────────┐ │
│ │ Stripe │ │ Square │ │ More │ │
│ └────────┘ └────────┘ └────────┘ │
│ │
│ ┌─────────────────────────────────┐ │
│ │ Supabase (PostgreSQL) │ │
│ └─────────────────────────────────┘ │
└────────────────────────────────────────┘
Layer 1: AI Agents & Protocols
The consumption layer. AI agents interact with RefundKit through three interfaces:
- MCP Server — 12 tools via Model Context Protocol (stdio or SSE transport)
- TypeScript SDK — Direct integration for Node.js/TypeScript applications
- REST API — HTTP endpoints at
api.refundkit.dev/v1
All three interfaces return the same { data, error } response shape.
Layer 2: RefundKit Core
The business logic layer. All decisions are made here:
| Module | Purpose | |--------|---------| | Policy Engine | Evaluates eligibility against merchant rules | | Return Lifecycle | Manages RMA generation, state machine, shipment tracking | | Fraud & Disputes | Multi-signal risk scoring and recommendations | | Approval Workflows | Human-in-the-loop review for high-value or risky refunds | | Webhook System | Event-driven notifications with HMAC-SHA256 signatures | | Processor Router | Auto-routes refunds to the correct payment processor |
Layer 3: Payment Providers
The execution layer. Processor adapters translate RefundKit operations into provider-specific API calls:
| Provider | Status | Capabilities | |----------|--------|-------------| | Stripe | Available | Full refund lifecycle, partial refunds, cancellation | | Square | Available | Refund processing, partial refunds (no cancellation) | | PayPal | Planned | — | | Adyen | Planned | — |
Data Flow: Refund Request
- Agent calls
refundkit_process_refund(MCP) orrk.refunds.create()(SDK) - Policy Engine checks eligibility against merchant rules
- Dispute Risk Engine scores the transaction
- If thresholds are exceeded, refund enters the Approval Queue
- Once approved, Processor Router selects the correct payment processor
- Processor adapter executes the refund with the payment provider
- Webhook System notifies subscribed endpoints of the status change
- Return is updated in Supabase (PostgreSQL)
Next Steps
- Quickstart — Get started with RefundKit.
- MCP Server — Connect AI agents to RefundKit.
- SDK Reference — Full SDK documentation.