# future-internet-lab/attackfl architecture

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

- Interactive diagram: https://gitdiagram.com/future-internet-lab/attackfl
- Repository: https://github.com/future-internet-lab/attackfl

## Overview

Based on our analysis of the file tree and README, this project is a Python-based federated learning testbed designed to simulate a poisoning attack scenario. The project comprises a server (server.py) that orchestrates training rounds and multiple clients (client.py) that participate in federated learning – some of which are configured to perform different attack modes. It also interfaces with a RabbitMQ server (configured via a docker-compose.yaml snippet in the README) for asynchronous message passing between components.

##### Main Components
- Server Component: Represented by server.py. This is the central orchestrator that:
- Loads or initializes the DNN model (e.g., using CNN, RNN, or Transformer models).
- Configures training rounds (number of rounds, various parameters, validation, etc.).
- Saves and sends *.pth parameter files for continuous training.
- Client Component: Represented by client.py. Clients are designed to:
- To the server via RabbitMQ.
- Run local model training for a set number of epochs.
- Optionally perform adversarial poisoning attacks using various modes (Random, LIE, Min-Max, etc.).
- RabbitMQ Message Broker: This external service (set up via docker-compose with the RabbitMQ container) is essential for inter-process communication in the federated network.
- Configuration & Data:
- config.yaml: Holds global configuration for both server and clients (FL settings, learning rate, etc.).
- The dataset files (train_dataset.pkl.gz and test_dataset.pkl.gz) are used for training/validation.
- Core Library/Utilities: The src/ directory includes modules for logging (Log.py), machine learning model handling (Model.py), remote procedure call (RpcClient.py), and additional utilities/validation (Utils.py, Validation.py).

##### Relationships and Interactions
- The server sends out model parameters and training instructions to the clients via the RabbitMQ message broker.
- The clients receive parameters, perform local training (or execute an attack if instructed), and then send back their updates to the server.
- The server rounds are triggered by a training loop with a specified number of rounds (as configured in config.yaml).

##### Architectural Patterns and Design Principles
- Distributed Computing Pattern: Clear separation between the server (coordinator) and clients (workers).
- Message-oriented Middleware: Use of RabbitMQ for decoupled communication.
- Configuration-driven Behavior: The central configuration file (config.yaml) defines important operational parameters affecting both server and client behavior.
- Modular Code Organization: The use of the src/ directory for helper modules demonstrates a separation of concerns (logging, model handling, and utility functions separated into different modules).

##### Relevant Technologies and Frameworks
- Python (primary language).
- PyTorch (for deep learning and building DNN models).
- Pika (for RabbitMQ integration).
- Docker & docker-compose (for RabbitMQ container deployment).
- Additional libraries such as numpy, torchvision, requests, tqdm, and pyyaml.

##### Essential Components
- Server Application (server.py) – with internal modules (src/Model.py, src/Log.py, etc.) depicted as subcomponents if needed.
- Client Application (client.py) – also noting its potential to operate in different attack modes.
- Configuration File (config.yaml) – shown as a source of runtime parameters influencing both server and client.
- Data files (train/test_dataset.pkl.gz) joined to give an idea of the data flow from storage to training.
- Optional: A note or visual for persistent storage for *.pth files, showing the “stateful” aspect of the server, where the trained model parameters are saved and loaded.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Server Cluster
    subgraph "Server Cluster"
        S["Server (server.py)"]:::server
        subgraph "Core Modules"
            L["Logging Utility (Log.py)"]:::module
            M["Model Handling (Model.py)"]:::module
            R["RPC Client (RpcClient.py)"]:::module
            U["Additional Utilities (Utils.py)"]:::module
            V["Validation Utility (Validation.py)"]:::module
        end
        S --> L
        S --> M
        S --> R
        S --> U
        S --> V
    end

    %% Messaging Layer
    subgraph "Messaging Layer"
        MQ["RabbitMQ Broker"]:::broker
    end

    %% Client Cluster
    subgraph "Client Cluster"
        C["Client (client.py)\n(Genuine/Malicious Modes)"]:::client
    end

    %% Configuration and Data
    subgraph "Configuration & Data"
        CFG["Configuration (config.yaml)"]:::external
        subgraph "Data Storage"
            TD["Training Data (train_dataset.pkl.gz)"]:::external
            TT["Testing Data (test_dataset.pkl.gz)"]:::external
        end
    end

    %% Communication Flows
    S -->|"sends_params"| MQ
    MQ -->|"forwards_instructions"| C
    C -->|"sends_updates"| MQ
    MQ -->|"aggregates_updates"| S

    %% Config and Data Flows
    CFG --> S
    CFG --> C
    TD --> S
    TT --> S
    TD --> C

    %% Internal Persistence Note (model parameters saved)
    S ---|"saves_model(.pth)"| S

    %% Click Events
    click S "https://github.com/future-internet-lab/attackfl/blob/main/server.py"
    click C "https://github.com/future-internet-lab/attackfl/blob/main/client.py"
    click MQ "https://github.com/future-internet-lab/attackfl/blob/main/README.md"
    click CFG "https://github.com/future-internet-lab/attackfl/blob/main/config.yaml"
    click TD "https://github.com/future-internet-lab/attackfl/blob/main/train_dataset.pkl.gz"
    click TT "https://github.com/future-internet-lab/attackfl/blob/main/test_dataset.pkl.gz"
    click L "https://github.com/future-internet-lab/attackfl/blob/main/src/Log.py"
    click M "https://github.com/future-internet-lab/attackfl/blob/main/src/Model.py"
    click R "https://github.com/future-internet-lab/attackfl/blob/main/src/RpcClient.py"
    click U "https://github.com/future-internet-lab/attackfl/blob/main/src/Utils.py"
    click V "https://github.com/future-internet-lab/attackfl/blob/main/src/Validation.py"

    %% Styles
    classDef server fill:#FFDDCC,stroke:#333,stroke-width:2px;
    classDef client fill:#CCEEFF,stroke:#333,stroke-width:2px;
    classDef broker fill:#E0FFE0,stroke:#333,stroke-width:2px;
    classDef external fill:#FFE0E0,stroke:#333,stroke-width:2px;
    classDef module fill:#FFFFCC,stroke:#333,stroke-width:2px;
```
