# adap/flower architecture

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

- Interactive diagram: https://gitdiagram.com/adap/flower
- Repository: https://github.com/adap/flower

## Overview

##### Main Components
- Server Component: This is the central “orchestrator” that hosts the global model and federated strategies. In the Flower architecture, it is responsible for aggregating client updates (using strategies like FedAvg, FedProx, FedNova, etc.), managing secure aggregation (including modules for differential privacy and secure protocols) and logging events.
- Client Component: Flower supports a wide range of clients (across Python, C/C++, mobile platforms via Kotlin and Swift, etc.) that run local training. These clients handle local data preparation using their chosen machine learning libraries (e.g., TensorFlow, PyTorch, scikit-learn) and communicate updates to the server using standardized protocols.
- Communication Layer: Flower relies heavily on gRPC communication as defined by its numerous protocol buffer (.proto) files found under directories like src/proto and within language-specific subfolders. This layer handles the bidirectional data transfers (client updates and server commands) and secure message handling.
- Extensibility and Strategy Modules: The core design features different strategy modules (for example, FedAvg, FedAvgM, adaptive federated optimization, etc.) that can be extended or overridden. These modules are part of the server’s orchestration and may be represented as subcomponents inside the server module.
- Infrastructure & Deployment: There are directories for Docker (including base images, client/server containers, distributed and supernode setups), CI/CD workflows (GitHub actions, Docker Hub integration) and multiple deployment examples (in “examples”, “benchmarks” and “intelligence” folders) that show how Flower can be deployed in different operational environments.

##### Relationships and Interactions
- Connections from the Communication Layer to each of the core components, emphasizing the use of gRPC (or REST in some CLI variants) as the transport mechanism.
- That the Server uses Strategy Modules to aggregate and update models, which in turn instructs the Clients for the next training round.
- Optionally, incorporate additional elements like secure aggregation submodules, logging/telemetry, and client state management – major subcomponents that are critical for research and production scenarios.

##### Architectural Patterns and Design Principles
- Modularity: The system is designed in a way that each component (client core, server core, communication, strategies) is loosely coupled and can be extended or replaced. Indicate these modules with separate blocks.
- Extensibility: Clearly annotate areas where custom strategies may be injected and where clients can override default behavior (e.g., different machine learning backends).
- Containerization and Deployment: Show a peripheral “deployment layer” that includes Docker images and dev container configurations. This emphasizes that Flower is designed for portable deployment as well as local development.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Server Component
    subgraph "Server Component"
        direction TB
        PythonServer["Python Server"]:::server
        SwiftServer["Swift Server"]:::server
        subgraph "Strategy Modules"
            direction TB
            PythonStrategy["Python Strategies"]:::strategy
        end
        PythonServer -->|"uses"| PythonStrategy
    end

    %% Client Component
    subgraph "Client Component"
        direction TB
        PythonClient["Python Client"]:::client
        CCClient["C/C++ Client"]:::client
        KotlinClient["Kotlin Client"]:::client
        SwiftClient["Swift Client"]:::client
    end

    %% Communication Layer
    subgraph "Communication Layer"
        direction TB
        ProtoDefs["Protocol Buffers (.proto)"]:::proto
        GRPCUtils["gRPC Utilities (Python)"]:::proto
        ProtoDefs -->|"defines"| GRPCUtils
    end

    %% Deployment & Infrastructure
    subgraph "Infrastructure & Deployment"
        direction TB
        Docker["Docker Resources"]:::deploy
        DevContainers["Dev Containers"]:::deploy
        CICD["CI/CD Workflows"]:::deploy
    end

    %% Interactions between Clients and Servers
    PythonClient -->|"update"| PythonServer
    CCClient -->|"update"| PythonServer
    KotlinClient -->|"update"| PythonServer
    SwiftClient -->|"update"| SwiftServer

    PythonServer -->|"global_model"| PythonClient
    PythonServer -->|"global_model"| CCClient
    PythonServer -->|"global_model"| KotlinClient
    SwiftServer -->|"global_model"| SwiftClient

    %% Communication connections
    GRPCUtils -->|"communicates_with"| PythonServer
    GRPCUtils -->|"communicates_with"| PythonClient
    GRPCUtils -->|"communicates_with"| SwiftServer
    GRPCUtils -->|"communicates_with"| SwiftClient

    %% Click Events
    click PythonServer "https://github.com/adap/flower/tree/main/src/py/flwr/server"
    click SwiftServer "https://github.com/adap/flower/tree/main/src/swift/flwr/Sources/Flower/…"
    click PythonStrategy "https://github.com/adap/flower/tree/main/src/py/flwr/server/strategy"
    click PythonClient "https://github.com/adap/flower/tree/main/src/py/flwr/client"
    click CCClient "https://github.com/adap/flower/tree/main/src/cc/flwr"
    click KotlinClient "https://github.com/adap/flower/tree/main/src/kotlin/flwr"
    click SwiftClient "https://github.com/adap/flower/blob/main/src/swift/flwr/Sources/Flower/Client/Client.swift"
    click ProtoDefs "https://github.com/adap/flower/tree/main/src/proto/flwr/proto"
    click GRPCUtils "https://github.com/adap/flower/tree/main/src/py/flwr/proto"
    click Docker "https://github.com/adap/flower/tree/main/src/docker"
    click DevContainers "https://github.com/adap/flower/tree/main/.devcontainer/"
    click CICD "https://github.com/adap/flower/tree/main/.github/"

    %% Styling Classes
    classDef server fill:#B3CDE0,stroke:#333,stroke-width:2px;
    classDef client fill:#CDEBB0,stroke:#333,stroke-width:2px;
    classDef proto fill:#FEEFB3,stroke:#333,stroke-width:2px;
    classDef strategy fill:#FBB4AE,stroke:#333,stroke-width:2px;
    classDef deploy fill:#D9D9D9,stroke:#333,stroke-width:2px;
```
