# graphprotocol/contracts architecture

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

- Interactive diagram: https://gitdiagram.com/graphprotocol/contracts
- Repository: https://github.com/graphprotocol/contracts

## Overview

##### Main Components
- Smart Contracts: This includes the primary “contracts” package. It features numerous subdirectories (like “arbitrum”, “staking”, “governance”, “l2”, etc.) which represent different aspects of the protocol operations on-chain. Also include “token-distribution” since it manages token locks and distributions.
- Data Edge: Represented by the “data-edge” package, this component appears to handle event processing, custom tasks (like bridging events and working with calldata), and may be responsible for interfacing between on-chain events and off-chain indexing or analytics.
- SDK: The “sdk” package is the TypeScript-based interface used to interact with the protocol’s contracts. It covers deployments, network interactions, wrappers around the contracts, and helper utilities.
- Developer Tooling and Configurations: Include “eslint-graph-config” and “solhint-graph-config” as shared linting/formatting utilities to enforce consistent code style in TypeScript and Solidity, respectively.
- CI/CD Infrastructure: Although not part of the “runtime” system, the GitHub workflows in “.github” (build, tests, publish, deployment verification) are essential to the overall system. They ensure continuous integration, testing (via Mocha, Hardhat, etc.), deployment, and versioning (using Changesets).

- That the contracts (on-chain components) are deployed to different networks (Ethereum, Arbitrum, etc.) and are used by both the SDK and Token Distribution modules.
- That the Data Edge package listens to blockchain events (emitted by the contracts) and may interact with other off-chain services to provide indexing.
- Demonstrate that the SDK is a middleware layer that eases contract interaction and deployment (using scripts, tasks, and network deployment ‘actions’ included in the repository).

##### Architectural Patterns
- Monorepo Structure: Emphasize that all packages share dependencies and versioning via Yarn workspaces.
- Modularization: The separation into discrete packages (contracts, sdk, token-distribution, etc.) allows clear boundaries between on-chain logic, off-chain services, and developer tools.
- CI/CD and Versioning: The use of Changesets for version management and GitHub workflows for automated testing, building, and deployment.
- Blockchain Interaction: A clear delineation of how smart contracts (with audits and tests in their subdirectories) interact with deployment scripts, SDK interfaces, and proxy/upgrades support.

## Diagram (Mermaid)

```mermaid
graph TB
    A["Yarn Workspaces Monorepo"]:::repo

    subgraph "On-chain Components"
        SC["Smart Contracts (contracts)"]:::onChain
        TD["Token Distribution (token-distribution)"]:::onChain
    end

    subgraph "Off-chain Components"
        SDK["SDK (sdk)"]:::offChain
        DE["Data Edge (data-edge)"]:::offChain
    end

    subgraph "Developer Tools & CI/CD"
        ESL["TypeScript Linting (eslint-graph-config)"]:::devTools
        SOL["Solidity Linting (solhint-graph-config)"]:::devTools
        subgraph "CI/CD Infrastructure"
            GH["GitHub Workflows (.github/workflows)"]:::devTools
            CS["Changesets (.changeset)"]:::devTools
            HUS["Commit Hooks (.husky)"]:::devTools
        end
    end

    %% Monorepo connections to components
    A --> SC
    A --> TD
    A --> SDK
    A --> DE
    A --> ESL
    A --> SOL
    A --> GH

    %% Inter-component interactions
    SDK -->|"calls"| SC
    SDK -->|"interacts"| TD
    SC -->|"emits_events"| DE
    GH -->|"builds_and_deploys"| SC
    GH -->|"builds_and_deploys"| TD
    GH -->|"builds_and_deploys"| SDK
    GH -->|"builds_and_deploys"| DE

    %% Class definitions for colors and styles
    classDef repo fill:#ffffcc,stroke:#999900,stroke-width:2px;
    classDef onChain fill:#ffcccc,stroke:#990000,stroke-width:2px;
    classDef offChain fill:#ccffcc,stroke:#009900,stroke-width:2px;
    classDef devTools fill:#ccccff,stroke:#000099,stroke-width:2px;

    %% Click Events
    click SC "https://github.com/graphprotocol/contracts/tree/main/packages/contracts"
    click TD "https://github.com/graphprotocol/contracts/tree/main/packages/token-distribution"
    click DE "https://github.com/graphprotocol/contracts/tree/main/packages/data-edge"
    click SDK "https://github.com/graphprotocol/contracts/tree/main/packages/sdk"
    click ESL "https://github.com/graphprotocol/contracts/tree/main/packages/eslint-graph-config"
    click SOL "https://github.com/graphprotocol/contracts/tree/main/packages/solhint-graph-config"
    click GH "https://github.com/graphprotocol/contracts/tree/main/.github/workflows"
    click CS "https://github.com/graphprotocol/contracts/blob/main/.changeset"
    click HUS "https://github.com/graphprotocol/contracts/blob/main/.husky"
```
