# envoy-vc/son-of-anton-agentic-ethereum architecture

> Architecture diagram of the GitHub repository envoy-vc/son-of-anton-agentic-ethereum, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/envoy-vc/son-of-anton-agentic-ethereum
- Repository: https://github.com/envoy-vc/son-of-anton-agentic-ethereum

## Overview

##### Main Components
- Web Frontend (apps/web):
- Built with NextJS.
- Contains pages, layouts, components (including chat, hero, navbar), and styling.
- Houses API routes under the “src/app/api/trpc” folder, suggesting client-server interactions via TRPC.
- Backend/Server Package (packages/server):
- Contains the core server-side logic, helper functions, and schema definitions.
- Likely provides additional back-end API endpoints or business logic needed by the web app.
- Wallet Plugin (packages/wallet-plugin):
- Implements wallet-related functionality.
- Contains core logic for integrating web3 interactions, as indicated by files in “src/goat” and “src/common”.
- Database & Data Layer (within apps/web/src/db):
- Manages entities such as conversation and message.
- Represents the persistence layer required for chat functionalities and possibly other state information.
- AI & Utility Libraries (apps/web/src/lib and related folders):
- Implements the AI agent features (e.g., under “src/lib/ai”).
- Provides utility and sign-tool functions that are key to the secure signature process.
- State Management and Hooks:
- Uses React hooks and state management stores (apps/web/src/hooks and src/stores) to manage UI state and data flows across the application.

##### Relationships and Data Flows
- Client-to-Server Communication:
- The Web Frontend communicates with backend services via API endpoints (built using TRPC) which are defined both in the “apps/web” API routes and possibly extended in packages/server.
- Server-to-Wallet Plugin Integration:
- When handling web3 interactions, the backend likely interacts with the Wallet Plugin to sign transactions or verify signatures via threshold ECDSA.
- Database Interactions:
- Interactions from both front-end (via API calls) and possibly backend operations which read/write data to the database.
- AI Agent and Utility Components:
- That internal libraries (in apps/web/src/lib) are used to execute AI-driven tasks and process web3 interactions securely.

##### Architectural Patterns and Design Principles
- Monorepo Architecture:
- Modular Design:
- Clear separation between layers: UI (NextJS), server logic (packages/server), and wallet-related functionality (packages/wallet-plugin).
- API Layer:
- TRPC usage for type-safe APIs between the front end and back end.
- Security and Web3 Integration:
- Design’s focus on securely handling private keys via MPC based threshold ECDSA.

##### Specific Elements
- Clear Labels: Each major module (Web Frontend, API, Server, Wallet Plugin, Database, AI Libraries) should be clearly labeled.
- Detailed Subdivision: Since the project is modular, break down the “apps/web” module into further internal components (like API routes, components, state management) if necessary to capture as many details as possible.

- Additionally, show interactions with the Database (for storing chat and conversation entities) and the AI/Utility libraries for processing the AI functions.
- External integrations (like the Nillion-based secure key management) as additional nodes that the Wallet Plugin interfaces with.

## Diagram (Mermaid)

```mermaid
graph TD
    U["User"]:::external

    subgraph "Web Frontend (apps/web)"
        F["NextJS Frontend"]:::frontend
        UI["UI Components (pages, layouts, components)"]:::frontend
        API["TRPC API Endpoint"]:::frontend
        H["State Management & Hooks"]:::utility
        SStore["State Store"]:::utility
        DB["Database (Entities)"]:::database
        AI["AI Libraries"]:::utility
        SIGN["Sign Tool"]:::utility
    end

    subgraph "Packages"
        S["Backend/Server Package"]:::backend
        WP["Wallet Plugin"]:::plugin
    end

    EN["Nillion Network (Secure ECDSA)"]:::external

    U -->|"uses"| UI
    UI -->|"calls"| API
    UI -->|"manages"| H
    UI -->|"storesState"| SStore
    UI -->|"utilizes"| AI
    API -->|"dataAccess"| DB
    API -->|"businessLogic"| S
    S -->|"walletOps"| WP
    WP -->|"integrates"| EN

    click F "https://github.com/envoy-vc/son-of-anton-agentic-ethereum/tree/main/apps/web"
    click S "https://github.com/envoy-vc/son-of-anton-agentic-ethereum/tree/main/packages/server"
    click WP "https://github.com/envoy-vc/son-of-anton-agentic-ethereum/tree/main/packages/wallet-plugin"
    click DB "https://github.com/envoy-vc/son-of-anton-agentic-ethereum/tree/main/apps/web/src/db"
    click AI "https://github.com/envoy-vc/son-of-anton-agentic-ethereum/tree/main/apps/web/src/lib/ai"
    click SIGN "https://github.com/envoy-vc/son-of-anton-agentic-ethereum/blob/main/apps/web/src/lib/sign-tool.ts"
    click H "https://github.com/envoy-vc/son-of-anton-agentic-ethereum/tree/main/apps/web/src/hooks"
    click SStore "https://github.com/envoy-vc/son-of-anton-agentic-ethereum/tree/main/apps/web/src/stores"

    classDef frontend fill:#AEDFF7,stroke:#333,stroke-width:2px;
    classDef backend fill:#F7D6AE,stroke:#333,stroke-width:2px;
    classDef database fill:#C7F7AE,stroke:#333,stroke-width:2px;
    classDef plugin fill:#F7AEAE,stroke:#333,stroke-width:2px;
    classDef utility fill:#FFF7AE,stroke:#333,stroke-width:2px;
    classDef external fill:#E0E0E0,stroke:#333,stroke-width:2px;
```
