# shoaib-devpy/blockchain_fl_framework_py architecture

> Architecture diagram of the GitHub repository shoaib-devpy/blockchain_fl_framework_py, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shoaib-devpy/blockchain_fl_framework_py
- Repository: https://github.com/shoaib-devpy/blockchain_fl_framework_py

## Overview

This is a financial-ML framework combining federated learning with blockchain consensus and security techniques. Its main workflow preprocesses credit-card data, partitions it for client-side training, aggregates local models, evaluates and visualizes results, and also records blocks through a PBFT-backed chain. The map includes the documented security and smart-contract capabilities. The excerpts show key calls and PBFT message handling; other connections are included only where the main.py reference index or README supports them. Several main.py sections and visualization internals were not shown, so their internal relationships are not expanded.

Main entry points: [`main.py`](https://github.com/shoaib-devpy/blockchain_fl_framework_py/blob/main/main.py) (Workflow orchestrator), [`pbft/pbft_node.py`](https://github.com/shoaib-devpy/blockchain_fl_framework_py/blob/main/pbft/pbft_node.py) (PBFT node), [`blockchain/blockchain.py`](https://github.com/shoaib-devpy/blockchain_fl_framework_py/blob/main/blockchain/blockchain.py) (Blockchain), [`pbft/network.py`](https://github.com/shoaib-devpy/blockchain_fl_framework_py/blob/main/pbft/network.py) (PBFT network)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Data and ML"]
  node_main["Workflow orchestrator<br/>[main.py]"]
  node_preprocess["Data preprocessing"]
  node_clients["Federated clients<br/>[client.py]"]
  node_aggregator["Model aggregation<br/>[aggregator.py]"]
end

subgraph group_chain["Blockchain and PBFT"]
  node_smart_contract["Smart contract<br/>[smart_contract.py]"]
  node_blockchain[("Blockchain<br/>[blockchain.py]")]
  node_network["PBFT network<br/>[network.py]"]
  node_pbft_node["PBFT node<br/>[pbft_node.py]"]
  node_pbft_message["PBFT message<br/>[pbft_message.py]"]
end

subgraph group_security["Security"]
  node_security_training["Adversarial training"]
  node_anomaly["Anomaly detection"]
end

subgraph group_results["Evaluation and Visualization"]
  node_evaluation["Model evaluation<br/>[main.py]"]
  node_visualization["Result visualization<br/>[visualization.py]"]
end

node_user(("Framework operator"))
node_dataset_service["Dataset provider"]

node_user -->|"runs workflow"| node_main
node_main -->|"loads and partitions"| node_preprocess
node_preprocess -->|"downloads dataset"| node_dataset_service
node_main -->|"trains clients"| node_clients
node_main -->|"aggregates models"| node_aggregator
node_main -->|"applies training"| node_security_training
node_main -->|"runs detection"| node_anomaly
node_main -->|"evaluates models"| node_evaluation
node_main -->|"plots results"| node_visualization
node_main -->|"uses contract"| node_smart_contract
node_main -->|"adds blocks"| node_blockchain
node_blockchain -->|"creates network"| node_network
node_blockchain -->|"initializes nodes"| node_pbft_node
node_pbft_node -->|"broadcasts messages"| node_network
node_network -->|"delivers messages"| node_pbft_node
node_pbft_node -->|"creates messages"| node_pbft_message

click node_main "https://github.com/shoaib-devpy/blockchain_fl_framework_py/blob/main/main.py"
click node_preprocess "https://github.com/shoaib-devpy/blockchain_fl_framework_py/blob/main/utils/data_preprocessing.py"
click node_clients "https://github.com/shoaib-devpy/blockchain_fl_framework_py/blob/main/federated_learning/client.py"
click node_aggregator "https://github.com/shoaib-devpy/blockchain_fl_framework_py/blob/main/federated_learning/aggregator.py"
click node_security_training "https://github.com/shoaib-devpy/blockchain_fl_framework_py/blob/main/security/adversarial_training.py"
click node_anomaly "https://github.com/shoaib-devpy/blockchain_fl_framework_py/blob/main/security/anomaly_detection.py"
click node_evaluation "https://github.com/shoaib-devpy/blockchain_fl_framework_py/blob/main/main.py"
click node_visualization "https://github.com/shoaib-devpy/blockchain_fl_framework_py/blob/main/visualization.py"
click node_smart_contract "https://github.com/shoaib-devpy/blockchain_fl_framework_py/blob/main/blockchain/smart_contract.py"
click node_blockchain "https://github.com/shoaib-devpy/blockchain_fl_framework_py/blob/main/blockchain/blockchain.py"
click node_network "https://github.com/shoaib-devpy/blockchain_fl_framework_py/blob/main/pbft/network.py"
click node_pbft_node "https://github.com/shoaib-devpy/blockchain_fl_framework_py/blob/main/pbft/pbft_node.py"
click node_pbft_message "https://github.com/shoaib-devpy/blockchain_fl_framework_py/blob/main/pbft/pbft_message.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_preprocess,node_clients,node_aggregator toneBlue
class node_smart_contract,node_blockchain,node_network,node_pbft_node,node_pbft_message toneAmber
class node_security_training,node_anomaly toneMint
class node_evaluation,node_visualization toneRose
class node_user,node_dataset_service toneIndigo
```

## Components

### Data and ML

- [Workflow orchestrator](https://github.com/shoaib-devpy/blockchain_fl_framework_py/blob/main/main.py): `main.py`
- [Data preprocessing](https://github.com/shoaib-devpy/blockchain_fl_framework_py/blob/main/utils/data_preprocessing.py): `utils/data_preprocessing.py`
- [Federated clients](https://github.com/shoaib-devpy/blockchain_fl_framework_py/blob/main/federated_learning/client.py): `federated_learning/client.py`
- [Model aggregation](https://github.com/shoaib-devpy/blockchain_fl_framework_py/blob/main/federated_learning/aggregator.py): `federated_learning/aggregator.py`

### Blockchain and PBFT

- [Smart contract](https://github.com/shoaib-devpy/blockchain_fl_framework_py/blob/main/blockchain/smart_contract.py): `blockchain/smart_contract.py`
- [Blockchain](https://github.com/shoaib-devpy/blockchain_fl_framework_py/blob/main/blockchain/blockchain.py): `blockchain/blockchain.py`
- [PBFT network](https://github.com/shoaib-devpy/blockchain_fl_framework_py/blob/main/pbft/network.py): `pbft/network.py`
- [PBFT node](https://github.com/shoaib-devpy/blockchain_fl_framework_py/blob/main/pbft/pbft_node.py): `pbft/pbft_node.py`
- [PBFT message](https://github.com/shoaib-devpy/blockchain_fl_framework_py/blob/main/pbft/pbft_message.py): `pbft/pbft_message.py`

### Security

- [Adversarial training](https://github.com/shoaib-devpy/blockchain_fl_framework_py/blob/main/security/adversarial_training.py): `security/adversarial_training.py`
- [Anomaly detection](https://github.com/shoaib-devpy/blockchain_fl_framework_py/blob/main/security/anomaly_detection.py): `security/anomaly_detection.py`

### Evaluation and Visualization

- [Model evaluation](https://github.com/shoaib-devpy/blockchain_fl_framework_py/blob/main/main.py): `main.py`
- [Result visualization](https://github.com/shoaib-devpy/blockchain_fl_framework_py/blob/main/visualization.py): `visualization.py`

### Other components

- **Framework operator**
- **Dataset provider**

## Connections

- Framework operator → Workflow orchestrator: runs workflow (evidence: `README.md`)
- Workflow orchestrator → Data preprocessing: loads and partitions (evidence: `main.py`)
- Data preprocessing → Dataset provider: downloads dataset (evidence: `utils/data_preprocessing.py`)
- Workflow orchestrator → Federated clients: trains clients (evidence: `main.py`)
- Workflow orchestrator → Model aggregation: aggregates models (evidence: `main.py`)
- Workflow orchestrator → Adversarial training: applies training (evidence: `main.py`)
- Workflow orchestrator → Anomaly detection: runs detection (evidence: `main.py`)
- Workflow orchestrator → Model evaluation: evaluates models (evidence: `main.py`)
- Workflow orchestrator → Result visualization: plots results (evidence: `main.py`)
- Workflow orchestrator → Smart contract: uses contract (evidence: `main.py`)
- Workflow orchestrator → Blockchain: adds blocks (evidence: `main.py`)
- Blockchain → PBFT network: creates network (evidence: `blockchain/blockchain.py`)
- Blockchain → PBFT node: initializes nodes (evidence: `blockchain/blockchain.py`)
- PBFT node → PBFT network: broadcasts messages (evidence: `pbft/pbft_node.py`)
- PBFT network → PBFT node: delivers messages (evidence: `pbft/network.py`)
- PBFT node → PBFT message: creates messages (evidence: `pbft/pbft_node.py`)
