# dtc2025ag/moai architecture

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

- Interactive diagram: https://gitdiagram.com/dtc2025ag/moai
- Repository: https://github.com/dtc2025ag/moai

## Overview

MOAI is a C++ implementation of non-interactive secure Transformer inference using CKKS, with matrix operations, nonlinear layers, and bootstrapping as major capabilities. The intended workflow is encrypted inputs processed through Transformer operations and returned as encrypted results; the README does not identify a runtime entry point, and sampled excerpts do not establish wiring among the high-level layer modules, so those links are left out. Bootstrapper’s construction of ModularReducer and its use of SEAL evaluator operations are visible in sampled source. Other subsystem relationships are based on the documented product purpose and module names.

Main entry points: [`include/source/bootstrapping/Bootstrapper.cpp`](https://github.com/dtc2025ag/moai/blob/main/include/source/bootstrapping/Bootstrapper.cpp) (Bootstrapper), [`include/source/ckks_evaluator.cpp`](https://github.com/dtc2025ag/moai/blob/main/include/source/ckks_evaluator.cpp) (CKKS evaluator), [`thirdparty/SEAL-4.1-bs/native/src/seal/evaluator.h`](https://github.com/dtc2025ag/moai/blob/main/thirdparty/SEAL-4.1-bs/native/src/seal/evaluator.h) (SEAL evaluator), [`include/source/matrix_mul/Batch_encode_encrypt.hpp`](https://github.com/dtc2025ag/moai/blob/main/include/source/matrix_mul/Batch_encode_encrypt.hpp) (Batch encoding)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_transformer["Transformer operations"]
  node_matrix["Matrix multiplication"]
  node_plainmatrix["Plaintext matrix"]
  node_batch["Batch encoding"]
  node_gelu["GELU<br/>[gelu.hpp]"]
  node_geluothers["Other GELU<br/>[gelu_others.hpp]"]
  node_layernorm["Layer normalization<br/>[layernorm.hpp]"]
  node_softmax["Softmax<br/>[softmax.hpp]"]
end

subgraph group_approx["CKKS approximation"]
  node_ckkseval["CKKS evaluator<br/>[ckks_evaluator.cpp]"]
  node_polynomial["Polynomial evaluation<br/>[ckks_evaluator.cpp]"]
end

subgraph group_bootstrap["Bootstrapping"]
  node_bootstrapper["Bootstrapper<br/>[Bootstrapper.cpp]"]
  node_reducer["Modular reducer<br/>[ModularReducer.cpp]"]
  node_remez["Remez approximation<br/>[Remez.cpp]"]
end

subgraph group_backend["HE backend"]
  node_sealencoder["CKKS encoder<br/>[ckks.h]"]
  node_sealevaluator["SEAL evaluator<br/>[evaluator.h]"]
  node_sealcontext["SEAL context<br/>[context.h]"]
end

node_caller(("Inference caller"))
node_output(("Encrypted result"))

node_caller -->|"provides inputs"| node_batch
node_batch -->|"encodes inputs"| node_matrix
node_caller -->|"invokes"| node_matrix
node_caller -->|"invokes"| node_plainmatrix
node_caller -->|"invokes"| node_gelu
node_caller -->|"invokes"| node_geluothers
node_caller -->|"invokes"| node_layernorm
node_caller -->|"invokes"| node_softmax
node_caller -->|"invokes"| node_bootstrapper
node_caller -->|"receives result"| node_output
node_ckkseval -->|"evaluates"| node_polynomial
node_bootstrapper -->|"constructs"| node_reducer
node_bootstrapper -->|"uses operations"| node_sealevaluator
node_ckkseval -->|"calls"| node_sealevaluator
node_ckkseval -->|"encodes constants"| node_sealencoder
node_bootstrapper -->|"produces ciphertext"| node_output
node_sealcontext -.->|"configures"| node_sealevaluator

click node_matrix "https://github.com/dtc2025ag/moai/blob/main/include/source/matrix_mul/Ct_ct_matrix_mul.hpp"
click node_plainmatrix "https://github.com/dtc2025ag/moai/blob/main/include/source/matrix_mul/Ct_pt_matrix_mul.hpp"
click node_batch "https://github.com/dtc2025ag/moai/blob/main/include/source/matrix_mul/Batch_encode_encrypt.hpp"
click node_gelu "https://github.com/dtc2025ag/moai/blob/main/include/source/non_linear_func/gelu.hpp"
click node_geluothers "https://github.com/dtc2025ag/moai/blob/main/include/source/non_linear_func/gelu_others.hpp"
click node_layernorm "https://github.com/dtc2025ag/moai/blob/main/include/source/non_linear_func/layernorm.hpp"
click node_softmax "https://github.com/dtc2025ag/moai/blob/main/include/source/non_linear_func/softmax.hpp"
click node_ckkseval "https://github.com/dtc2025ag/moai/blob/main/include/source/ckks_evaluator.cpp"
click node_polynomial "https://github.com/dtc2025ag/moai/blob/main/include/source/ckks_evaluator.cpp"
click node_bootstrapper "https://github.com/dtc2025ag/moai/blob/main/include/source/bootstrapping/Bootstrapper.cpp"
click node_reducer "https://github.com/dtc2025ag/moai/blob/main/include/source/bootstrapping/ModularReducer.cpp"
click node_remez "https://github.com/dtc2025ag/moai/blob/main/include/source/bootstrapping/common/Remez.cpp"
click node_sealencoder "https://github.com/dtc2025ag/moai/blob/main/thirdparty/SEAL-4.1-bs/native/src/seal/ckks.h"
click node_sealevaluator "https://github.com/dtc2025ag/moai/blob/main/thirdparty/SEAL-4.1-bs/native/src/seal/evaluator.h"
click node_sealcontext "https://github.com/dtc2025ag/moai/blob/main/thirdparty/SEAL-4.1-bs/native/src/seal/context.h"

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_matrix,node_plainmatrix,node_batch,node_gelu,node_geluothers,node_layernorm,node_softmax toneBlue
class node_ckkseval,node_polynomial toneAmber
class node_bootstrapper,node_reducer,node_remez toneMint
class node_sealencoder,node_sealevaluator,node_sealcontext toneRose
class node_caller,node_output toneIndigo
```

## Components

### Transformer operations

- [Matrix multiplication](https://github.com/dtc2025ag/moai/blob/main/include/source/matrix_mul/Ct_ct_matrix_mul.hpp): `include/source/matrix_mul/Ct_ct_matrix_mul.hpp`
- [Plaintext matrix](https://github.com/dtc2025ag/moai/blob/main/include/source/matrix_mul/Ct_pt_matrix_mul.hpp): `include/source/matrix_mul/Ct_pt_matrix_mul.hpp`
- [Batch encoding](https://github.com/dtc2025ag/moai/blob/main/include/source/matrix_mul/Batch_encode_encrypt.hpp): `include/source/matrix_mul/Batch_encode_encrypt.hpp`
- [GELU](https://github.com/dtc2025ag/moai/blob/main/include/source/non_linear_func/gelu.hpp): `include/source/non_linear_func/gelu.hpp`
- [Other GELU](https://github.com/dtc2025ag/moai/blob/main/include/source/non_linear_func/gelu_others.hpp): `include/source/non_linear_func/gelu_others.hpp`
- [Layer normalization](https://github.com/dtc2025ag/moai/blob/main/include/source/non_linear_func/layernorm.hpp): `include/source/non_linear_func/layernorm.hpp`
- [Softmax](https://github.com/dtc2025ag/moai/blob/main/include/source/non_linear_func/softmax.hpp): `include/source/non_linear_func/softmax.hpp`

### CKKS approximation

- [CKKS evaluator](https://github.com/dtc2025ag/moai/blob/main/include/source/ckks_evaluator.cpp): `include/source/ckks_evaluator.cpp`
- [Polynomial evaluation](https://github.com/dtc2025ag/moai/blob/main/include/source/ckks_evaluator.cpp): `include/source/ckks_evaluator.cpp`

### Bootstrapping

- [Bootstrapper](https://github.com/dtc2025ag/moai/blob/main/include/source/bootstrapping/Bootstrapper.cpp): `include/source/bootstrapping/Bootstrapper.cpp`
- [Modular reducer](https://github.com/dtc2025ag/moai/blob/main/include/source/bootstrapping/ModularReducer.cpp): `include/source/bootstrapping/ModularReducer.cpp`
- [Remez approximation](https://github.com/dtc2025ag/moai/blob/main/include/source/bootstrapping/common/Remez.cpp): `include/source/bootstrapping/common/Remez.cpp`

### HE backend

- [CKKS encoder](https://github.com/dtc2025ag/moai/blob/main/thirdparty/SEAL-4.1-bs/native/src/seal/ckks.h): `thirdparty/SEAL-4.1-bs/native/src/seal/ckks.h`
- [SEAL evaluator](https://github.com/dtc2025ag/moai/blob/main/thirdparty/SEAL-4.1-bs/native/src/seal/evaluator.h): `thirdparty/SEAL-4.1-bs/native/src/seal/evaluator.h`
- [SEAL context](https://github.com/dtc2025ag/moai/blob/main/thirdparty/SEAL-4.1-bs/native/src/seal/context.h): `thirdparty/SEAL-4.1-bs/native/src/seal/context.h`

### Other components

- **Inference caller**
- **Encrypted result**

## Connections

- Inference caller → Batch encoding: provides inputs
- Batch encoding → Matrix multiplication: encodes inputs
- Inference caller → Matrix multiplication: invokes
- Inference caller → Plaintext matrix: invokes
- Inference caller → GELU: invokes
- Inference caller → Other GELU: invokes
- Inference caller → Layer normalization: invokes
- Inference caller → Softmax: invokes
- Inference caller → Bootstrapper: invokes
- Inference caller → Encrypted result: receives result
- CKKS evaluator → Polynomial evaluation: evaluates
- Bootstrapper → Modular reducer: constructs
- Bootstrapper → SEAL evaluator: uses operations
- CKKS evaluator → SEAL evaluator: calls
- CKKS evaluator → CKKS encoder: encodes constants
- Bootstrapper → Encrypted result: produces ciphertext
- SEAL context → SEAL evaluator: configures
