Skip to main content

Overview

The MetaVault frontend is built with Next.js 14 using the App Router, TypeScript, and Tailwind CSS. It provides a modern, responsive interface for users to interact with the vault, monitor their positions, and chat with AI agents.

Technology Stack

Project Structure

Architecture Diagram

Key Components

1. App Router Structure

File: src/app/page.tsx The main page implements a tabbed interface:

2. Web3 Provider Setup

File: src/app/providers.tsx
File: src/config/wagmi.ts

3. VaultDashboard Component

File: src/components/VaultDashboard.tsx The main dashboard shows:
  • Vault statistics (TVL, APY, user shares)
  • Strategy allocations
  • Deposit/withdraw actions
  • Recent activity
  • Top depositors
Data Fetching:

4. Deposit/Withdraw Flows

File: src/components/DepositModal.tsx

5. AgentChat Component

File: src/components/AgentChat.tsx Provides a chat interface to interact with AI agents:

6. API Routes

Agent Proxy

File: src/app/api/agent/route.ts

APY Calculation

File: src/app/api/vault/apy/route.ts

State Management

Local State

  • React useState: UI state (modals, inputs, tabs)
  • React useReducer: Complex forms

Server State

  • TanStack Query: Blockchain data caching
  • Wagmi Hooks: Automatic re-fetching on block changes

Web3 State

  • Wagmi: Account, chain, connection status
  • Wallet Provider: Signer, transactions

Data Flow

Read Flow (Vault Balance)

Write Flow (Deposit)

Agent Chat Flow

Styling

Tailwind Configuration

Custom theme with dark mode:

Design System

  • Colors: Dark theme with blue/violet accents
  • Typography: Inter font family
  • Spacing: 4px base unit (Tailwind default)
  • Components: Glass-morphism effects
  • Icons: Lucide React

Performance Optimizations

React Query Caching

Wagmi Auto-Refetch

Code Splitting

  • Next.js automatic code splitting
  • Dynamic imports for modals

Image Optimization

  • Next.js <Image> component
  • WebP format with fallbacks

Error Handling

Network Errors

Transaction Errors

Environment Variables

Testing Strategy

  • Unit Tests: Component logic (Jest + React Testing Library)
  • Integration Tests: Contract interactions (Playwright)
  • E2E Tests: Full user flows (Playwright + Hardhat)
  • Visual Tests: Storybook for component library

Deployment

Docker