# superioragents/superior-agents architecture

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

- Interactive diagram: https://gitdiagram.com/superioragents/superior-agents
- Repository: https://github.com/superioragents/superior-agents

## Overview

##### Main Components
- Agent Module: This is the core Python-based agent that handles both trading and marketing. It has its own directory with subdirectories for scripts, core source code (agent/src), configurations (agent/starter JSONs for marketing and trading), Docker settings (agent/docker), and dependency management (requirements, pyproject.toml).
- Meta-Swap API: A Node/TypeScript-based service (indicated by package.json, Dockerfile, and source code under meta-swap-api/src) dedicated to handling swap operations. It manages blockchain interactions (addresses, signers, swap providers) and exposes endpoints for swap functionality.
- Notification Service: A Python service that aggregates data from various sources (e.g., scraping Twitter data) to feed agent information into the system. It is containerized (Dockerfile, docker-compose.yml) and contains components for cron jobs and server functionality.
- rag-api: Another Python service responsible for retrieval or processing (likely related to retrieval-augmented generation “RAG”) although simpler in structure (only a few scripts) than the others.
- REST API for the Python Server-side: A FastAPI-based backend structured under rest-api. It manages database interactions (agent_sessions, chat_history, notifications, payments, etc.), application routes, and utility functions. It is set up to initialize databases, and allows agents to interact with the system via APIs.
- External Configuration/Integration: There are several environment variables across components ensuring connectivity to external APIs (Twitter, blockchain providers, etc.), plus specialized configuration such as Ethereum private keys and ABI files for interacting with smart contracts.

##### Relationships & Interactions
- The Agent Module interacts with:
- The Python server’s REST API (acting as a backend database or orchestration engine).
- Token swapping through integration with the Meta-Swap API.
- Not only does it interact with external blockchain networks (via provided ABI files) for trading, but also uses the configuration JSON files to dictate behavior.
- The Meta-Swap API provides transactional endpoints to facilitate swaps. It interacts with blockchain helpers, signers (eth and sol services), and multiple swap providers (eg. 1inch, Kyber, etc.).
- The Notification Service collects data (market trends, Twitter feeds, etc.) that are later utilized by the agents to assess performance and adjust strategies.
- The rag-api may act as a data aggregator or preprocessing service for agent workflows (for instance, providing enhanced data via retrieval augmented generation flows).
- The REST API is the central point of integration that allows agents and external services like the notification service to interact with persistent data (users, agent sessions, wallet snapshots, etc.).

##### Architectural Patterns & Design Principles
- Modular architecture: Separation of concerns is evident between the trading/marketing agent, swap API, notifications, and REST services, which could be deployed independently.
- Microservices pattern: Each component (agent, meta-swap-api, notification, rag-api, and rest-api) is containerized using Docker. They likely communicate over defined APIs.
- Containerization & Deployment: Multiple Dockerfiles and docker-compose configurations indicate an emphasis on reproducible environments and container orchestration.
- Use of configuration files and environment variables: These outline how external integrations (APIs, blockchain connectivity, etc.) are provided, ensuring a clear separation between code and sensitive data/configuration.
- Extensibility: The agent’s configurable JSON files (marketing.json, trading.json) allow dynamic behavior and underscore both configuration-driven development and plug-and-play extensibility.

##### Final Recommendations
- Then progressively refine to add submodules (for example, under the agent module, illustrate where trading and marketing logic reside).
- That integration points for external APIs (Twitter, blockchain nodes, etc.) are clearly marked.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Agent Module Subgraph
    subgraph "Agent Module (Python)"
        A1("Core Source (agent/src)"):::python
        A2("Configurations (agent/starter)"):::python
        A3("Docker Settings (agent/docker)"):::python
        A4("Utility Scripts (agent/scripts)"):::python
    end

    %% Meta-Swap API Subgraph
    subgraph "Meta-Swap API (TypeScript/Node.js)"
        M1("Source Code (meta-swap-api/src)"):::nodejs
        M2("Package Config (meta-swap-api/package.json)"):::nodejs
        M3("Docker Settings (meta-swap-api/Dockerfile)"):::nodejs
    end

    %% Notification Service Subgraph
    subgraph "Notification Service (Python)"
        N1("Server (notification/server.py)"):::python
        N2("Cron Worker (notification/cron_worker.py)"):::python
        N3("Service Scripts (notification/scrapers & twitter_service)"):::python
        N4("Docker & Compose (notification/Dockerfile, docker-compose.yml)"):::python
    end

    %% rag-api Subgraph
    subgraph "rag-api (Python)"
        R1("API Endpoints (rag-api/api.py)"):::python
        R2("Data Fetcher (rag-api/fetch.py)"):::python
        R3("Data Store (rag-api/store.py)"):::python
    end

    %% REST API Subgraph
    subgraph "REST API (FastAPI/Python)"
        RT1("Routes & Utilities (rest-api/routes, interface, config.py)"):::python
        RT2("Database Interfaces (rest-api/db)"):::python
        RT3("Docker Setup (rest-api/Dockerfile, README)"):::python
    end

    %% External and Database Nodes
    E1("Blockchain Networks & Swap Providers"):::external
    E2("External APIs (Twitter,etc.)"):::external
    DB["Database (Persistent Storage)"]:::container

    %% Connections between components
    A1 -->|"swap_request"| M1
    A1 <-->|"data_exchange"| RT1
    N1 -->|"alerts_feed"| RT1
    R1 -->|"data_retrieval"| RT1
    M1 -->|"blockchain_interact"| E1
    RT1 -->|"stores_data"| DB
    E2 -->|"twitter_api_scrape"| N3
    N3 -->|"feed_data"| N1

    %% Click Events for Agent Module
    click A1 "https://github.com/superioragents/superior-agents/tree/main/agent/src"
    click A2 "https://github.com/superioragents/superior-agents/tree/main/agent/starter"
    click A3 "https://github.com/superioragents/superior-agents/tree/main/agent/docker"
    click A4 "https://github.com/superioragents/superior-agents/tree/main/agent/scripts"

    %% Click Events for Meta-Swap API
    click M1 "https://github.com/superioragents/superior-agents/tree/main/meta-swap-api/src"
    click M2 "https://github.com/superioragents/superior-agents/blob/main/meta-swap-api/package.json"
    click M3 "https://github.com/superioragents/superior-agents/tree/main/meta-swap-api/Dockerfile"

    %% Click Events for Notification Service
    click N1 "https://github.com/superioragents/superior-agents/blob/main/notification/server.py"
    click N2 "https://github.com/superioragents/superior-agents/blob/main/notification/cron_worker.py"
    click N3 "https://github.com/superioragents/superior-agents/blob/main/notification/scrapers.py"
    click N4 "https://github.com/superioragents/superior-agents/tree/main/notification/Dockerfile"

    %% Click Events for rag-api
    click R1 "https://github.com/superioragents/superior-agents/blob/main/rag-api/api.py"
    click R2 "https://github.com/superioragents/superior-agents/blob/main/rag-api/fetch.py"
    click R3 "https://github.com/superioragents/superior-agents/blob/main/rag-api/store.py"

    %% Click Events for REST API
    click RT1 "https://github.com/superioragents/superior-agents/tree/main/rest-api/routes"
    click RT2 "https://github.com/superioragents/superior-agents/tree/main/rest-api/db"
    click RT3 "https://github.com/superioragents/superior-agents/tree/main/rest-api/Dockerfile"

    %% Class Definitions for Styling
    classDef python fill:#AED6F1,stroke:#2874A6,stroke-width:2px;
    classDef nodejs fill:#ABEBC6,stroke:#28B463,stroke-width:2px;
    classDef external fill:#F5CBA7,stroke:#DC7633,stroke-width:2px;
    classDef container fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
```
