System Overview
Last updated
Last updated
This document provides a comprehensive overview of the Ava Portfolio Manager's architecture, explaining how its components work together to create a powerful DeFi portfolio management system powered by AI.
The Ava Portfolio Manager is built on a multi-agent AI system, with specialized agents working together to provide advanced portfolio management capabilities. The architecture follows a modular design with clear separation of concerns.
The frontend is built with Next.js and provides the user interface for interacting with the Ava Portfolio Manager. Key components include:
Chat Interface: Allows users to communicate with the Eliza Agent using natural language
Portfolio Dashboard: Displays portfolio metrics, holdings, and performance
Transaction Interface: Provides real-time status of pending and completed transactions
Settings Panel: Allows users to configure preferences and connect wallets
The backend is built with Node.js and provides the API, agent system, and database services:
HTTP API: RESTful API endpoints for frontend communication
WebSocket Server: Real-time updates and agent communication
Authentication Service: User authentication and authorization
Database Service: Persistent storage for user data and agent state
The agent system consists of four specialized AI agents:
Eliza Agent: The conversational interface that processes natural language and coordinates interactions between the user and other agents
Sonic Agent: Handles blockchain interactions, including fetching data from and executing transactions on various DeFi protocols
Move Agent: Analyzes portfolio data, suggests optimization strategies, and monitors performance
Task Manager Agent: Coordinates complex tasks that require multiple agents, ensuring tasks are tracked and completed
The event bus facilitates communication between agents and system components:
Publish-Subscribe Model: Components publish events and subscribe to relevant topics
Event Routing: Ensures events reach the appropriate subscribers
Event Persistence: Maintains a record of events for debugging and recovery
The protocol plugins provide standardized interfaces for interacting with various DeFi protocols:
Uniswap Plugin: For DEX interactions and liquidity provision
Aave Plugin: For lending and borrowing
MarginZero Plugin: For options trading
Generic ERC20/ERC721 Plugin: For standard token interactions
User inputs a request via the chat interface
Frontend sends the request to the backend API
API forwards the request to the Eliza Agent
Eliza Agent processes the natural language, determines intent, and creates tasks
Task Manager coordinates execution across agents
Results are sent back through the API to the frontend
Frontend displays the results to the user
User requests a transaction (e.g., "Swap 1 ETH for USDC")
Eliza Agent determines the intent is a swap transaction
Task Manager creates a transaction task
Sonic Agent prepares the transaction using the appropriate protocol plugin
Transaction details are displayed to the user for confirmation
Upon approval, Sonic Agent submits the transaction to the blockchain
Transaction status updates are published to the event bus
Frontend receives updates via WebSocket and displays status to the user
User requests portfolio analysis (e.g., "How is my portfolio performing?")
Eliza Agent determines the intent is portfolio analysis
Task Manager creates an analysis task
Sonic Agent fetches on-chain data for the user's wallets
Move Agent analyzes the data and generates insights
Results are formatted by the Eliza Agent for user consumption
Frontend displays the analysis to the user
Each agent is implemented as a TypeScript class that extends a base Agent class:
Specialized agents implement additional methods specific to their purpose:
The event bus uses a publish-subscribe pattern:
Protocol plugins implement a common interface:
The system uses multiple storage mechanisms:
Database: PostgreSQL for structured data (user profiles, transaction history)
Cache: Redis for temporary data and rate limiting
Vector Database: For semantic search capabilities in the AI agents
Blockchain: The ultimate source of truth for all on-chain data
Security is implemented at multiple levels:
Authentication: JWT-based authentication for API access
Authorization: Role-based access control for different operations
Input Validation: All user inputs are validated and sanitized
Transaction Safety: Multi-step confirmation for transactions
Key Management: Private keys are encrypted and securely stored
Rate Limiting: To prevent abuse of API endpoints
The architecture is designed for scalability:
Horizontal Scaling: Components can be deployed across multiple servers
Microservices: Each major component can operate independently
Load Balancing: Requests can be distributed across multiple instances
Caching: Reduces repeated computation and blockchain queries
Asynchronous Processing: Long-running tasks are processed asynchronously
The system includes robust error handling:
Graceful Degradation: If a component fails, others continue to function
Retry Mechanisms: Failed operations are retried with exponential backoff
Circuit Breakers: Prevent cascading failures
Comprehensive Logging: For debugging and auditing
Error Boundaries: Isolate failures in the UI
The system can be deployed in various configurations:
Development: Local deployment with development dependencies
Staging: Test environment with production-like configuration
Production: Fully scaled deployment with redundancy
Self-Hosted: Users can deploy their own instance with custom configuration
The system supports multiple blockchains through a unified interface:
Chain Registry: Maintains information about supported chains
Chain Adapters: Normalize interactions across different blockchains
Bridge Integration: Support for cross-chain operations
Multi-Chain Wallet: Manages addresses across multiple chains
The system includes comprehensive monitoring:
Logging: Structured logs with appropriate log levels
Metrics: Performance and usage metrics
Alerts: Notification system for critical issues
Health Checks: Regular verification of system components
Performance Tracking: Monitoring of response times and resource usage
Planned architectural enhancements include:
Enhanced AI Capabilities: More sophisticated agent interactions
Decentralized Components: Moving toward decentralized architecture
Mobile Support: Dedicated mobile client
Plugin Marketplace: User-contributed protocol integrations
Advanced Analytics: Predictive portfolio analytics
The Ava Portfolio Manager's architecture is designed to be modular, scalable, and extensible. By using a multi-agent system with specialized components, it provides a powerful platform for DeFi portfolio management while maintaining the flexibility to evolve with the rapidly changing DeFi landscape.