# mathijs81/tokenblend architecture

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

- Interactive diagram: https://gitdiagram.com/mathijs81/tokenblend
- Repository: https://github.com/mathijs81/tokenblend

## Overview

##### Project type and purpose
- TokenBlend is a full-stack blockchain dApp.
- Frontend: a Vue.js single-page app for asset-blend management (sliders, trade plans, swaps).

##### File structure
Top-level:
- .github: CI/CD workflow (deploy.yml).
- blockchain/: Hardhat config, scripts (addManager, depositWeth), tests, package.json.
- web/: Vue.js dApp with codegen schemas, GraphQL, assets, components, services, router, styles, utilities.
Patterns:
- Separation of “blockchain” test/fork environment from “web” dApp.
- Frontend organized by features (components, views, services, util).
- GraphQL codegen for on-chain data (Enzyme, Uniswap, vaults).

##### Key tech stack (from README + files)
- Hardhat (blockchain testing/forking) + ethers.js
- Vue 3 + TypeScript + Vue Router + SCSS
- Web3/Ethers services for Uniswap, Paraswap, Idle, Enzyme
- GitHub Actions for CI/CD

##### Main components & interactions
A. User’s Browser
- Runs the Vue.js SPA (App.vue → views & components).
- Provides on-chain data: vaults, token lists, price feeds.
C. Web3Service Layer
- enzymeService.ts, idleService.ts, uniswapService.ts, paraswapService.ts
- Wraps ethers.js calls to smart contracts.
D. Ethereum Networks
1. Local Hardhat fork (blockchain/).
- Used for testing and scripts (addManager, depositWeth)
- Runs a replica of mainnet contracts for Uniswap/Idle.
2. Mainnet (live dApp mode)
- Direct Web3 interactions for swaps, deposits in real mode.
E. Smart Contracts
- IdleToken, Enzyme Vault, Uniswap Router on chain.
F. External Services
- Paraswap REST API for optimized swaps.
G. CI/CD Pipeline
- GitHub Actions deploy workflow pushes web build to GitHub Pages.

##### Architectural patterns & principles
- Clear separation of concerns:
– Presentation (Vue components & views)
– Data access (GraphQL layer + util/sdk.ts)
– Business logic (orderplan generation, slider rebalancing in orderplan.ts)
– Protocol integration (Web3 services)
- API-first for on-chain data (GraphQL codegen).
- Modular services for each protocol.
- Local testnet abstraction via Hardhat.

## Diagram (Mermaid)

```mermaid
flowchart TD

    subgraph "Frontend Layer"
        AppVue["App.vue"]:::frontend
        MainTS["main.ts"]:::frontend
        Components["components/"]:::frontend
        Views["views/"]:::frontend
        Router["router/index.ts"]:::frontend
        Styles["styles/style.scss"]:::frontend
    end

    subgraph "GraphQL & Codegen"
        CodegenSrc["codegen-src/"]:::data
        CodegenYAML["codegen.yaml"]:::data
        CodegenUniYAML["codegen_uniswap.yaml"]:::data
        EnzymeGraph["enzymegraph.ts"]:::data
        SDK["sdk.ts"]:::data
    end

    subgraph "Business Logic"
        OrderPlan["OrderPlan (orderplan.ts)"]:::services
    end

    subgraph "Web3 Services Layer"
        Web3Service["web3Service.ts"]:::services
        EnzymeS["enzymeService.ts"]:::services
        IdleS["idleService.ts"]:::services
        UniswapS["uniswapService.ts"]:::services
        ParaswapS["paraswapService.ts"]:::services
        IdleTokenJSON["IdleToken.json"]:::services
    end

    subgraph "Blockchain Networks"
        subgraph "Local Hardhat Network"
            HardhatConfig["hardhat.config.ts"]:::network
            ContractsLH["contracts/"]:::network
            AddManager["scripts/addManager.ts"]:::network
            DepositWeth["scripts/depositWeth.ts"]:::network
            SampleTest["test/sample-test.js"]:::network
        end
        Mainnet["Ethereum Mainnet"]:::network
    end

    subgraph "Smart Contracts"
        SCContracts["contracts/"]:::services
    end

    subgraph "External Protocols"
        UniswapAPI["Uniswap REST API"]:::external
        ParaswapAPI["Paraswap REST API"]:::external
        IdleTokenExt["Idle (IdleToken)"]:::external
    end

    CI["GitHub Actions CI/CD"]:::ci

    %% Connections
    AppVue -->|"loads"| MainTS
    MainTS -->|initializes| Components
    MainTS -->|initializes| Views
    MainTS -->|initializes| Router
    MainTS -->|applies styles| Styles

    Views -->|"user actions"| OrderPlan
    OrderPlan -->|"generates plan"| Web3Service
    AppVue -->|"queries data"| CodegenYAML
    CodegenSrc -->|"defines schema"| GraphQL["GraphQL API"]:::data
    CodegenYAML -->|"configures codegen"| GraphQL
    CodegenUniYAML -->|"configures codegen"| GraphQL
    EnzymeGraph -->|"query definitions"| GraphQL
    SDK -->|"runtime SDK"| GraphQL

    AppVue -->|"GraphQL over HTTPS"| GraphQL
    AppVue -->|"user triggers swap"| Web3Service

    Web3Service -->|"calls"| EnzymeS
    Web3Service -->|"calls"| IdleS
    Web3Service -->|"calls"| UniswapS
    Web3Service -->|"calls"| ParaswapS

    EnzymeS -->|"ethers.js JSON-RPC"| HardhatConfig
    EnzymeS -->|"ethers.js JSON-RPC"| Mainnet
    IdleS -->|"ethers.js JSON-RPC"| HardhatConfig
    IdleS -->|"ethers.js JSON-RPC"| Mainnet
    UniswapS -->|"ethers.js JSON-RPC"| HardhatConfig
    UniswapS -->|"ethers.js JSON-RPC"| Mainnet
    ParaswapS -->|"REST API"| ParaswapAPI

    HardhatConfig -->|"deploys to"| ContractsLH
    ContractsLH --> SampleTest
    ContractsLH --> AddManager
    ContractsLH --> DepositWeth

    Mainnet --> SCContracts
    HardhatConfig --> SCContracts

    AppVue -->|"deploy build"| CI

    %% Click Events
    click AppVue "https://github.com/mathijs81/tokenblend/blob/master/web/src/App.vue"
    click MainTS "https://github.com/mathijs81/tokenblend/blob/master/web/src/main.ts"
    click Components "https://github.com/mathijs81/tokenblend/tree/master/web/src/components/"
    click Views "https://github.com/mathijs81/tokenblend/tree/master/web/src/views/"
    click Router "https://github.com/mathijs81/tokenblend/blob/master/web/src/router/index.ts"
    click Styles "https://github.com/mathijs81/tokenblend/blob/master/web/src/styles/style.scss"
    click CodegenSrc "https://github.com/mathijs81/tokenblend/tree/master/web/codegen-src/"
    click CodegenYAML "https://github.com/mathijs81/tokenblend/blob/master/web/codegen.yaml"
    click CodegenUniYAML "https://github.com/mathijs81/tokenblend/blob/master/web/codegen_uniswap.yaml"
    click EnzymeGraph "https://github.com/mathijs81/tokenblend/blob/master/web/src/data/enzymegraph.ts"
    click SDK "https://github.com/mathijs81/tokenblend/blob/master/web/src/data/sdk.ts"
    click Web3Service "https://github.com/mathijs81/tokenblend/blob/master/web/src/web3/web3Service.ts"
    click EnzymeS "https://github.com/mathijs81/tokenblend/blob/master/web/src/web3/enzymeService.ts"
    click IdleS "https://github.com/mathijs81/tokenblend/blob/master/web/src/web3/idleService.ts"
    click UniswapS "https://github.com/mathijs81/tokenblend/blob/master/web/src/web3/uniswapService.ts"
    click ParaswapS "https://github.com/mathijs81/tokenblend/blob/master/web/src/web3/paraswapService.ts"
    click IdleTokenJSON "https://github.com/mathijs81/tokenblend/blob/master/web/src/web3/IdleToken.json"
    click OrderPlan "https://github.com/mathijs81/tokenblend/blob/master/web/src/orderplan/orderplan.ts"
    click HardhatConfig "https://github.com/mathijs81/tokenblend/blob/master/blockchain/hardhat.config.ts"
    click ContractsLH "https://github.com/mathijs81/tokenblend/tree/master/blockchain/contracts/"
    click AddManager "https://github.com/mathijs81/tokenblend/blob/master/blockchain/scripts/addManager.ts"
    click DepositWeth "https://github.com/mathijs81/tokenblend/blob/master/blockchain/scripts/depositWeth.ts"
    click SampleTest "https://github.com/mathijs81/tokenblend/blob/master/blockchain/test/sample-test.js"
    click CI "https://github.com/mathijs81/tokenblend/blob/master/.github/workflows/deploy.yml"

    %% Styles
    classDef frontend fill:#e5ffe5,stroke:#333,stroke-width:1px
    classDef data fill:#cce0ff,stroke:#333,stroke-width:1px
    classDef services fill:#ffe0b2,stroke:#333,stroke-width:1px
    classDef network fill:#ffebcc,stroke:#333,stroke-width:1px
    classDef external fill:#e0e0e0,stroke:#333,stroke-width:1px
    classDef ci fill:#f3e5f5,stroke:#333,stroke-width:1px
```
