Skip to main content

Architecture Overview

The MetaVault AI frontend is a modern Web3 application built with Next.js 14 using the App Router, React 18, TypeScript, and Tailwind CSS. It provides a comprehensive dashboard for managing DeFi vault operations and interacting with an AI-powered assistant.

Tech Stack

Core Framework

  • Next.js 14.2.0 - App Router with Server Components
  • React 18.3.0 - UI library
  • TypeScript 5.5.0 - Type safety
  • Tailwind CSS 3.4.0 - Utility-first styling

Web3 Integration

  • Wagmi 2.7.0 - React Hooks for Ethereum
  • Viem 2.9.0 - TypeScript Ethereum library
  • WalletConnect 2.21.10 - Multi-wallet support

State Management

  • @tanstack/react-query 5.51.0 - Async state management
  • Wagmi’s built-in state - Wallet and contract state

Utilities

  • Ethers.js 6.13.0 - Additional Ethereum utilities
  • Lucide React 0.400.0 - Icon library
  • clsx 2.1.1 - Conditional class names

Project Structure

App Router Structure

Root Layout (src/app/layout.tsx:1)

The root layout wraps the entire application with metadata and providers:

Providers Configuration (src/app/providers.tsx:1)

Centralized provider setup for Wagmi and React Query:
Key Configuration:
  • Disabled automatic refetch on window focus to reduce RPC calls
  • 5-minute stale time and 10-minute garbage collection
  • Exponential backoff retry strategy
  • Automatic reconnection on mount

Main Page (src/app/page.tsx:1)

The home page implements a tabbed interface with sidebar navigation:

API Routes

Agent Chat API (src/app/api/agent/route.ts:1)

Proxy endpoint for AI assistant communication:
Features:
  • Session management for conversation continuity
  • Wallet address forwarding for personalized responses
  • Unsigned transaction handling for AI-initiated transactions

TypeScript Configuration

Path Aliases (tsconfig.json:21)

Enables clean imports like @/components/VaultDashboard instead of relative paths.

Styling Architecture

Tailwind Configuration (tailwind.config.ts:1)

Custom Glass Morphism Styles

The application uses custom glass-panel effects defined in globals.css:

Environment Variables

Build Configuration

Next.js Config (next.config.js:1)

Externalizes packages that cause issues in browser environments.

Development Workflow

Running Locally

Runs on http://localhost:3000

Building for Production

Type Checking

Performance Optimizations

  1. React Query Caching - 5-minute stale time reduces RPC calls
  2. Selective Refetching - Disabled window focus refetch
  3. Event-Driven Updates - Real-time contract event listeners
  4. SSR Support - Cookie-based storage for server-side rendering
  5. Batch RPC Calls - Multicall enabled for multiple reads

Next Steps

React Components

Learn about the component architecture and patterns

Web3 Integration

Deep dive into Wagmi and Viem usage patterns