# nlakhoa/aave-v3-origin architecture

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

- Interactive diagram: https://gitdiagram.com/nlakhoa/aave-v3-origin
- Repository: https://github.com/nlakhoa/aave-v3-origin

## Overview

##### Components
- Protocol Contracts: In the src/contracts directory you have the core protocol elements. This includes protocol configuration, the lending pool, tokenization mechanics, rewards, and treasury contracts.
- Extensions: Components that extend the basic protocol are in directories like src/contracts/extensions (including paraswap-adapters, stata-token, and v3-config-engine) that provide additional functionality or integrations.
- Dependencies & Libraries: Under src/contracts/dependencies you see integrations with external libraries (e.g., OpenZeppelin, Chainlink, Gnosis, and WETH). These support the security and utility functions within the protocol.
- Verification & Formal Methods: The certora directory is subdivided into basic, deprecated, and stata components. These contain harnesses, configuration files (the “conf” folders), patch files, and specification files used for formal verification. This is a critical layer for ensuring contract correctness.
- Testing & Deployment: The tests directory houses unit tests and integration tests for each part of the protocol, along with deployment scripts in src/deployments that handle configuration procedures and utility functions.
- Audit & Documentation: The audits folder holds multiple external audit reports, and the docs folder (and report directory) provides key technical papers and feature summaries. Although these are not "active" system components, they are essential for understanding architectural decisions and security measures.

##### Out Component Relationships
- “Core Protocol” block representing the lending pool, configuration, tokenization, and rewards logic.
- “Extensions” block representing modules that enhance or adapt the protocol (paraswap adapters, stata-token, v3-config-engine).
- “Dependencies & Libraries” block illustrating external contracts, utility libraries, and open-source dependencies (OpenZeppelin, Chainlink, etc.).
- “Formal Verification” block showing the Certora verification setups (basic, deprecated, stata) including harnesses and spec files.
- “Testing & Deployment” block covering tests, deployment procedures, and build scripts (Makefile, Foundry, npm-based scripts).
- “Audits & Documentation” block that, while not runtime components, provide context for security audits and technical guidance.
- For example, the “Core Protocol” interacts with “Dependencies & Libraries” (to access audited and proven routines).
- “Extensions” plug into the “Core Protocol” by adding functionality.
- “Formal Verification” is applied to both “Core Protocol” and “Extensions” ensuring correct behavior.
- “Testing & Deployment” serves all live contracts through continuous integration (as indicated by the GitHub workflows).

##### Architectural Patterns & Design Principles
- Separation of Concerns: Clearly demarcate between protocol logic, extensions, and verification layers.
- Modularity: The file tree indicates a modular design with distinct directories for tests, deployments, and verification specifications.
- Upgradability: Pay attention to the “upgradeability” dependencies and Aave-specific upgrade patterns present in src/contracts/misc/aave-upgradeability.
- Formal Verification: The Certora and audit directories underscore a strong focus on correctness and security properties.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Aave V3.2 Origin – Foundry-based Protocol"
        %% Core Protocol Contracts Subgraph
        subgraph "Core Protocol Contracts"
            PC["Protocol Contracts"]:::core
            PCFG["Protocol Configuration"]:::core
            TKN["Tokenization Module"]:::core
            RWD["Rewards System"]:::core
            TRSY["Treasury Contracts"]:::core
            UPGR["Aave Upgradeability Mechanism"]:::core
        end

        %% Extensions & Adapters Subgraph
        subgraph "Extensions & Adapters"
            PS["Paraswap Adapters"]:::extension
            ST["Stata Token"]:::extension
            VC["V3 Config Engine"]:::extension
        end

        %% Dependencies & Libraries Subgraph
        subgraph "Dependencies & Libraries"
            DEP["External Libraries"]:::dependency
        end

        %% Formal Verification Subgraph
        subgraph "Formal Verification"
            VERB["Certora - Basic"]:::verification
            VERD["Certora - Deprecated"]:::verification
            VERS["Certora - Stata"]:::verification
        end

        %% Testing & Deployment Subgraph
        subgraph "Testing & Deployment"
            TST["Tests"]:::testing
            DS["Deployment Scripts"]:::testing
        end

        %% Audits & Documentation Subgraph
        subgraph "Audits & Documentation"
            AUD["Audit Reports"]:::audit
            DOC["Documentation & Reports"]:::audit
        end
    end

    %% Internal Core Protocol chain
    PC -->|"init"| PCFG
    PCFG -->|"chain"| TKN
    TKN -->|"chain"| RWD
    RWD -->|"chain"| TRSY
    TRSY -->|"chain"| UPGR

    %% External Dependencies to Core Protocol
    DEP -->|"depends"| PCFG

    %% Extensions integration into Core Protocol
    PS -->|"integrates"| PCFG
    ST -->|"integrates"| PCFG
    VC -->|"integrates"| PCFG

    %% Formal Verification applied to Core Protocol
    VERB -->|"verifies"| PCFG
    VERD -->|"verifies"| PCFG
    VERS -->|"verifies"| PCFG

    %% Testing & Deployment interacts with Core Protocol
    TST -->|"tests"| PCFG
    DS -->|"deploys"| PCFG

    %% Audits & Documentation provide guidance for Core Protocol
    AUD -->|"audits"| PCFG
    DOC -->|"documents"| PCFG

    %% Click Events
    click PC "https://github.com/nlakhoa/aave-v3-origin/tree/main/src/contracts/protocol"
    click PCFG "https://github.com/nlakhoa/aave-v3-origin/tree/main/src/contracts/protocol/configuration"
    click TKN "https://github.com/nlakhoa/aave-v3-origin/tree/main/src/contracts/protocol/tokenization"
    click RWD "https://github.com/nlakhoa/aave-v3-origin/tree/main/src/contracts/rewards"
    click TRSY "https://github.com/nlakhoa/aave-v3-origin/tree/main/src/contracts/treasury"
    click UPGR "https://github.com/nlakhoa/aave-v3-origin/tree/main/src/contracts/misc/aave-upgradeability"
    click PS "https://github.com/nlakhoa/aave-v3-origin/tree/main/src/contracts/extensions/paraswap-adapters"
    click ST "https://github.com/nlakhoa/aave-v3-origin/tree/main/src/contracts/extensions/stata-token"
    click VC "https://github.com/nlakhoa/aave-v3-origin/tree/main/src/contracts/extensions/v3-config-engine"
    click DEP "https://github.com/nlakhoa/aave-v3-origin/tree/main/src/contracts/dependencies"
    click VERB "https://github.com/nlakhoa/aave-v3-origin/tree/main/certora/basic"
    click VERD "https://github.com/nlakhoa/aave-v3-origin/tree/main/certora/deprecated"
    click VERS "https://github.com/nlakhoa/aave-v3-origin/tree/main/certora/stata"
    click TST "https://github.com/nlakhoa/aave-v3-origin/tree/main/tests"
    click DS "https://github.com/nlakhoa/aave-v3-origin/tree/main/src/deployments"
    click AUD "https://github.com/nlakhoa/aave-v3-origin/tree/main/audits"
    click DOC "https://github.com/nlakhoa/aave-v3-origin/tree/main/docs"

%% Styles
classDef core fill:#ffe6e6,stroke:#b30000,stroke-width:2px;
classDef extension fill:#e6f7ff,stroke:#0055cc,stroke-width:2px;
classDef dependency fill:#ffffcc,stroke:#999900,stroke-width:2px;
classDef verification fill:#e6ffe6,stroke:#008000,stroke-width:2px;
classDef testing fill:#ffe6ff,stroke:#cc0099,stroke-width:2px;
classDef audit fill:#f2f2f2,stroke:#666666,stroke-width:2px;
```
