# 0xoucan/moderia-aitrifectaethglobal architecture

> Architecture diagram of the GitHub repository 0xoucan/moderia-aitrifectaethglobal, 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/0xoucan/moderia-aitrifectaethglobal
- Repository: https://github.com/0xoucan/moderia-aitrifectaethglobal

## Overview

##### Main System Components
- Frontend: The Next.js application under the “src/app” directory, which is responsible for user interfaces (login, dashboards for agents, mentors, students, service booking, etc.). Also includes various shared components (inside “src/components”) and hooks for API queries.
- Backend API & Business Logic: The backend is encapsulated in “src/backend” and the “src/server” directories. The backend contains controllers (e.g., booking, payment, service, transcript, user), services (booking-service, payment-service, etc.), and a collection of business logic in dedicated action providers (ERC20 escrow, Moderia agent, Otter AI quality analysis, recall test, and service marketplace).
- External Integrations & Data Storage: The system integrates with Recall Network for secure, decentralized data storage and uses blockchain (Base Sepolia) for payment escrow and transactions. Otter AI is used for call analysis and quality verification. Telegram (and a potential demo mode) is used for alternate user interaction.
- Database and ORM: Prisma files and “prisma/schema.prisma” indicate the use of a relational database, while the README and environment variables (Nillion DB configs) suggest potential additional database integrations.

##### Determining Relationships and Interactions
- The Frontend communicates with API routes under “src/app/api” that serve as gateways to business logic.
- The API endpoints in the Next.js app (e.g., /api/recall, /api/users) interact with backend controllers in “src/server/controllers” to process booking, payment, and user-related functionality.
- Controllers and services call out to specialized action providers (located in “src/backend/src/action-providers/…”) for handling specific processes such as escrow transactions, service quality review, and dispute resolution.
- The action providers interface with external services such as:
- Blockchain networks for secure payment processing.
- Recall Network to store and retrieve decentralized data.
- Otter AI for call transcription and quality assessment.
- Telegram for bot-driven command interactions.
- There is also service integration between the Next.js UI components and shared libraries in “src/lib” (for example, the fullRecallFlow or recallActions which are used in both frontend and backend components).

##### Architectural Patterns & Design Principles
- Separation of Concerns: The project clearly decouples the UI (frontend components and pages), backend API processing, and specialized business logic (action providers).
- Microservices/Modular Approach: Even though the project runs as a unified codebase, the backend is split into various “action-provider” directories, each handling a discrete function (ERC20 escrow, Moderia, Otter AI, etc.). This modular approach enhances scalability and maintainability.
- Secure & Resilient Integration: Use of Recall Network for data security and blockchain for financial transactions emphasizes design principles around trust and security.
- Extensibility: With clearly separated layers (frontend, controllers, services, action providers), adding new providers or functionalities (like new mediation channels) can be done with minimal impact to other components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FE("Next.js Frontend"):::frontend
        FEComponents("Shared Components & Hooks"):::frontend
    end

    %% API Gateway
    subgraph "API Gateway"
        API("API Routes"):::backend
    end

    %% Backend Controllers and Services
    subgraph "Backend Processing"
        Controllers("Controllers<br/>(booking, payment, service, transcript, user)"):::backend
        Services("Services<br/>(booking-service, payment-service, service-service, transcript-service, user-service)"):::backend
    end

    %% Action Providers / Business Logic Modules
    subgraph "Action Providers"
        ERC20("ERC20 Escrow Provider"):::provider
        Moderia("Moderia Action Provider"):::provider
        OtterAI("Otter AI Action Provider"):::provider
        RecallTest("Recall Test Provider"):::provider
        ServiceMP("Service Marketplace Provider"):::provider
    end

    %% External Integrations & Storage
    subgraph "External Integrations & Storage"
        Blockchain("Blockchain Network (ERC20)"):::external
        RecallNet("Recall Network (Decentralized Storage)"):::external
        OtterExt("Otter AI Service"):::external
        Telegram("Telegram Bot Interface"):::external
    end

    %% Database/ORM Layer
    subgraph "Database/ORM"
        Prisma("Prisma Schema & Migrations"):::database
        Seed("Seed Script"):::database
    end

    %% Connections
    FE -->|"sends-request"| API
    FEComponents -->|"supports FE"| FE

    API -->|"forwards-request"| Controllers
    Controllers -->|"calls-business-logic"| Services

    Services -->|"triggers"| ERC20
    Services -->|"handles-mediation"| Moderia
    Services -->|"initiates-quality"| OtterAI
    Services -->|"runs-recall"| RecallTest
    Services -->|"executes-marketplace"| ServiceMP

    ERC20 -->|"uses"| Blockchain
    OtterAI -->|"analyzes-via"| OtterExt
    RecallTest -->|"stores-data"| RecallNet
    Moderia -->|"integrates-with"| Telegram

    %% Response flow (dotted back pathways)
    Blockchain -. "returns-status" .-> ERC20
    OtterExt -. "returns-analysis" .-> OtterAI
    RecallNet -. "returns-storage-info" .-> RecallTest
    Telegram -. "returns-commands" .-> Moderia

    Services -->|"sends-response"| API
    API -->|"responds-to"| FE

    Services -->|"accesses"| Prisma
    Prisma -->|"seeded-by"| Seed

    %% Click Events
    click FE "https://github.com/0xoucan/moderia-aitrifectaethglobal/tree/main/src/app"
    click FEComponents "https://github.com/0xoucan/moderia-aitrifectaethglobal/tree/main/src/app/components"
    click API "https://github.com/0xoucan/moderia-aitrifectaethglobal/tree/main/src/app/api"
    click Controllers "https://github.com/0xoucan/moderia-aitrifectaethglobal/tree/main/src/server/controllers"
    click Services "https://github.com/0xoucan/moderia-aitrifectaethglobal/tree/main/src/services"
    click ERC20 "https://github.com/0xoucan/moderia-aitrifectaethglobal/tree/main/src/backend/src/action-providers/erc20-escrow"
    click Moderia "https://github.com/0xoucan/moderia-aitrifectaethglobal/tree/main/src/backend/src/action-providers/moderia"
    click OtterAI "https://github.com/0xoucan/moderia-aitrifectaethglobal/tree/main/src/backend/src/action-providers/otter-ai"
    click RecallTest "https://github.com/0xoucan/moderia-aitrifectaethglobal/tree/main/src/backend/src/action-providers/recall-test"
    click ServiceMP "https://github.com/0xoucan/moderia-aitrifectaethglobal/tree/main/src/backend/src/action-providers/service-marketplace"
    click Telegram "https://github.com/0xoucan/moderia-aitrifectaethglobal/blob/main/src/backend/src/telegram-interface.ts"
    click Prisma "https://github.com/0xoucan/moderia-aitrifectaethglobal/blob/main/prisma/schema.prisma"
    click Seed "https://github.com/0xoucan/moderia-aitrifectaethglobal/blob/main/prisma/seed.ts"

    %% Styles
    classDef frontend fill:#a6cee3,stroke:#1f78b4,stroke-width:2px;
    classDef backend fill:#b2df8a,stroke:#33a02c,stroke-width:2px;
    classDef provider fill:#fb9a99,stroke:#e31a1c,stroke-width:2px;
    classDef external fill:#fdbf6f,stroke:#ff7f00,stroke-width:2px;
    classDef database fill:#cab2d6,stroke:#6a3d9a,stroke-width:2px;
```
