# superfluid-finance/protocol-monorepo architecture

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

- Interactive diagram: https://gitdiagram.com/superfluid-finance/protocol-monorepo
- Repository: https://github.com/superfluid-finance/protocol-monorepo

## Overview

##### And Map the Main Components
- Ethereum Contracts: Represented in the “packages/ethereum-contracts” directory. These are the Solidity smart contracts implementing the core protocol logic and upgradeability. Include supporting folders like “contracts”, “test”, “audits”, and “deploy” scripts.
- SDK and Frameworks:
– SDK-Core (“packages/sdk-core”): A modern JavaScript/TypeScript interface for applications to interact with the protocol without direct Solidity knowledge.
– SDK-Redux (“packages/sdk-redux”): Tailored for React/Redux based front-end applications, incorporating RTK Query slices and state-management integrations.
– JS-SDK (“packages/js-sdk”): The older JavaScript SDK (now deprecated) that provides similar functionality.
- Testing and Fuzzing Tools: (“packages/hot-fuzz”) which harnesses tools like Echidna for fuzz testing smart contracts.
- Supporting/Utility Components: Other packages (for example spec-haskell, starknet-contracts, examples, tasks) that support additional testing/specification, deployment scripts, CI/CD configuration (GitHub workflows under .github), and helper tasks.

- How the Ethereum blockchain hosts the deployed contracts from the ethereum-contracts package.
- Deployment and development tooling (e.g., GitHub Actions workflows, Foundry/Hardhat configurations) as external flows that support continuous integration/deployment and testing.

##### Architectural Patterns & Design Principles
- Modularity and Separation of Concerns: Each package serves a distinct role in the ecosystem (contracts, indexing, SDKs, metadata, testing).
- Monorepo Structure: All these components are maintained within one repository to ensure synchronized versioning, shared infrastructure (like CI/CD in .github), and cross-package integration testing.

##### Technologies, Frameworks, and Libraries
- Smart Contracts & Development: Solidity, Foundry, Hardhat.
- SDKs and Front-End Integrations: JavaScript/TypeScript, React, Redux (RTK Query in sdk-redux).
- CI/CD and Testing: GitHub Actions (with multiple workflows), Echidna (via hot-fuzz), and various test suites/linting configurations.
- Project configuration/packaging tools: Yarn, npm, Lerna, and Nix for reproducible environments.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% On-Chain Layer
    subgraph "On-Chain Layer"
        EthereumContracts["Ethereum Contracts"]:::onchain
    end

    %% Off-Chain Layer
    subgraph "Off-Chain Layer"
        Subgraph["Subgraph"]:::offchain
        Metadata["Metadata"]:::offchain
    end

    %% Application Layer
    subgraph "Application Layer"
        SDKCore["SDK-Core"]:::application
        SDKRedux["SDK-Redux"]:::application
        JSSDK["JS-SDK"]:::application
        SDKReduxExamples["Frontend Apps (sdk-redux-examples)"]:::application
    end

    %% Supporting/Utility Components
    subgraph "Supporting/Utility Components"
        HotFuzz["Testing & Fuzzing Tools (hot-fuzz)"]:::support
        SpecHaskell["Spec-Haskell"]:::support
        StarknetContracts["Starknet Contracts"]:::support
        Tasks["Tasks"]:::support
    end

    %% External CI/CD and Deployment Tools
    ExternalCI["CI/CD & Deployment Tools"]:::external

    %% Relationships and Data Flows
    EthereumContracts -->|"emitsEvents"| Subgraph
    Subgraph -->|"indexesEvents"| Metadata
    Subgraph -->|"providesData"| SDKCore
    Subgraph -->|"providesData"| SDKRedux
    Subgraph -->|"providesData"| JSSDK
    SDKReduxExamples -->|"consumesSDK"| SDKRedux
    ExternalCI -->|"buildsTests"| EthereumContracts
    ExternalCI -->|"deploysIndexing"| Subgraph
    ExternalCI -->|"deploysApps"| SDKCore

    %% Legend
    subgraph "Legend"
        LE1["On-Chain: Ethereum Contracts"]:::onchain
        LE2["Off-Chain: Subgraph, Metadata"]:::offchain
        LE3["Application: SDKs, Front-End Apps"]:::application
        LE4["Support: Testing, Spec Tools, Tasks"]:::support
        LE5["External: CI/CD & Deployment Tools"]:::external
    end

    %% Click Events (paths for click events are not shown in node labels)
    click EthereumContracts "https://github.com/superfluid-finance/protocol-monorepo/tree/dev/packages/ethereum-contracts"
    click Subgraph "https://github.com/superfluid-finance/protocol-monorepo/tree/dev/packages/subgraph"
    click SDKCore "https://github.com/superfluid-finance/protocol-monorepo/tree/dev/packages/sdk-core"
    click SDKRedux "https://github.com/superfluid-finance/protocol-monorepo/tree/dev/packages/sdk-redux"
    click JSSDK "https://github.com/superfluid-finance/protocol-monorepo/tree/dev/packages/js-sdk"
    click Metadata "https://github.com/superfluid-finance/protocol-monorepo/tree/dev/packages/metadata"
    click HotFuzz "https://github.com/superfluid-finance/protocol-monorepo/tree/dev/packages/hot-fuzz"
    click SpecHaskell "https://github.com/superfluid-finance/protocol-monorepo/tree/dev/packages/spec-haskell"
    click StarknetContracts "https://github.com/superfluid-finance/protocol-monorepo/tree/dev/packages/starknet-contracts"
    click SDKReduxExamples "https://github.com/superfluid-finance/protocol-monorepo/tree/dev/sdk-redux-examples"
    click Tasks "https://github.com/superfluid-finance/protocol-monorepo/tree/dev/tasks"

    %% Styles
    classDef onchain fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef offchain fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef application fill:#FFFFE0,stroke:#000,stroke-width:2px;
    classDef support fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef external fill:#FFC0CB,stroke:#000,stroke-width:2px;
```
