# ariiellus/eth-trifecta architecture

> Architecture diagram of the GitHub repository ariiellus/eth-trifecta, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ariiellus/eth-trifecta
- Repository: https://github.com/ariiellus/eth-trifecta

## Overview

##### Main Components
a. Frontend (User Interface):
- Represented by the Next.js part of the project under the “src/app” directory.
- Includes pages (login, dashboard for agent/mentor/student, service listings), UI components, and providers.
- Different operating modes are supported (terminal, Telegram, chat mode, demo mode).

b. API Layer & Server Controllers:
- The “src/app/api” folder comprises RESTful API endpoints for “recall”, “users” (with sub-routes for bookings, payments, services, stats), etc.
- On the backend side, “src/server/controllers” includes controllers for bookings, payments, transcripts, and user management.
- Services under “src/services” provide business logic for managing bookings, payments, and service processing.

c. Backend and Action Providers:
- The “src/backend” folder houses the business logic closely related to blockchain actions and integrations.
- Within “src/backend/src/action-providers”, there are multiple sub-folders for various functionalities such as ERC20 escrow, Moderia mediation, Otter AI quality verification, recall protocol testing, recall test, and service marketplace.
- These action providers encapsulate interactions with external systems (blockchain, recall network, and Otter AI) and include testing modules as well.

d. Database & Secure Data Storage:
- The README details a database schema with collections for services, bookings, reviews, transactions, and meetings.
- Secure data storage is implemented using Recall Network / Nillion DB (as indicated by environment variables and schema details).

##### Relationships and Interactions
- How user actions (like creating a service, booking, or payment) trigger calls to API endpoints. For example, the frontend API routes (under “src/app/api”) communicate with the server controllers (in “src/server/controllers”) and then with services (in “src/services”).
- Interaction between the backend and the various action providers (ERC20 Escrow, Otter AI, Moderia, etc.). These providers interact with external systems (blockchain networks, Recall Network, and Telegram for chat modes).
- Secure data storage, which is used for storing sensitive service metadata, transaction history, meeting transcripts, and dispute data.

##### Incorporate Architectural Patterns and Technologies
- Separation of concerns: Frontend (UI/UX via Next.js), Backend (API endpoints and controllers), Business Logic (action providers), and External Integrations (blockchain, Recall Network, Otter AI).
- Backend Services & Action Providers (e.g., modules grouped together)

- Clear labels for each component:
- "Next.js Frontend" with pages like login, dashboard, and service listing.
- "API Gateway" that exposes endpoints (recall, users, etc.) to handle data flow.
- "Server Controllers & Business Services" that process requests and coordinate actions (booking, payment, meeting transcription).
- "Action Providers" for specific tasks like ERC20 Escrow, Moderia mediation, Otter AI analysis, etc.
- "Database / Secure Storage" representing Recall Network or Nillion DB where transactional and quality data is stored.
- "External Integrations" pointing to Blockchain (Base Sepolia), Otter AI, and possibly Telegram.
- Client → Frontend UI → API Endpoint → Controller/Service → Action Provider → External Systems → Database.
- For example, from the “ERC20 Escrow” provider to “Blockchain Network” and then back to update payment status.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Layer
    A["Next.js Frontend (UI)"]:::frontend

    %% API Layer
    B["API Endpoints"]:::api

    %% Server Controllers
    C["Server Controllers"]:::controller

    %% Business Logic Services
    D["Business Logic Services"]:::service

    %% Action Providers Subgraph
    subgraph "Action Providers"
        E1["ERC20 Escrow Action Provider"]:::action
        E2["Moderia Mediation Action Provider"]:::action
        E3["Otter AI Quality Verification Action Provider"]:::action
        E4["Recall Test Action Provider"]:::action
        E5["Recall Protocol Action Provider"]:::action
        E6["Service Marketplace Action Provider"]:::action
    end

    %% External Systems
    F["Blockchain Network"]:::external
    F2["Telegram Bot"]:::external
    F3["Otter AI External"]:::external
    G["Secure Data Storage (Recall Network/Nillion DB)"]:::db

    %% Data Flow Connections
    A -->|"sends requests"| B
    B -->|"routes calls"| C
    C -->|"orchestrates"| D
    D -->|"triggers"| E1
    D -->|"triggers"| E2
    D -->|"triggers"| E3
    D -->|"triggers"| E4
    D -->|"triggers"| E5
    D -->|"triggers"| E6

    %% External interactions from Action Providers
    E1 -->|"processes payment"| F
    F -->|"confirms transaction"| E1

    E3 -->|"sends media for analysis"| F3
    F3 -->|"returns quality data"| E3

    E2 -->|"manages chat mode"| F2

    %% Database interactions
    D -->|"updates logs"| G
    E1 -->|"updates payment status"| G
    E2 -->|"records mediation outcome"| G
    E3 -->|"stores transcript"| G
    E4 -->|"saves test result"| G
    E5 -->|"saves protocol validation"| G
    E6 -->|"updates marketplace"| G

    %% Direct frontend external interaction (for multi-mode chat)
    A -->|"initiates chat"| F2

    %% Click Events
    click A "https://github.com/ariiellus/eth-trifecta/tree/main/src/app"
    click B "https://github.com/ariiellus/eth-trifecta/tree/main/src/app/api"
    click C "https://github.com/ariiellus/eth-trifecta/tree/main/src/server/controllers"
    click D "https://github.com/ariiellus/eth-trifecta/tree/main/src/services"
    click E1 "https://github.com/ariiellus/eth-trifecta/tree/main/src/backend/src/action-providers/erc20-escrow"
    click E2 "https://github.com/ariiellus/eth-trifecta/tree/main/src/backend/src/action-providers/moderia"
    click E3 "https://github.com/ariiellus/eth-trifecta/tree/main/src/backend/src/action-providers/otter-ai"
    click E4 "https://github.com/ariiellus/eth-trifecta/tree/main/src/backend/src/action-providers/recall-test"
    click E5 "https://github.com/ariiellus/eth-trifecta/tree/main/src/backend/src/action-providers/recall-protocol"
    click E6 "https://github.com/ariiellus/eth-trifecta/tree/main/src/backend/src/action-providers/service-marketplace"
    click G "https://github.com/ariiellus/eth-trifecta/blob/main/prisma/schema.prisma"

    %% Styling
    classDef frontend fill:#add8e6,stroke:#000,stroke-width:1px;
    classDef api fill:#90ee90,stroke:#000,stroke-width:1px;
    classDef controller fill:#ffff99,stroke:#000,stroke-width:1px;
    classDef service fill:#ffa500,stroke:#000,stroke-width:1px;
    classDef action fill:#ffb6c1,stroke:#000,stroke-width:1px;
    classDef external fill:#d3d3d3,stroke:#000,stroke-width:1px,stroke-dasharray: 5 5;
    classDef db fill:#e0ffff,stroke:#000,stroke-width:1px;
```
