# struct-defi/struct-contracts architecture

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

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

## Overview

##### Component Relationships

a) Control Flow:
- Factory → Product creation
- Product → YieldSource interactions
- Product → SPToken minting/burning

b) Data Flow:
- User deposits → Products
- Products → Yield Sources → External protocols
- Price feeds → Oracle → Products
- Protocol fees → DistributionManager

##### State Transitions

**OPEN → INVESTED → WITHDRAWN**

##### Important Details

a) Role-based Access:
- GOVERNANCE, KEEPER, PAUSER, PRODUCT, FACTORY roles

b) Integration Points:
- Chainlink price feeds
- DEX interactions (TraderJoe, GMX)
- Reward distribution paths

##### Technical Specifications

Annotations for:
- Smart contract inheritance relationships
- Key parameters (leverage thresholds, durations)
- Protocol fees flow
- Token relationships (SPToken to deposits)

##### Integration flexibility with different protocols

Remember to include the three main states (OPEN, INVESTED, WITHDRAWN) as they are crucial to the protocol's operation, and clearly show how funds flow through the system during each state.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Core["Core Protocol Layer"]
        FEYFactory["FEY Product Factory"]
        FEYProduct["FEY Product"]
        SPToken["SP Token"]
        GlobalAccess["Global Access Control"]
    end

    subgraph Integration["Integration Layer"]
        direction TB
        subgraph TJ["TraderJoe Integration"]
            TJFactory["TraderJoe Factory"]
            TJProduct["TraderJoe Product"]
        end
        
        subgraph GMX["GMX Integration"]
            GMXFactory["GMX Factory"]
            GMXProduct["GMX Product"]
        end
    end

    subgraph Infrastructure["Infrastructure Layer"]
        PriceOracle["Price Oracle"]
        DistManager["Distribution Manager"]
        YieldSource["Yield Sources"]
        Chainlink["Chainlink Feeds"]
    end

    subgraph States["Product States"]
        OPEN --> INVESTED
        INVESTED --> WITHDRAWN
    end

    %% Core Protocol Relationships
    FEYFactory --> FEYProduct
    FEYProduct --> SPToken
    GlobalAccess -.-> FEYFactory
    GlobalAccess -.-> FEYProduct
    GlobalAccess -.-> SPToken

    %% Integration Relationships
    FEYFactory --> TJFactory
    FEYFactory --> GMXFactory
    TJFactory --> TJProduct
    GMXFactory --> GMXProduct
    TJProduct --> YieldSource
    GMXProduct --> YieldSource

    %% Infrastructure Relationships
    Chainlink --> PriceOracle
    PriceOracle --> FEYProduct
    FEYProduct --> DistManager
    YieldSource --> TJProduct
    YieldSource --> GMXProduct

    %% Click Events
    click FEYProduct "https://github.com/struct-defi/struct-contracts/tree/main/contracts/protocol/products"
    click SPToken "https://github.com/struct-defi/struct-contracts/tree/main/contracts/protocol/tokenization"
    click TJFactory "https://github.com/struct-defi/struct-contracts/tree/main/contracts/protocol/products/autopool"
    click GMXFactory "https://github.com/struct-defi/struct-contracts/tree/main/contracts/protocol/products/gmx"
    click TJProduct "https://github.com/struct-defi/struct-contracts/tree/main/contracts/external/traderjoe"
    click GMXProduct "https://github.com/struct-defi/struct-contracts/tree/main/contracts/external/gmx"
    click YieldSource "https://github.com/struct-defi/struct-contracts/tree/main/contracts/protocol/yield-sources"

    %% Styling
    classDef core fill:#e1f5fe,stroke:#01579b
    classDef integration fill:#f3e5f5,stroke:#4a148c
    classDef infrastructure fill:#e8f5e9,stroke:#1b5e20
    classDef state fill:#fff3e0,stroke:#e65100
    classDef external fill:#fafafa,stroke:#424242

    class FEYFactory,FEYProduct,SPToken,GlobalAccess core
    class TJFactory,TJProduct,GMXFactory,GMXProduct integration
    class PriceOracle,DistManager,YieldSource,Chainlink infrastructure
    class OPEN,INVESTED,WITHDRAWN state
    
    %% Legend
    subgraph Legend
        L1["Core Protocol"]:::core
        L2["Integration"]:::integration
        L3["Infrastructure"]:::infrastructure
        L4["State"]:::state
        L5["External"]:::external
    end
```
