# circlefin/refund-protocol architecture

> Architecture diagram of the GitHub repository circlefin/refund-protocol, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/circlefin/refund-protocol
- Repository: https://github.com/circlefin/refund-protocol

## Overview

##### Project Type and Purpose
- This is a smart-contract protocol (library) written in Solidity using Foundry.
- The project “Refund Protocol” implements a non-custodial refund/chargeback mechanism on Ethereum (or EVM chains) via an arbiter system.

##### File Structure Analysis
- Top-level:
- `.github/`: CI pipeline (`ci.yaml`) that runs `forge build`, `forge test`, etc.
- `lib/`: submodule libraries (`forge-std`, `openzeppelin-contracts`).
- `src/`: your Solidity contracts (core protocol code).
- `test/`: Foundry tests verifying protocol logic.
- `foundry.toml`, `remappings.txt`: Foundry configuration & dependency remapping.
- No frontend or off-chain service code in this repo; the focus is purely on on-chain protocol logic and test automation.

##### Key Components
a. On-Chain Environment (Ethereum/EVM)
- Core `RefundManager` (or equivalent) contract
- `Arbiter` or dispute-resolution contract
- External ERC-20 Token Contract
- e.g., USDC/USDT stablecoin
- OpenZeppelin Contracts (inheritance/utilities)
- Forge-Std Library (testing helpers, mocks)
b. Off-Chain Actors & Tools
- Payment Sender (EOA)
- Payment Receiver (EOA)
- Arbiter (EOA or multi-sig)
- CI/CD Pipeline (.github/workflows/ci.yaml running Foundry)
- Developer’s Local Machine (Foundry CLI)

##### Relationships & Data Flows
- Sender/Receiver initiate dispute by calling contract functions.
- Arbiter listens to on-chain events (e.g., `DisputeCreated`) and calls `resolveDispute()`.
- Dependency Flow: Your contracts extend OpenZeppelin modules; tests import forge-std mocks.

##### Architectural Patterns & Principles
- Modular Contracts: split core logic and dispute-resolution logic.
- Non-custodial Design: funds never leave the protocol contract except by explicit function calls.
- Event-Driven Off-Chain Arbitration: use Solidity events to notify arbiters.
- CI/CD Integration: automated build/test via GitHub Actions.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% On-Chain Layer
    subgraph "Blockchain (Ethereum/EVM)"
        direction TB
        RM["RefundManager"]:::onchain
        AM["ArbiterModule"]:::onchain
        ET["ExternalToken (ERC-20)"]:::onchain
        OZ["OpenZeppelin Contracts"]:::library
    end

    %% Off-Chain Actors
    subgraph "Off-Chain Actors & Tools"
        direction TB
        PS["Payment Sender (EOA)"]:::offchain
        PR["Payment Receiver (EOA)"]:::offchain
        AR["Arbiter (EOA/Multi-sig)"]:::offchain
        DT["Developer Local (Foundry CLI)"]:::offchain
    end

    %% CI/CD Layer
    CI["CI Runner"]:::cicd
    FC["Foundry Config"]:::cicd
    RMm["Remappings"]:::cicd
    GM["Git Submodules"]:::cicd

    %% Relationships - Token Flow
    PS -->|"lockFunds()"| RM
    RM -->|"transferFrom()/approve()"| ET
    RM -->|"transfer() token"| PR
    AR -->|"resolveDispute()"| AM
    AM -->|"resolveOnChain()"| RM

    %% Relationships - Control Flow
    PS -->|"createDispute()"| AM
    PR -->|"raiseDispute()"| AM
    AM -->|"emit DisputeCreated"| AR

    %% Developer & CI Interactions
    DT -->|"forge build/test"| RM
    CI -->|"runs ci.yaml"| DT
    CI -->|"forge build/test"| RM

    %% Dependency Flows
    RM -->|"inherits/utilities"| OZ
    AM -->|"inherits/utilities"| OZ
    TestSuite["Tests"]:::test -->|"import mocks/util"| ForgeStd["Forge-Std"]:::library
    TestSuite -->|"import OZ modules"| OZ

    %% Click Events
    click RM "https://github.com/circlefin/refund-protocol/blob/master/src/RefundManager.sol"
    click AM "https://github.com/circlefin/refund-protocol/blob/master/src/ArbiterModule.sol"
    click ET "https://github.com/circlefin/refund-protocol/blob/master/src/interfaces/IERC20.sol"
    click OZ "https://github.com/circlefin/refund-protocol/tree/master/lib/openzeppelin-contracts/"
    click ForgeStd "https://github.com/circlefin/refund-protocol/tree/master/lib/forge-std/"
    click TestSuite "https://github.com/circlefin/refund-protocol/tree/master/test/"
    click CI "https://github.com/circlefin/refund-protocol/blob/master/ .github/workflows/ci.yaml"
    click FC "https://github.com/circlefin/refund-protocol/blob/master/foundry.toml"
    click RMm "https://github.com/circlefin/refund-protocol/blob/master/remappings.txt"
    click GM "https://github.com/circlefin/refund-protocol/blob/master/.gitmodules"

    %% Styles
    classDef onchain fill:#cce5ff,stroke:#0066cc,color:#003366
    classDef offchain fill:#d4edda,stroke:#28a745,color:#155724
    classDef cicd fill:#ffe5b4,stroke:#ff9900,color:#663300
    classDef library fill:#e2e3e5,stroke:#6c757d,color:#343a40
    classDef test fill:#f8d7da,stroke:#dc3545,color:#721c24
```
