# openfheorg/openfhe-development architecture

> Architecture diagram of the GitHub repository openfheorg/openfhe-development, 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/openfheorg/openfhe-development
- Repository: https://github.com/openfheorg/openfhe-development

## Overview

##### Main Components
- Library Core Modules:
- “src/core”: Contains the fundamental building blocks such as lattice operations, math utilities, memory management, and other common routines. This is the heart of many cryptographic computations, including underlying mathematical operations, sampling routines, and utilities.
- “src/pke”: Implements public-key encryption (PKE) schemes that include variants like BFV, BGV, and CKKS. This module handles context creation, key generation, encryption, decryption, and homomorphic evaluation.
- “src/binfhe”: Implements Boolean circuit based encryption (FHEW/TFHE) and related functionalities. This module provides a separate API (BinFHEContext) for functional evaluation and Boolean operations.
- Application and Example Layers:
- “benchmark”: Contains performance and correctness benchmarks that use the core and scheme implementations.
- “demoData”, “docs”, and example subdirectories (like “src/pke/examples” and “src/binfhe/examples”) illustrate usage and provide code to demonstrate FHE capabilities.
- Build and Configuration Infrastructure:
- Top-level files and directories (CMakeLists.txt, Makefile, configure scripts, Docker configurations, CI workflows in “.github/workflows”, and “docs”) represent automated build, testing, and deployment pipelines.
- Testing and Verification:
- Unit test directories under “src/core/unittest”, “src/pke/unittest”, and “src/binfhe/unittest” provide test cases ensuring correctness.
- External Dependencies/Third-Party:
- “third-party”: Contains supporting libraries and tools (like Google Test, benchmark frameworks) used for building or testing OpenFHE components.

##### Relationships and Data Flow
- The core module forms the base for both PKE and BinFHE:
- Within “src/pke” and “src/binfhe”, highlight submodules dedicated to key aspects (e.g., “include”, “lib”, “examples” and “unittest”) to differentiate between the API definitions, the underlying implementations, and usage examples.
- Incorporate build and CI/CD pipeline infrastructure:
- An external build system block (denoted by “CMakeLists.txt”, “Makefile”, “scripts”, “docker”) that interacts with the source code components to produce executables and libraries.
- Documentation and Benchmarking:
- Link the “docs” folder and “benchmark” folder to the main library modules to show that they reflect both developer guidance and performance assessments.

##### Architectural Patterns and Design Principles
- Modular Design:
- The clear separation between core library functionalities and encryption schemes is an example of strong modular design.
- Separation of Concerns:
- Different folders encapsulate specific responsibilities (e.g., cryptographic primitives in “src/core”, high-level encryption scheme definitions and utilities in “src/pke” and “src/binfhe”).
- Reusability and Extensibility:
- The project structure supports adding new encryption schemes or extending existing ones without interfering with core functionalities.
- Integration with Automated Build and Testing:
- The presence of CI/CD workflows, Dockerfiles, and extensive unit tests has a clear impact on how development, integration, and deployment pipelines interact with the core components.

##### Relevant Technologies, Frameworks, and Libraries
- GNU C++ and Clang C++ (as per the README requirements).
- CMake and Makefile for building the code.
- Docker and GitHub Actions for containerization and CI/CD.
- External libraries in “third-party” such as Google Test, Google Benchmark, and gperftools used for testing and performance analysis.

##### Final Touches
- Every component (library, test, build tool, documentation) is clearly labeled.
- From “Core” → “PKE/BinFHE”
- From “Build Tools” → “Compilation of Modules”
- From “Unit Tests/Benchmarks” → “Modules they are testing”
- Avoid over-simplification; try to capture as many essential layers as possible.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Dependencies
    E("Third-Party Libraries"):::external

    %% Build & CI/CD Infrastructure
    subgraph "Build & CI/CD Infrastructure"
        BI1("CMakeLists.txt"):::build
        BI2("Makefile"):::build
        BI3("CMake & Scripts"):::build
        BI4("CI/CD Workflows"):::build
        BI5("Docker Config"):::build
        BI1 --- BI2
        BI2 --- BI3
        BI3 --- BI4
        BI4 --- BI5
    end

    %% Core Module
    subgraph "Core Module"
        C1("Core Module"):::core
        C2("Core: Include"):::core
        C3("Core: Lib"):::core
        C4("Core: Unit Tests"):::core
        C5("Core: Examples"):::core
        C1 --- C2
        C1 --- C3
        C1 --- C4
        C1 --- C5
    end

    %% PKE Module
    subgraph "PKE Module"
        P1("PKE Module"):::pke
        P2("PKE: Include"):::pke
        P3("PKE: Lib"):::pke
        P4("PKE: Unit Tests"):::pke
        P5("PKE: Examples"):::pke
        P1 --- P2
        P1 --- P3
        P1 --- P4
        P1 --- P5
    end

    %% BinFHE Module
    subgraph "BinFHE Module"
        B1("BinFHE Module"):::binfhe
        B2("BinFHE: Include"):::binfhe
        B3("BinFHE: Lib"):::binfhe
        B4("BinFHE: Unit Tests"):::binfhe
        B5("BinFHE: Examples"):::binfhe
        B1 --- B2
        B1 --- B3
        B1 --- B4
        B1 --- B5
    end

    %% Application & Example Layers
    subgraph "Application & Examples"
        A1("Benchmarks"):::app
        A2("Demo Data"):::app
    end

    %% Documentation & Testing
    D("Documentation & Guides"):::docs
    T("Testing & Verification"):::test

    %% Relationships
    %% External Dependencies feed Build and Testing
    E -->|"supports"| BI1
    E -->|"supports"| T

    %% Build Infrastructure builds modules
    BI4 -->|"builds"| C1
    BI4 -->|"builds"| P1
    BI4 -->|"builds"| B1

    %% Core Module provides base for encryption schemes
    C1 -->|"provides_base"| P1
    C1 -->|"provides_base"| B1

    %% Testing verifies modules
    T -->|"verifies"| C1
    T -->|"verifies"| P1
    T -->|"verifies"| B1

    %% Documentation for modules
    D -->|"documents"| C1
    D -->|"documents"| P1
    D -->|"documents"| B1

    %% Application Layers use the modules
    A1 -->|"assesses"| C1
    A1 -->|"assesses"| P1
    A1 -->|"assesses"| B1
    A2 -->|"demonstrates"| P1
    A2 -->|"demonstrates"| B1

    %% Styling
    classDef core fill:#a8ddb5,stroke:#2b8cbe,stroke-width:2px;
    classDef pke fill:#fdbb84,stroke:#e34a33,stroke-width:2px;
    classDef binfhe fill:#fdae6b,stroke:#e6550d,stroke-width:2px;
    classDef build fill:#dadaeb,stroke:#636363,stroke-width:2px;
    classDef app fill:#c6dbef,stroke:#2171b5,stroke-width:2px;
    classDef docs fill:#e5f5e0,stroke:#31a354,stroke-width:2px;
    classDef test fill:#fee0d2,stroke:#99000d,stroke-width:2px;
    classDef external fill:#fddaec,stroke:#de2d26,stroke-width:2px;

    %% Click Events for Core Module
    click C1 "https://github.com/openfheorg/openfhe-development/tree/main/src/core"
    click C2 "https://github.com/openfheorg/openfhe-development/tree/main/src/core/include"
    click C3 "https://github.com/openfheorg/openfhe-development/tree/main/src/core/lib"
    click C4 "https://github.com/openfheorg/openfhe-development/tree/main/src/core/unittest"
    click C5 "https://github.com/openfheorg/openfhe-development/tree/main/src/core/examples"

    %% Click Events for PKE Module
    click P1 "https://github.com/openfheorg/openfhe-development/tree/main/src/pke"
    click P2 "https://github.com/openfheorg/openfhe-development/tree/main/src/pke/include"
    click P3 "https://github.com/openfheorg/openfhe-development/tree/main/src/pke/lib"
    click P4 "https://github.com/openfheorg/openfhe-development/tree/main/src/pke/unittest"
    click P5 "https://github.com/openfheorg/openfhe-development/tree/main/src/pke/examples"

    %% Click Events for BinFHE Module
    click B1 "https://github.com/openfheorg/openfhe-development/tree/main/src/binfhe"
    click B2 "https://github.com/openfheorg/openfhe-development/tree/main/src/binfhe/include"
    click B3 "https://github.com/openfheorg/openfhe-development/tree/main/src/binfhe/lib"
    click B4 "https://github.com/openfheorg/openfhe-development/tree/main/src/binfhe/unittest"
    click B5 "https://github.com/openfheorg/openfhe-development/tree/main/src/binfhe/examples"

    %% Click Events for Build & CI/CD Infrastructure
    click BI1 "https://github.com/openfheorg/openfhe-development/blob/main/CMakeLists.txt"
    click BI2 "https://github.com/openfheorg/openfhe-development/tree/main/Makefile"
    click BI3 "https://github.com/openfheorg/openfhe-development/tree/main/scripts"
    click BI4 "https://github.com/openfheorg/openfhe-development/tree/main/.github/workflows"
    click BI5 "https://github.com/openfheorg/openfhe-development/tree/main/docker"

    %% Click Events for Application & Example Layers
    click A1 "https://github.com/openfheorg/openfhe-development/tree/main/benchmark"
    click A2 "https://github.com/openfheorg/openfhe-development/tree/main/demoData"

    %% Click Event for Documentation
    click D "https://github.com/openfheorg/openfhe-development/tree/main/docs"

    %% Click Event for External Dependencies
    click E "https://github.com/openfheorg/openfhe-development/tree/main/third-party"
```
