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
| Technology | Version | Purpose |
|---|---|---|
| Next.js | 14.2.0 | React framework with App Router |
| React | 18.3.0 | UI library |
| TypeScript | 5.5.0 | Type safety |
| Tailwind CSS | 3.4.0 | Styling |
| Wagmi | 2.7.0 | React hooks for Ethereum |
| Viem | 2.9.0 | TypeScript Ethereum library |
| TanStack Query | 5.51.0 | Data fetching and caching |
| WalletConnect | 2.21.10 | Wallet connection |
| Lucide React | 0.400.0 | Icons |
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
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
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