# megayours/megaforwarder architecture

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

- Interactive diagram: https://gitdiagram.com/megayours/megaforwarder
- Repository: https://github.com/megayours/megaforwarder

## Overview

##### Project Type and Purpose
- MegaForwarder is a backend service with a modular architecture that handles tasks related to blockchain protocols (evidenced by files like ERC20Listener, ERC721Listener, SolanaListener, and plugins for forwarding actions such as ERC20Forwarder, ERC721Forwarder, etc.).
- The application routes HTTP requests (see the “routes” directory for endpoints related to task creation, preparation, and validation) and processes them via a core framework that makes heavy use of listeners and plugins.
- It is designed to be easily extendable with additional plugins and listeners to support multiple blockchain protocols and related forwarding/processing functionalities.

##### Analyzing the File Structure
a. Top-level structure:
- Configuration: The “src/config” folder (e.g., OracleConfig.ts) likely holds environment and integration setup.
- Core: The “src/core” directory contains the backbone of the application:
- Subdirectories like “cache”, “errors”, “interfaces”, “listener”, “plugin”, “task”, and various “types” indicate a modular design.
- Registries for plugins and listeners (e.g., PluginRegistry.ts, ListenerRegistry.ts) suggest dynamic management and registration.
- Specialized Modules:
- The “src/listeners” folder implements domain-specific event listeners (ERC20, ERC721, Solana, etc.).
- The “src/plugins” folder houses plugins that encapsulate the actual forwarding logic, processing, or integration with external services.
- API Routes: The “src/routes” folder outlines HTTP endpoints (e.g., heliusWebhook.ts, taskCreate.ts, taskPrepare.ts, taskValidate.ts) that integrate with external requests.
- Utility Functions: “src/util” contains helpers (such as for ABIs, auth, error handling, crypto, etc.) that support the core business logic.
b. Supporting Files:
- Dockerfile and docker-compose.yml for containerizing and deploying the system.
- The Bun package (package.json and bun.lock) indicates a fast runtime environment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% API Gateway Subgraph
    subgraph "API Gateway / HTTP Routes"
        taskCreate["taskCreate (Endpoint)"]
        taskPrepare["taskPrepare (Endpoint)"]
        taskValidate["taskValidate (Endpoint)"]
        heliusWebhook["heliusWebhook (Endpoint)"]
    end

    %% Core Processing Engine Subgraph
    subgraph "Core Processing Engine"
        taskProcessor["Task Processor"]
        listenerRegistry["Listener Registry"]
        pluginRegistry["Plugin Registry"]
        errorHandling["Error Handling"]
    end

    %% Listeners Subgraph
    subgraph "Listener Modules"
        ERC20Listener["ERC20Listener"]
        ERC721Listener["ERC721Listener"]
        MocaStakeListener["MocaStakeListener"]
        SolanaListener["SolanaListener"]
    end

    %% Plugins Subgraph
    subgraph "Plugin Modules"
        ERC20Forwarder["ERC20Forwarder"]
        ERC721Forwarder["ERC721Forwarder"]
        MocaStakeForwarder["MocaStakeForwarder"]
        SolanaMegaForwarder["SolanaMegaForwarder"]
        AccountLinker["AccountLinker"]
        EVMContractRegistration["EVMContractRegistration"]
        ManageMegadata["ManageMegadata"]
        SolanaBalanceUpdater["SolanaBalanceUpdater"]
    end

    %% Configuration Module Subgraph
    subgraph "Configuration Module"
        OracleConfig["OracleConfig"]
        ConfigIndex["Config Index"]
    end

    %% Utilities Node
    Utilities["Utilities"]

    %% Containerization / Deployment Subgraph
    subgraph "Containerization / Deployment"
        Dockerfile["Dockerfile"]
        DockerCompose["docker-compose.yml"]
    end

    %% Relationships

    %% API routes feed into Core Task Processor
    taskCreate -->|"TaskRequest"| taskProcessor
    taskPrepare -->|"TaskRequest"| taskProcessor
    taskValidate -->|"TaskRequest"| taskProcessor
    heliusWebhook -->|"WebhookEvent"| taskProcessor

    %% Core Process interacts with registries
    taskProcessor -->|"RegisterListener"| listenerRegistry
    taskProcessor -->|"RegisterPlugin"| pluginRegistry
    taskProcessor -->|"Error"| errorHandling

    %% Listener Registry receives events from Listeners
    ERC20Listener -->|"EventNotification"| listenerRegistry
    ERC721Listener -->|"EventNotification"| listenerRegistry
    MocaStakeListener -->|"EventNotification"| listenerRegistry
    SolanaListener -->|"EventNotification"| listenerRegistry

    %% Plugin Registry triggers plugins
    pluginRegistry -->|"Invoke"| ERC20Forwarder
    pluginRegistry -->|"Invoke"| ERC721Forwarder
    pluginRegistry -->|"Invoke"| MocaStakeForwarder
    pluginRegistry -->|"Invoke"| SolanaMegaForwarder
    pluginRegistry -->|"Invoke"| AccountLinker
    pluginRegistry -->|"Invoke"| EVMContractRegistration
    pluginRegistry -->|"Invoke"| ManageMegadata
    pluginRegistry -->|"Invoke"| SolanaBalanceUpdater

    %% Configuration feeds into API and Core
    OracleConfig --- taskProcessor
    ConfigIndex --- taskProcessor
    OracleConfig --- taskCreate
    ConfigIndex --- heliusWebhook

    %% Utilities support modules
    Utilities --- taskProcessor
    Utilities --- ERC20Listener
    Utilities --- ERC20Forwarder

    %% Containerization supports deployment of the system
    Dockerfile --- taskProcessor
    DockerCompose --- taskProcessor

    %% Click Events for API Gateway / Routes
    click taskCreate "https://github.com/megayours/megaforwarder/blob/main/src/routes/taskCreate.ts"
    click taskPrepare "https://github.com/megayours/megaforwarder/blob/main/src/routes/taskPrepare.ts"
    click taskValidate "https://github.com/megayours/megaforwarder/blob/main/src/routes/taskValidate.ts"
    click heliusWebhook "https://github.com/megayours/megaforwarder/blob/main/src/routes/heliusWebhook.ts"

    %% Click Events for Core Processing Engine
    click pluginRegistry "https://github.com/megayours/megaforwarder/blob/main/src/core/plugin/PluginRegistry.ts"
    click listenerRegistry "https://github.com/megayours/megaforwarder/blob/main/src/core/listener/ListenerRegistry.ts"
    click taskProcessor "https://github.com/megayours/megaforwarder/tree/main/src/core"

    %% Click Events for Listener Modules
    click ERC20Listener "https://github.com/megayours/megaforwarder/blob/main/src/listeners/ERC20Listener.ts"
    click ERC721Listener "https://github.com/megayours/megaforwarder/blob/main/src/listeners/ERC721Listener.ts"
    click MocaStakeListener "https://github.com/megayours/megaforwarder/blob/main/src/listeners/MocaStakeListener.ts"
    click SolanaListener "https://github.com/megayours/megaforwarder/blob/main/src/listeners/SolanaListener.ts"

    %% Click Events for Plugin Modules
    click ERC20Forwarder "https://github.com/megayours/megaforwarder/blob/main/src/plugins/ERC20Forwarder.ts"
    click ERC721Forwarder "https://github.com/megayours/megaforwarder/blob/main/src/plugins/ERC721Forwarder.ts"
    click MocaStakeForwarder "https://github.com/megayours/megaforwarder/blob/main/src/plugins/MocaStakeForwarder.ts"
    click SolanaMegaForwarder "https://github.com/megayours/megaforwarder/blob/main/src/plugins/SolanaMegaForwarder.ts"
    click AccountLinker "https://github.com/megayours/megaforwarder/blob/main/src/plugins/AccountLinker.ts"
    click EVMContractRegistration "https://github.com/megayours/megaforwarder/blob/main/src/plugins/EVMContractRegistration.ts"
    click ManageMegadata "https://github.com/megayours/megaforwarder/blob/main/src/plugins/ManageMegadata.ts"
    click SolanaBalanceUpdater "https://github.com/megayours/megaforwarder/blob/main/src/plugins/SolanaBalanceUpdater.ts"

    %% Click Events for Configuration Module
    click OracleConfig "https://github.com/megayours/megaforwarder/blob/main/src/config/OracleConfig.ts"
    click ConfigIndex "https://github.com/megayours/megaforwarder/blob/main/src/config/index.ts"

    %% Click Event for Utilities
    click Utilities "https://github.com/megayours/megaforwarder/tree/main/src/util"

    %% Click Events for Containerization / Deployment
    click Dockerfile "https://github.com/megayours/megaforwarder/tree/main/Dockerfile"
    click DockerCompose "https://github.com/megayours/megaforwarder/blob/main/docker-compose.yml"

    %% Styles
    classDef api fill:#FFD700,stroke:#8B8000,stroke-width:2px;
    classDef core fill:#87CEEB,stroke:#4682B4,stroke-width:2px;
    classDef listener fill:#FFA07A,stroke:#CD5C5C,stroke-width:2px;
    classDef plugin fill:#90EE90,stroke:#32CD32,stroke-width:2px;
    classDef config fill:#D3D3D3,stroke:#A9A9A9,stroke-width:2px;
    classDef utility fill:#FFB6C1,stroke:#FF69B4,stroke-width:2px;
    classDef container fill:#DDA0DD,stroke:#9932CC,stroke-width:2px;

    %% Assign classes to nodes
    class taskCreate,taskPrepare,taskValidate,heliusWebhook api;
    class taskProcessor,listenerRegistry,pluginRegistry,errorHandling core;
    class ERC20Listener,ERC721Listener,MocaStakeListener,SolanaListener listener;
    class ERC20Forwarder,ERC721Forwarder,MocaStakeForwarder,SolanaMegaForwarder,AccountLinker,EVMContractRegistration,ManageMegadata,SolanaBalanceUpdater plugin;
    class OracleConfig,ConfigIndex config;
    class Utilities utility;
    class Dockerfile,DockerCompose container;
```
