# tjdghks994/fedpso architecture

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

- Interactive diagram: https://gitdiagram.com/tjdghks994/fedpso
- Repository: https://github.com/tjdghks994/fedpso

## Overview

##### Project type and purpose
- This is a Python-based federated-learning prototype that demonstrates two aggregation algorithms: FedAvg (baseline) and FedPSO (novel PSO-based aggregator).
- Its goal is to simulate clients training local models, then coordinate with a central server aggregator to update a global model under constrained communication (Docker+docker-compose orchestrates the environment).

##### File structure
- Top-level:
- Dockerfile + docker-compose.yaml: containerize & launch server/clients
- requirements.txt: Python dependencies (e.g., PyTorch, numpy)
- FedPSO/ directory:
– build_model.py: defines the neural network architecture
– fed_avg.py: FedAvg orchestration (send global model → clients train → return weights → average → update)
– fed_pso.py: FedPSO orchestration (send global model → clients train → return scores → server picks best → fetch that client’s weights → update)
- figure/: PNGs illustrating protocol & experimental results

##### README for additional insights
- README includes:
- Abstract: communicates data privacy & communication cost challenges
- Usage + docker-compose snippets: shows how to spin up FedAvg or FedPSO services
- Figures: protocol flowcharts for both FedAvg and FedPSO

##### Elements
- Clear labels:
- Docker Compose
- Aggregation Service (Server)
- Federated Clients (Client 1…Client K)
- Model Definition Module
- Network Link
- Global model → Clients
- Local updates (weights or scores) → Server
- Updated model feedback loop
- Blue rectangles for containers
- Green ovals for code modules

##### Detailed capture of essential elements
- Build_model.py as a shared library mounted into all containers (via volume in docker-compose)
- How commenting/uncommenting lines in docker-compose selects FedAvg vs FedPSO
- Data payload sizes: “model weights (~MB)” vs “score scalar (bytes)” to emphasize communication cost reduction in FedPSO

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Project Documentation"
        README["README.md"]:::other
        Requirements["requirements.txt"]:::other
        Figures["figure/"]:::other
    end

    subgraph "Orchestration Layer"
        Dockerfile["Dockerfile"]:::container
        DockerCompose["docker-compose.yaml"]:::container
    end

    subgraph "Container Network"
        ServerContainer["Aggregation Service (Server)"]:::container
        ClientsGroup["Federated Clients (1..K)"]:::container
    end

    subgraph "Code Modules"
        BuildModel["build_model.py"]:::module
        FedAvgService["fed_avg.py"]:::module
        FedPSOService["fed_pso.py"]:::module
    end

    Dockerfile --> DockerCompose
    DockerCompose --> ServerContainer
    DockerCompose --> ClientsGroup

    ServerContainer -.-> BuildModel
    ClientsGroup -.-> BuildModel
    ServerContainer -.-> FedAvgService
    ServerContainer -.-> FedPSOService

    ServerContainer -->|"global model (~MB)"| ClientsGroup
    ClientsGroup -->|"weights (~MB) / score (bytes)"| ServerContainer

    click Dockerfile "https://github.com/tjdghks994/fedpso/tree/main/Dockerfile"
    click DockerCompose "https://github.com/tjdghks994/fedpso/blob/main/docker-compose.yaml"
    click BuildModel "https://github.com/tjdghks994/fedpso/blob/main/FedPSO/build_model.py"
    click FedAvgService "https://github.com/tjdghks994/fedpso/blob/main/FedPSO/fed_avg.py"
    click FedPSOService "https://github.com/tjdghks994/fedpso/blob/main/FedPSO/fed_pso.py"
    click Requirements "https://github.com/tjdghks994/fedpso/blob/main/requirements.txt"
    click README "https://github.com/tjdghks994/fedpso/blob/main/README.md"
    click Figures "https://github.com/tjdghks994/fedpso/tree/main/figure/"

    classDef container fill:#cce5ff,stroke:#0366d6
    classDef module fill:#e6ffcc,stroke:#55a630
    classDef other fill:#f9f0c0,stroke:#d66f36

    linkStyle 3,4,5,6 stroke-dasharray:5 5
    linkStyle 7,8 stroke:#f90,stroke-width:2px
```
