# yearn/yearn-vaults architecture

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

- Interactive diagram: https://gitdiagram.com/yearn/yearn-vaults
- Repository: https://github.com/yearn/yearn-vaults

## Overview

Based on our review of the file structure and the README, this repository is dedicated to the development and deployment of smart contracts for Yearn Vaults – a key component of the Yearn Finance ecosystem. The project is not a full-stack web application but rather an on-chain protocol implementation that leverages Ethereum smart contracts (written in Vyper), deployment scripts (in Python using Brownie), and extensive testing suites.

##### Main Components
- Smart Contracts:
- Contracts in the “contracts” directory (e.g., Registry.vy, Vault.vy) as the core of the system.
- The inheritable template strategy (and possibly other strategy contracts) featured in the testing suites.
- Deployment & Management Tools:
- Brownie framework (brownie-config.yaml and brownie compile/test commands) that facilitates compilation, deployment, and testing of the contracts.
- Python scripts in the “scripts” directory (e.g., deploy.py, keep.py) that handle deployment and ongoing maintenance tasks.
- Test Suite:
- Integration tests, functional tests, and test configuration files in the “tests” directory that ensure the contracts behave as expected.
- Different testing layers (functional tests for individual components like base_fee_oracle, registry, strategy, vault and integration tests for cross-component behavior).
- CI/CD & Repository Maintenance:
- GitHub Actions workflows (found in .github/workflows) that enforce linting, testing, and release protocols.
- Commit linting, prettier configurations, and husky pre-commit hooks that ensure code quality.
- External Services & Dependencies:
- Ethereum network components like Ganache (for local development) and integration with providers like Infura and Etherscan (for deployment and verification).
- Dependencies in package.json and requirements-dev.txt that support both Node.js and Python environments.
- Developer Environment & Tooling:
- Tools and guides for setting up local environments (VSCode, Python 3.8, Node.js, Ganache, yarn, etc.).

##### Relationships and Data Flow
- Flow from the developer’s local environment (where setup and testing are performed) to the deployment phase (using Brownie) ending with the contracts deployed on the Ethereum blockchain.
- That the “scripts” and “contracts” interact closely: deployment scripts call upon smart contract artifacts.
- Test suites as an independent module that verifies the deployed contracts both in simulated networks (Ganache) and integrated environments.
- That the CI/CD system (GitHub workflows) automatically triggers scripts for testing and deployment, ensuring code quality before integration.

##### Architectural Patterns and Design Principles
- Modularity: The directory structure clearly separates concerns – contracts, scripts, tests, and configurations are all neatly compartmentalized.
- Reusable Components: A registry pattern is suggested by the “Registry.vy” contract and a template strategy, indicating extensibility.
- Automated Quality Gate: The integration of CI (with GitHub actions), code formatting, and linting emphasizes an automated and continuous integration approach.
- Test-Driven Development: The plurality of tests (functional and integration) underscores an architecture where reliability is ensured through automated testing.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Developer & CI Layer"
        devTools["Developer Tools (VSCode,Python,Node.js,Linting)"]:::dev
        ciCd["CI/CD (GitHubActions)"]:::ci
        testSuite["Test Suite (Functional&IntegrationTests)"]:::test
        husky["Pre-commit Hooks (.husky)"]:::ci
        commitlint["Commitlint (commitlint.config.js)"]:::ci
        prettierConfig["Prettier Config (.prettierrc.json)"]:::ci
        prettierIgnore["Prettier Ignore (.prettierignore)"]:::ci
    end

    subgraph "Smart Contract Core"
        brownie["Brownie Framework (Compilation,Deployment)"]:::core
        config["brownie-config.yaml (Configuration)"]:::config
        registry["Registry.vy (CoreContract)"]:::contract
        vault["Vault.vy (CoreContract)"]:::contract
        deployScr["deploy.py (DeploymentScript)"]:::script
        keepScr["keep.py (MaintenanceScript)"]:::script
    end

    subgraph "External Services & Dependencies"
        blockchain["EthereumBlockchain (Ganache,Mainnet/Testnets)"]:::external
        infura["Infura/Etherscan (Verification)"]:::external
        dependencies["Dependencies (package.json & requirements-dev.txt)"]:::external
    end

    devTools --> ciCd
    ciCd --> testSuite
    testSuite --> registry
    testSuite --> vault
    ciCd --> config
    config --> brownie
    brownie --> deployScr
    brownie --> keepScr
    deployScr --> blockchain
    keepScr --> blockchain
    blockchain --> infura
    devTools --> husky
    devTools --> commitlint
    devTools --> prettierConfig
    devTools --> prettierIgnore
    dependencies --> blockchain

    click registry "https://github.com/yearn/yearn-vaults/blob/master/contracts/Registry.vy"
    click vault "https://github.com/yearn/yearn-vaults/blob/master/contracts/Vault.vy"
    click config "https://github.com/yearn/yearn-vaults/blob/master/brownie-config.yaml"
    click deployScr "https://github.com/yearn/yearn-vaults/blob/master/scripts/deploy.py"
    click keepScr "https://github.com/yearn/yearn-vaults/blob/master/scripts/keep.py"
    click testSuite "https://github.com/yearn/yearn-vaults/tree/master/tests/"
    click ciCd "https://github.com/yearn/yearn-vaults/tree/master/.github/workflows/"
    click husky "https://github.com/yearn/yearn-vaults/tree/master/.husky/"
    click commitlint "https://github.com/yearn/yearn-vaults/blob/master/commitlint.config.js"
    click prettierConfig "https://github.com/yearn/yearn-vaults/blob/master/.prettierrc.json"
    click prettierIgnore "https://github.com/yearn/yearn-vaults/blob/master/.prettierignore"
    click dependencies "https://github.com/yearn/yearn-vaults/blob/master/package.json"
    click dependencies "https://github.com/yearn/yearn-vaults/blob/master/requirements-dev.txt"

    classDef dev fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef ci fill:#A9DFBF,stroke:#145A32,stroke-width:2px;
    classDef test fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef core fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
    classDef contract fill:#FAD7A0,stroke:#7D6608,stroke-width:2px;
    classDef script fill:#D2B4DE,stroke:#4A235A,stroke-width:2px;
    classDef config fill:#85C1E9,stroke:#1B4F72,stroke-width:2px;
    classDef external fill:#D5F5E3,stroke:#1E8449,stroke-width:2px;
```
