# namay10/driftprotocol-ui architecture

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

- Interactive diagram: https://gitdiagram.com/namay10/driftprotocol-ui
- Repository: https://github.com/namay10/driftprotocol-ui

## Overview

##### Project type and purpose
- From the file‐tree and README we see this is a Next.js (React + TypeScript) frontend application bootstrapped via create-next-app.
- It does not contain any in-repo “backend” or API routes, but instead integrates with external services (Drift protocol via driftclient/driftWalletWrapper, and a Web3 wallet provider).

##### File structure
- Top-level:
- package.json, tsconfig.json, next.config.ts, eslint.config.mjs – Next.js + TypeScript + linting/build config
- public/ – static assets
- src/app/ – new Next.js “app” directory hosting UI, layout, page.tsx
- Under src/app:
- components/ – presentational and container React components (DepositWithdraw.tsx, PerpOrderPanel.tsx, SubaccountSidebar.tsx, WalletConnectButton.tsx, etc.)
- lib/ – wrappers for business logic & SDK integrations (driftclient.ts, driftWalletWrapper.ts, perporder.ts)
- store/ – global state store using React Context or a state library (userdriftstore.ts)
- layout.tsx, globals.css – app shell + global styling

##### README for additional insights
- Confirms standard Next.js frontend, no mention of custom server or database.
- Deployment target is Vercel or any static-hosting plus serverless.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client - Browser"
        subgraph "Next.js App Router"
            Layout["Layout Component"]:::ui
            Page["Root Page (page.tsx)"]:::ui
            subgraph "Components"
                DW["Deposit/Withdraw Panel"]:::ui
                FD["First Deposit Prompt"]:::ui
                IW["Wallet Data Input Form"]:::ui
                PP["Perpetual Order Panel"]:::ui
                SS["Subaccount Sidebar"]:::ui
                SD["Subaccount Details View"]:::ui
                WC["Wallet Connect Button"]:::ui
            end
        end
        subgraph "State"
            WCProvider["Wallet Context Provider"]:::state
            Store["User Drift Store"]:::state
        end
    end

    subgraph "Business Logic"
        DWrap["Drift Wallet Wrapper"]:::logic
        DClient["Drift Protocol Client"]:::logic
        PLogic["Perpetual Order Logic"]:::logic
    end

    subgraph "External Services"
        WProvider["Web3 Wallet Provider (MetaMask, WalletConnect)"]:::external
        Blockchain["Blockchain / RPC Node"]:::external
    end

    subgraph "Hosting/CDN"
        CDN["Vercel / Static Hosting"]:::hosting
    end

    subgraph "Config Files"
        NextConfig["next.config.ts"]:::config
        Tsconfig["tsconfig.json"]:::config
        ESLint["eslint.config.mjs"]:::config
        PostCSS["postcss.config.mjs"]:::config
    end

    Page -->|renders| DW
    Page -->|renders| FD
    Page -->|renders| IW
    Page -->|renders| PP
    Page -->|renders| SS
    Page -->|renders| SD
    Page -->|renders| WC
    Layout -->|wraps| Page

    DW & FD & IW & PP & SS & SD & WC -->|use context| WCProvider
    WCProvider -->|provides state| Store
    Store -->|dispatch actions| DWrap
    Store -->|dispatch actions| DClient
    Store -->|dispatch actions| PLogic

    DWrap -->|calls| WProvider
    DClient -->|calls| Blockchain
    PLogic -->|calls| DWrap
    PLogic -->|calls| DClient

    CDN -->|serves| Layout
    CDN -->|serves| Page
    CDN -->|serves| DW
    CDN -->|serves| FD
    CDN -->|serves| IW
    CDN -->|serves| PP
    CDN -->|serves| SS
    CDN -->|serves| SD
    CDN -->|serves| WC

    click Layout "https://github.com/namay10/driftprotocol-ui/blob/master/src/app/layout.tsx"
    click Page "https://github.com/namay10/driftprotocol-ui/blob/master/src/app/page.tsx"
    click DW "https://github.com/namay10/driftprotocol-ui/blob/master/src/app/components/DepositWithdraw.tsx"
    click FD "https://github.com/namay10/driftprotocol-ui/blob/master/src/app/components/FirstDeposit.tsx"
    click IW "https://github.com/namay10/driftprotocol-ui/blob/master/src/app/components/InputWalletData.tsx"
    click PP "https://github.com/namay10/driftprotocol-ui/blob/master/src/app/components/PerpOrderPanel.tsx"
    click SS "https://github.com/namay10/driftprotocol-ui/blob/master/src/app/components/SubaccountSidebar.tsx"
    click SD "https://github.com/namay10/driftprotocol-ui/blob/master/src/app/components/SubaccountDetails.tsx"
    click WC "https://github.com/namay10/driftprotocol-ui/blob/master/src/app/components/WalletConnectbutton.tsx"
    click WCProvider "https://github.com/namay10/driftprotocol-ui/blob/master/src/app/components/WalletContextProvider.tsx"
    click Store "https://github.com/namay10/driftprotocol-ui/blob/master/src/app/store/userdriftstore.ts"
    click DWrap "https://github.com/namay10/driftprotocol-ui/blob/master/src/app/lib/driftWalletWrapper.ts"
    click DClient "https://github.com/namay10/driftprotocol-ui/blob/master/src/app/lib/driftclient.ts"
    click PLogic "https://github.com/namay10/driftprotocol-ui/blob/master/src/app/lib/perporder.ts"
    click CDN "https://github.com/namay10/driftprotocol-ui/tree/master/public/"
    click NextConfig "https://github.com/namay10/driftprotocol-ui/blob/master/next.config.ts"
    click Tsconfig "https://github.com/namay10/driftprotocol-ui/blob/master/tsconfig.json"
    click ESLint "https://github.com/namay10/driftprotocol-ui/blob/master/eslint.config.mjs"
    click PostCSS "https://github.com/namay10/driftprotocol-ui/blob/master/postcss.config.mjs"

    classDef ui fill:#D6EAF8,stroke:#1B4F72
    classDef state fill:#FCF3CF,stroke:#7D6608
    classDef logic fill:#D5F5E3,stroke:#145A32
    classDef external fill:#FADBD8,stroke:#922B21,stroke-dasharray:5 5
    classDef hosting fill:#E8DAEF,stroke:#512E5F
    classDef config fill:#F2F3F4,stroke:#5D6D7E
```
