# oraidex/oraiswap-frontend architecture

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

- Interactive diagram: https://gitdiagram.com/oraidex/oraiswap-frontend
- Repository: https://github.com/oraidex/oraiswap-frontend

## Overview

##### Project type and purpose
- This is a single-page React application (“Oraidex’s Frontend”) designed as the user interface for a decentralized exchange on Oraichain. It is not a traditional full-stack server-side app but a front-end heavy DApp that interacts with smart contracts and multiple blockchain networks via REST, GraphQL, and on-chain libraries.

##### File structure
- Top-level config and tool files (.eslintrc, vite.config.ts, babel.config.js, etc.) support build and CI.
- Public & index.html deliver the HTML shell.
- src/index.tsx bootstraps the React app.
- src/components and src/pages hold UI components and page containers (e.g., Balance, Pools, Staking, UniversalSwap).
- src/store, src/reducer, src/routes.tsx define Redux state management and routing.
- src/rest and src/gql contain data-access layers: REST API clients and GraphQL codegen.
- src/libs and src/hooks include blockchain integrations (Metamask, Keplr, cw-bitcoin, nomic, Solana, TON, TronLink) and custom React hooks.
- CI workflows in .github/workflows automate lint/test/deploy.

##### README for additional insights
- Confirms this is purely frontend with NodeJS, building via Yarn/Vite.
- Mentions dependence on on-chain contracts (oraiswap).
- No server-side logic here; all business logic lives client-side or in on-chain contracts.

##### Detail
- Major folder’s role (e.g., src/pages vs. src/components).
- Distinguish between on-chain vs off-chain data sources.
- Middleware or codegen steps as part of the build pipeline.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer (UI)
    subgraph "Presentation Layer"
        direction TB
        UIEntry["Application Entry Point\nsrc/index.tsx"]:::ui
        Routes["Routing Setup\nsrc/routes.tsx"]:::ui
        Components["React UI Components\nsrc/components"]:::ui
        Pages["Page Containers\nsrc/pages"]:::ui
    end

    %% Business Logic Layer
    subgraph "Business Logic & State Management"
        direction TB
        StoreConfig["Store Configuration\nsrc/store/configure.ts"]:::logic
        StoreConstants["Store Constants\nsrc/store/constants.ts"]:::logic
        Reducers["Reducers\nsrc/reducer/*.ts"]:::logic
        Hooks["Business Logic & Side-Effects Hooks\nsrc/hooks"]:::logic
        Contexts["Global Context Providers\nsrc/context/*.tsx"]:::logic
        Layouts["Application Layouts & Shell\nsrc/layouts"]:::logic
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        direction TB
        RESTClient["REST Client\nsrc/rest"]:::data
        GraphQLClient["GraphQL Client & Codegen\nsrc/gql"]:::data
    end

    %% Blockchain Adapters
    subgraph "Blockchain Adapters"
        direction TB
        Metamask["Metamask Adapter\nsrc/libs/metamask.ts"]:::data
        Keplr["Keplr Adapter\nsrc/libs/keplr.ts"]:::data
        CWBitcoin["cw-bitcoin Adapter\nsrc/libs/cw-bitcoin"]:::data
        Nomic["nomic Adapter\nsrc/libs/nomic"]:::data
        ContractSingleton["Contract Singleton\nsrc/libs/contractSingleton.ts"]:::data
    end

    %% External Systems
    subgraph "External Systems"
        direction TB
        Coingecko["Coingecko API"]:::external
        OraichainLCD["Oraichain LCD Endpoints"]:::external
        EVMRPC["EVM JSON-RPC Endpoints"]:::external
        TonConnect["TonConnect"]:::external
        SmartContracts["Smart Contracts (Oraiswap)"]:::external
    end

    %% Build & CI
    subgraph "Build & CI"
        direction TB
        Vite["Vite & Babel\nvite.config.ts\nbabel.config.js"]:::infra
        CodegenTS["Codegen Config\ncodegen.ts\n.graphqlrc.ts"]:::infra
        CI["GitHub Actions Workflows\n.github/workflows/*.yml"]:::infra
    end

    %% Data Flow
    User["User"]:::external
    User -->|"interacts with"| UIEntry
    UIEntry -->|"renders"| Components
    UIEntry -->|"routes to"| Pages
    Pages -->|"dispatches actions or calls hooks"| StoreConfig
    Pages -->|"uses hooks"| Hooks
    Components -->|"uses hooks"| Hooks
    Hooks -->|"dispatch or update store"| StoreConfig
    StoreConfig -->|"uses constants & reducers"| StoreConstants
    StoreConfig -->|"uses reducers"| Reducers
    StoreConfig -->|"provides context"| Contexts
    Components -->|"wrapped by"| Layouts

    Hooks -->|"call"| RESTClient
    Hooks -->|"call"| GraphQLClient
    Hooks -->|"call"| Metamask
    Hooks -->|"call"| Keplr
    Hooks -->|"call"| CWBitcoin
    Hooks -->|"call"| Nomic
    Hooks -->|"call"| ContractSingleton

    RESTClient -->|"HTTP/GraphQL"| Coingecko
    RESTClient -->|"HTTP/GraphQL"| OraichainLCD
    GraphQLClient -->|"GraphQL"| OraichainLCD
    Metamask -->|"RPC"| EVMRPC
    Keplr -->|"RPC"| OraichainLCD
    CWBitcoin -->|"RPC"| OraichainLCD
    Nomic -->|"RPC"| EVMRPC
    ContractSingleton -->|"on-chain"| SmartContracts

    Vite -->|"bundles"| UIEntry
    CodegenTS -->|"generates types"| GraphQLClient
    CI -->|"runs tests & deploys"| Vite

    %% Click Events
    click Components "https://github.com/oraidex/oraiswap-frontend/tree/main/src/components"
    click Pages "https://github.com/oraidex/oraiswap-frontend/tree/main/src/pages"
    click UIEntry "https://github.com/oraidex/oraiswap-frontend/blob/main/src/index.tsx"
    click Routes "https://github.com/oraidex/oraiswap-frontend/blob/main/src/routes.tsx"
    click StoreConfig "https://github.com/oraidex/oraiswap-frontend/blob/main/src/store/configure.ts"
    click StoreConstants "https://github.com/oraidex/oraiswap-frontend/blob/main/src/store/constants.ts"
    click Reducers "https://github.com/oraidex/oraiswap-frontend/tree/main/src/reducer/"
    click RESTClient "https://github.com/oraidex/oraiswap-frontend/blob/main/src/rest/api.ts"
    click RESTClient "https://github.com/oraidex/oraiswap-frontend/blob/main/src/rest/graphClient.ts"
    click RESTClient "https://github.com/oraidex/oraiswap-frontend/blob/main/src/rest/request.ts"
    click GraphQLClient "https://github.com/oraidex/oraiswap-frontend/blob/main/src/gql/gql.ts"
    click GraphQLClient "https://github.com/oraidex/oraiswap-frontend/blob/main/src/gql/graphql.ts"
    click GraphQLClient "https://github.com/oraidex/oraiswap-frontend/blob/main/src/gql/index.ts"
    click Metamask "https://github.com/oraidex/oraiswap-frontend/blob/main/src/libs/metamask.ts"
    click Keplr "https://github.com/oraidex/oraiswap-frontend/blob/main/src/libs/keplr.ts"
    click CWBitcoin "https://github.com/oraidex/oraiswap-frontend/tree/main/src/libs/cw-bitcoin"
    click Nomic "https://github.com/oraidex/oraiswap-frontend/tree/main/src/libs/nomic"
    click ContractSingleton "https://github.com/oraidex/oraiswap-frontend/blob/main/src/libs/contractSingleton.ts"
    click Hooks "https://github.com/oraidex/oraiswap-frontend/tree/main/src/hooks"
    click Contexts "https://github.com/oraidex/oraiswap-frontend/tree/main/src/context/"
    click Layouts "https://github.com/oraidex/oraiswap-frontend/blob/main/src/layouts/App.tsx"
    click Layouts "https://github.com/oraidex/oraiswap-frontend/blob/main/src/layouts/Sidebar.tsx"
    click Layouts "https://github.com/oraidex/oraiswap-frontend/blob/main/src/layouts/Content.tsx"
    click Vite "https://github.com/oraidex/oraiswap-frontend/blob/main/vite.config.ts"
    click Vite "https://github.com/oraidex/oraiswap-frontend/blob/main/babel.config.js"
    click CodegenTS "https://github.com/oraidex/oraiswap-frontend/blob/main/codegen.ts"
    click CodegenTS "https://github.com/oraidex/oraiswap-frontend/blob/main/.graphqlrc.ts"
    click CI "https://github.com/oraidex/oraiswap-frontend/tree/main/.github/workflows/"

    %% Styles
    classDef ui fill:#cce5ff,stroke:#0366d6,color:#0366d6
    classDef logic fill:#d4edda,stroke:#22863a,color:#22863a
    classDef data fill:#ffe5b4,stroke:#d29922,color:#d29922
    classDef external fill:#f8d7da,stroke:#cb2431,color:#cb2431
    classDef infra fill:#e2e3e5,stroke:#6a737d,color:#6a737d
```
