# muhammadjehanzaib/defi-stablecoin architecture

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

- Interactive diagram: https://gitdiagram.com/muhammadjehanzaib/defi-stablecoin
- Repository: https://github.com/muhammadjehanzaib/defi-stablecoin

## Overview

##### Project type and purpose
- This is a Foundry-based Solidity project implementing an algorithmic, exogenously-collateralized stablecoin pegged to $1. It uses Chainlink Price Feeds for on-chain oracle data, allows users to exchange ETH and BTC for the stablecoin, and features decentralized minting and burning mechanisms.

##### File structure
- Top-level files:
- foundry.toml – Foundry config (compiler, paths, network settings)
- .gitmodules – Git submodule links to external smart-contract libraries
- README.md – Project goals and mechanisms
- Directories:
- src/ – Core Solidity contracts
– Libraries/ – Helper contracts and shared logic modules
- lib/ – Submodules with external dependencies
– openzeppelin-contracts/
– chainlink-brownie-contracts/
– forge-std/
- script/ – Deployment and management scripts (Forge scripts)
- test/ – Unit tests, fuzz tests, mock contracts

##### README for additional insights
- Peg mechanism: anchored to $1 via Chainlink price feeds
- Exchange function: swap ETH & BTC for stablecoin at real‐time price
- Minting: algorithmic, decentralized stability mechanism
- Collateral: exogenous crypto (users deposit ETH/BTC)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User
    User["Externally Owned Account (User)"]:::user

    %% On-Chain Contracts
    subgraph "On-Chain Contracts" 
        Stablecoin["Stablecoin Contract"]:::smartcontract
        CollateralVault["Collateral Vault Contract"]:::smartcontract
        PriceConsumer["Chainlink Price Feed Oracle Consumer"]:::external
    end

    %% Libraries & Dependencies
    subgraph "Libraries & Dependencies"
        Libraries["Library Modules"]:::smartcontract
        OZ["OpenZeppelin ERC-20 Foundations"]:::external
        ChainlinkLib["Chainlink Oracle Interfaces"]:::external
        ForgeStd["Forge-Std Utilities"]:::external
    end

    %% Off-Chain Scripts
    subgraph "Off-Chain Scripts"
        Scripts["Deployment & Management Scripts"]:::scripts
    end

    %% Testing Harness
    subgraph "Testing Harness"
        Mocks["Mock Oracles & Contracts"]:::tests
        FuzzTests["Fuzz Tests"]:::tests
        UnitTests["Unit Tests"]:::tests
    end

    %% Interactions
    User -->|"mint(amount), burn(amount), swapCollateral()"| Stablecoin
    Stablecoin -->|"fetchLatestPrice()"| PriceConsumer
    Stablecoin -->|"lock/release collateral"| CollateralVault
    Scripts -->|"deploy, configure oracles, upgrade"| Stablecoin

    Mocks -->|"simulate oracles"| Stablecoin
    FuzzTests -->|"run fuzz tests"| Stablecoin
    UnitTests -->|"run unit tests"| Stablecoin

    %% Library relations
    Stablecoin -->|"uses"| Libraries
    Libraries -->|"imports from"| OZ
    Stablecoin -->|"imports from"| ChainlinkLib
    Mocks -->|"uses testing utils"| ForgeStd
    FuzzTests -->|"uses testing utils"| ForgeStd
    UnitTests -->|"uses testing utils"| ForgeStd

    %% Click Events
    click Stablecoin "https://github.com/muhammadjehanzaib/defi-stablecoin/blob/main/src/Stablecoin.sol"
    click CollateralVault "https://github.com/muhammadjehanzaib/defi-stablecoin/blob/main/src/CollateralVault.sol"
    click PriceConsumer "https://github.com/muhammadjehanzaib/defi-stablecoin/blob/main/src/ChainlinkPriceConsumer.sol"
    click Libraries "https://github.com/muhammadjehanzaib/defi-stablecoin/tree/main/src/Libraries/"
    click OZ "https://github.com/muhammadjehanzaib/defi-stablecoin/tree/main/lib/openzeppelin-contracts/"
    click ChainlinkLib "https://github.com/muhammadjehanzaib/defi-stablecoin/tree/main/lib/chainlink-brownie-contracts/"
    click ForgeStd "https://github.com/muhammadjehanzaib/defi-stablecoin/tree/main/lib/forge-std/"
    click Scripts "https://github.com/muhammadjehanzaib/defi-stablecoin/tree/main/script/"
    click Mocks "https://github.com/muhammadjehanzaib/defi-stablecoin/tree/main/test/Mocks/"
    click FuzzTests "https://github.com/muhammadjehanzaib/defi-stablecoin/tree/main/test/fuzz/"
    click UnitTests "https://github.com/muhammadjehanzaib/defi-stablecoin/tree/main/test/unit/"

    %% Styles
    classDef smartcontract fill:#9f6,stroke:#333,stroke-width:1px
    classDef external fill:#f96,stroke:#333,stroke-width:1px
    classDef user fill:#6cf,stroke:#333,stroke-width:1px
    classDef scripts fill:#c9f,stroke:#333,stroke-width:1px
    classDef tests fill:#aaa,stroke:#333,stroke-width:1px
```
