# saddle-finance/saddle-frontend architecture

> Architecture diagram of the GitHub repository saddle-finance/saddle-frontend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/saddle-finance/saddle-frontend
- Repository: https://github.com/saddle-finance/saddle-frontend

## Overview

##### Main Components

a) Frontend Layer:
- React Application Core
- Pages (Swap, Pool, Farm, VeSDL, Risk)
- Components (shared UI elements)
- Providers (state management)
- Theme System
- Internationalization (i18n)
- Web3 Integration Layer

b) External Integrations:
- Web3 Providers (via Rainbowkit)
- Smart Contracts Integration
- Third-party Services
- Alchemy/Infura (REACT_APP_NETWORK_URL)
- BlockNative (notifications)
- Google Analytics

c) State Management:
- Application State
- User State
- Pool Data
- Token Data
- Transaction State

**[User Browser] → [Frontend Application]**
- ↓
**[State Management] ← [Core Components] → [Web3 Integration Layer]**
- ↓
- [Blockchain Interaction]
- ↓
- [Smart Contracts Layer]

##### Component Relationships

- Data flow between components
- Contract interactions
- State updates
- User interactions

##### Key Technical Elements to Highlight

a) Frontend Architecture:
- React components structure
- Theme system with Material-UI
- Storybook integration
- Cypress testing framework

b) Web3 Integration:
- Multiple wallet support
- Transaction handling
- Gas estimation
- Contract interactions

c) State Management:
- Custom hooks
- Context providers
- Data caching

##### Implementation Details

- Swap functionality
- Liquidity pools
- Farming
- Governance (VeSDL)
- Risk assessment

##### Testing Layer

A section showing:
- Cypress integration tests
- Component stories
- Unit tests

For this specific project, emphasize:
##### The user interaction flow for key features like swapping and farming

Remember to include the deployment architecture showing how the application is served via IPFS and accessible through multiple domains (saddle.exchange and saddlefinance.eth.link).

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Browser
        User(("User Browser"))
    end

    subgraph "Frontend Application"
        React["React Application Core"]:::frontend
        Pages["Pages Container"]:::frontend
        Components["Shared Components"]:::frontend
        Theme["Theme System"]:::frontend
        I18n["Internationalization"]:::frontend

        subgraph "Pages"
            Swap["Swap Page"]:::frontend
            Pool["Pool Page"]:::frontend
            Farm["Farm Page"]:::frontend
            VeSDL["VeSDL Page"]:::frontend
            Risk["Risk Page"]:::frontend
        end

        subgraph "Core Components"
            TokenInput["Token Input"]:::frontend
            SwapInterface["Swap Interface"]:::frontend
            PoolOps["Pool Operations"]:::frontend
            TxHandler["Transaction Handler"]:::frontend
        end
    end

    subgraph "State Management"
        AppState["Application State"]:::state
        UserState["User State"]:::state
        Providers["State Providers"]:::state
        DataHooks["Data Hooks"]:::state
    end

    subgraph "Web3 Integration"
        Web3Config["Core Configuration"]:::web3
        WalletIntegration["Wallet Integration"]:::web3
        RainbowKit["Rainbow Kit"]:::web3
    end

    subgraph "External Services"
        Alchemy["Alchemy/Infura"]:::external
        BlockNative["BlockNative"]:::external
        Analytics["Google Analytics"]:::external
    end

    subgraph "Testing Framework"
        Cypress["Integration Tests"]:::testing
        Storybook["Component Stories"]:::testing
        TestUtils["Test Utilities"]:::testing
    end

    User --> React
    React --> Pages
    React --> Components
    React --> Theme
    React --> I18n

    Pages --> Swap
    Pages --> Pool
    Pages --> Farm
    Pages --> VeSDL
    Pages --> Risk

    Components --> TokenInput
    Components --> SwapInterface
    Components --> PoolOps
    Components --> TxHandler

    React --> AppState
    React --> UserState
    React --> Providers
    React --> DataHooks

    React --> Web3Config
    Web3Config --> WalletIntegration
    Web3Config --> RainbowKit

    Web3Config --> Alchemy
    React --> BlockNative
    React --> Analytics

    classDef frontend fill:#3498db
    classDef state fill:#2ecc71
    classDef web3 fill:#9b59b6
    classDef external fill:#e67e22
    classDef testing fill:#f1c40f

    click Swap "https://github.com/saddle-finance/saddle-frontend/blob/master/src/pages/Swap/Swap.tsx"
    click Pool "https://github.com/saddle-finance/saddle-frontend/blob/master/src/pages/Pools/Pools.tsx"
    click Farm "https://github.com/saddle-finance/saddle-frontend/blob/master/src/pages/Farm/Farm.tsx"
    click VeSDL "https://github.com/saddle-finance/saddle-frontend/blob/master/src/pages/VeSDL/VeSdl.tsx"
    click Risk "https://github.com/saddle-finance/saddle-frontend/blob/master/src/pages/Risk/Risk.tsx"
    click AppState "https://github.com/saddle-finance/saddle-frontend/blob/master/src/state/application.ts"
    click UserState "https://github.com/saddle-finance/saddle-frontend/blob/master/src/state/user.ts"
    click Providers "https://github.com/saddle-finance/saddle-frontend/blob/master/src/providers/UserStateProvider.tsx"
    click Web3Config "https://github.com/saddle-finance/saddle-frontend/blob/master/src/connectors/config.ts"
    click WalletIntegration "https://github.com/saddle-finance/saddle-frontend/blob/master/src/components/Web3Status.tsx"
    click RainbowKit "https://github.com/saddle-finance/saddle-frontend/blob/master/src/components/Rainbowkit/index.ts"
    click Theme "https://github.com/saddle-finance/saddle-frontend/blob/master/src/theme/index.ts"
    click TokenInput "https://github.com/saddle-finance/saddle-frontend/blob/master/src/components/TokenInput.tsx"
    click SwapInterface "https://github.com/saddle-finance/saddle-frontend/blob/master/src/components/SwapPage.tsx"
    click PoolOps "https://github.com/saddle-finance/saddle-frontend/blob/master/src/components/PoolOverview.tsx"
    click TxHandler "https://github.com/saddle-finance/saddle-frontend/blob/master/src/components/ConfirmTransaction.tsx"
    click I18n "https://github.com/saddle-finance/saddle-frontend/blob/master/src/i18n.ts"
    click Cypress "https://github.com/saddle-finance/saddle-frontend/tree/master/cypress/integration/"
    click TestUtils "https://github.com/saddle-finance/saddle-frontend/tree/master/src/utils/__tests__/"
    click DataHooks "https://github.com/saddle-finance/saddle-frontend/blob/master/src/hooks/usePoolData.ts"
```
