How ahmadnurfadilah/aptomizer works
Project Type and Purpose
• Aptomizer is a full-stack AI-powered portfolio management and optimization tool for the Aptos blockchain.
• It integrates a chatbot AI assistant (using OpenAI and Vercel AI SDK) with blockchain interactions (via the Aptos SDK and Move Agent Kit), portfolio analytics, yield opportunities, and wallet management.
• The application leverages modern front-end tools (Next.js 15 with the App Router, Tailwind CSS, Shadcn UI, and Radix UI) combined with back-end API endpoints, Prisma-based database interaction (using PostgreSQL via Supabase), and custom blockchain libraries.
High-Level Architectural Components
a. Frontend (Client Side):
• Pages and Layouts: Found mainly under the app/ folder (app/page.tsx, app/dashboard/page.tsx, app/profile/page.tsx, etc.).
• UI Components: Custom React components under components/ (various UI widgets like buttons, charts, chat inputs, dashboards, onboarding flows, and wallet selectors).
• Global Styles: The global stylesheet (app/globals.css) and theming components (components/theme-provider.tsx).
b. API Endpoints (Backend API Layer):
• Located in app/api/ directory, segregated by functionalities:
• Chat endpoints (app/api/chat/route.ts): For interacting with the AI assistant.
• User-related endpoints (e.g., create, generate-ai-wallet, portfolio, profile, risk profile update/save, etc.).
• These endpoints handle user requests, communicate with the blockchain libraries, and facilitate AI conversations.
c. Business Logic & Blockchain Integration (Service Layer):
• Libraries in the lib/ directory provide core functions:
• Blockchain operations for Aptos, Panora, and related financial functionalities (found under lib/tools/aptos, lib/tools/joule, lib/tools/panora).
• Utility functions for portfolio analysis (like lib/clean-joule-all-positions-list.ts, lib/get-pool-address-by-token-name.ts).
• Wallet service integration to handle wallet interactions and security.
• Prisma database integration (lib/prisma.ts) interacts with the PostgreSQL database configured in prisma/schema.prisma.
d. Database:
• Managed via Prisma and PostgreSQL (with schema file located in prisma/schema.prisma). This layer stores user data, portfolio snapshots, risk profiles, and possibly transaction logs.
Relationships and Data Flow
• User interacts with the Frontend UI (via Next.js application components).
• Frontend sends requests to API endpoints (HTTP/REST style) for operations like chatting with the AI assistant, wallet creation, portfolio analysis, and transaction execution.
• API endpoints delegate heavy lifting to service layer functions in the lib directory. This includes blockchain queries (getting token details, fetching balances, transferring tokens/NFTs), and yield opportunities.
• Data from the blockchain and user actions is persisted and queried via the Prisma client and the database.
• External APIs (OpenAI API, Aptos blockchain endpoints, Panora API) are interfaced by the service layer functions.
Important Architectural Patterns and Technologies
• Separation of Concerns: Clear distinction between UI (view layer), API endpoints (controller layer), and service libraries (business logic layer).
• Modular Design: Code is organized into self-contained modules (e.g. separate directories for chat, profile, optimization in API, and blockchain operations in lib/tools).
• API Gateway-like Behavior: The Next.js API routes serve as gatekeepers, handling communication between the frontend and backend services.
• Security: Special attention is given to private key handling and encryption via environment variables and secure configurations.
• Use of Modern Tools: Next.js 15 with the App Router for a modern, file-system-based routing; Prisma for ORM; Vercel AI SDK and OpenAI API for enhanced AI functionalities.