# moda-gov-tw/pets-applications architecture

> Architecture diagram of the GitHub repository moda-gov-tw/pets-applications, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/moda-gov-tw/pets-applications
- Repository: https://github.com/moda-gov-tw/pets-applications

## Overview

##### Project type and purpose
- This is a multi-module research/demo repository showcasing six Privacy-Enhancing Technology (PET) applications:
- Differential Privacy
- Synthetic Data
- Federated Learning
- Homomorphic Encryption
- Secure Multiparty Computation
- k-Anonymization
- Each top-level folder implements one PET use case (mostly Python scripts or small apps) to demonstrate data-sharing or compute workflows while preserving privacy.

##### File structure
- Top-level directories correspond to PET categories. Inside each:
- A README.md describing the use case
- Sample datasets (NHANES.csv, other CSVs)
- Example scripts (.py, .sh)
- Subfolders for configurations, code, figures, utilities
- The federated_learning/financial_fraud_detection module has a richer structure:
– Shell scripts to generate job configs and splits
– A “tree-based” submodule with client/server JSON configs, custom executors, meta.json, and TensorBoard utilities
- The homomorphic_encryption module contains two distinct apps:
– A Node.js web frontend (views, assets, main.js) plus server code (TTC.js)
– A C++ TFHE-based compute library with CMake, include/, src/, testing/
- The secure_multiparty_computation module implements a small multi-party script hierarchy (Client, MPC_node, Player-Data).
- Config files (package.json, requirements.txt, CMakeLists.txt) signal different runtime environments (Node.js, Python, C++).

##### README for additional insights
- Confirms the high-level grouping and purpose of each directory
- Disclaimer: demo code only

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Top-level
    Repo["PETs Applications Suite"]:::root

    %% Differential Privacy Module
    subgraph "Differential Privacy Module"
        DP_Data["NHANES.csv"]:::data
        DP_Script["example_DP.py"]:::python
        DP_Output["sanitized.csv"]:::data
    end
    Repo --> DP_Data
    DP_Data -->|reads| DP_Script
    DP_Script -->|writes| DP_Output
    click DP_Script "https://github.com/moda-gov-tw/pets-applications/tree/main/differential_privacy/privacy-preserving_research_data_sharing"
    click DP_Data "https://github.com/moda-gov-tw/pets-applications/tree/main/differential_privacy/privacy-preserving_research_data_sharing"
    click DP_Output "https://github.com/moda-gov-tw/pets-applications/tree/main/differential_privacy/privacy-preserving_research_data_sharing"

    %% Synthetic Data Module
    subgraph "Synthetic Data Module"
        SD_Data["raw_data.csv"]:::data
        SD_Script["example_synth.py"]:::python
        SD_Output["synthetic_data.csv"]:::data
    end
    Repo --> SD_Data
    SD_Data --> SD_Script
    SD_Script --> SD_Output
    click SD_Script "https://github.com/moda-gov-tw/pets-applications/tree/main/synthetic_data/privacy-preserving_research_data_sharing"
    click SD_Data "https://github.com/moda-gov-tw/pets-applications/tree/main/synthetic_data/privacy-preserving_research_data_sharing"
    click SD_Output "https://github.com/moda-gov-tw/pets-applications/tree/main/synthetic_data/privacy-preserving_research_data_sharing"

    %% k-Anonymization Module
    subgraph "k-Anonymization Module"
        KA_Data["dataset.csv"]:::data
        KA_Script["k_anonymize.py"]:::python
        KA_Output["k_anonymized.csv"]:::data
    end
    Repo --> KA_Data
    KA_Data --> KA_Script
    KA_Script --> KA_Output
    click KA_Script "https://github.com/moda-gov-tw/pets-applications/tree/main/k-anonymization/privacy-preserving_research_data_sharing"
    click KA_Data "https://github.com/moda-gov-tw/pets-applications/tree/main/k-anonymization/privacy-preserving_research_data_sharing"
    click KA_Output "https://github.com/moda-gov-tw/pets-applications/tree/main/k-anonymization/privacy-preserving_research_data_sharing"

    %% Federated Learning Module
    subgraph "Federated Learning Module"
        FL_Raw["financial_fraud.csv"]:::data
        subgraph "Shell Scripts" 
            FL_S1["CCF_DP_job_config_gen.sh"]:::script
            FL_S2["CCF_data_split_gen.sh"]:::script
            FL_S3["CCF_job_config_gen.sh"]:::script
        end
        subgraph "Utils"
            FL_U1["prepare_data_split.py"]:::python
            FL_U2["prepare_job_config.py"]:::python
            FL_U3["baseline_individual.py"]:::python
            FL_U4["individual_v2.py"]:::python
        end
        FL_Predict["GM_predict.py"]:::python
        subgraph "Tree-Based Submodule"
            TB_Configs["config_fed_client.json\nconfig_fed_server.json"]:::config
            TB_Exec["creditcard_executor.py"]:::python
            TB_Util["plot_tensorboard_events.py"]:::python
        end
        FL_Agg["Central Aggregator"]:::server
    end
    Repo --> FL_Raw
    FL_Raw --> FL_S1 & FL_S2 & FL_S3
    FL_S2 --> FL_U1
    FL_S1 & FL_U2 --> FL_Predict
    FL_Predict --> FL_Agg
    FL_S3 --> FL_U3 & FL_U4
    TB_Configs --> TB_Exec
    TB_Exec --> TB_Util
    TB_Util --> FL_Agg
    click FL_S1 "https://github.com/moda-gov-tw/pets-applications/blob/main/federated_learning/financial_fraud_detection/CCF_DP_job_config_gen.sh"
    click FL_S2 "https://github.com/moda-gov-tw/pets-applications/blob/main/federated_learning/financial_fraud_detection/CCF_data_split_gen.sh"
    click FL_S3 "https://github.com/moda-gov-tw/pets-applications/blob/main/federated_learning/financial_fraud_detection/CCF_job_config_gen.sh"
    click FL_Predict "https://github.com/moda-gov-tw/pets-applications/blob/main/federated_learning/financial_fraud_detection/GM_predict.py"
    click FL_U1 "https://github.com/moda-gov-tw/pets-applications/blob/main/federated_learning/financial_fraud_detection/utils/prepare_data_split.py"
    click FL_U2 "https://github.com/moda-gov-tw/pets-applications/blob/main/federated_learning/financial_fraud_detection/utils/prepare_job_config.py"
    click FL_U3 "https://github.com/moda-gov-tw/pets-applications/blob/main/federated_learning/financial_fraud_detection/utils/baseline_individual.py"
    click FL_U4 "https://github.com/moda-gov-tw/pets-applications/blob/main/federated_learning/financial_fraud_detection/utils/individual_v2.py"
    click TB_Configs "https://github.com/moda-gov-tw/pets-applications/blob/main/federated_learning/financial_fraud_detection/tree-based/jobs/config_fed_client.json"
    click TB_Exec "https://github.com/moda-gov-tw/pets-applications/blob/main/federated_learning/financial_fraud_detection/tree-based/jobs/creditcard_executor.py"
    click TB_Util "https://github.com/moda-gov-tw/pets-applications/blob/main/federated_learning/financial_fraud_detection/tree-based/utils/plot_tensorboard_events.py"
    click FL_Raw "https://github.com/moda-gov-tw/pets-applications/tree/main/federated_learning/financial_fraud_detection"

    %% Homomorphic Encryption Module
    subgraph "Homomorphic Encryption Module"
        subgraph "Web Frontend"
            Browser["Browser"]:::client
            NodeServer["TTC.js"]:::node
            Views["views & assets"]:::asset
        end
        subgraph "C++ TFHE Library"
            CMake["CMakeLists.txt"]:::config
            HE_Hdrs["include/*.h"]:::code
            HE_Src["src/*.cpp"]:::code
        end
        EncryptedStore["Encrypted Result Store"]:::data
    end
    Repo --> Browser
    Browser --> NodeServer
    NodeServer --> Views
    NodeServer -->|calls| HE_Src
    HE_Src --> EncryptedStore
    click NodeServer "https://github.com/moda-gov-tw/pets-applications/blob/main/homomorphic_encryption/criminal_data_cloud_computing/node.js/TTC.js"
    click Views "https://github.com/moda-gov-tw/pets-applications/tree/main/homomorphic_encryption/criminal_data_cloud_computing/node.js/views"
    click CMake "https://github.com/moda-gov-tw/pets-applications/blob/main/homomorphic_encryption/criminal_data_cloud_computing/tfhe-police/CMakeLists.txt"
    click HE_Hdrs "https://github.com/moda-gov-tw/pets-applications/tree/main/homomorphic_encryption/criminal_data_cloud_computing/tfhe-police/include"
    click HE_Src "https://github.com/moda-gov-tw/pets-applications/tree/main/homomorphic_encryption/criminal_data_cloud_computing/tfhe-police/src"

    %% Secure Multiparty Computation Module
    subgraph "Secure Multiparty Computation Module"
        subgraph "Clients & Data Providers"
            MPC_Client["client.py"]:::python
            MPC_DP["average_salary.py"]:::python
            MPC_Stop["average_salary_finish.py"]:::python
            MPC_Domains["domains.py"]:::python
        end
        MPC_Node["average_gender_salary.mpc"]:::script
        PlayerDoc["README.md"]:::doc
        Result["Result Aggregator"]:::server
    end
    Repo --> MPC_Client
    MPC_Client --> MPC_DP & MPC_Stop & MPC_Domains
    MPC_DP & MPC_Stop --> MPC_Node
    MPC_Node --> Result
    click MPC_Client "https://github.com/moda-gov-tw/pets-applications/blob/main/secure_multiparty_computation/privacy-preserving_statistical_average_salary_calculation/Client/client.py"
    click MPC_DP "https://github.com/moda-gov-tw/pets-applications/blob/main/secure_multiparty_computation/privacy-preserving_statistical_average_salary_calculation/Client/Data_provider/average_salary.py"
    click MPC_Stop "https://github.com/moda-gov-tw/pets-applications/blob/main/secure_multiparty_computation/privacy-preserving_statistical_average_salary_calculation/Client/Stop_provider/average_salary_finish.py"
    click MPC_Domains "https://github.com/moda-gov-tw/pets-applications/blob/main/secure_multiparty_computation/privacy-preserving_statistical_average_salary_calculation/Client/domains.py"
    click MPC_Node "https://github.com/moda-gov-tw/pets-applications/blob/main/secure_multiparty_computation/privacy-preserving_statistical_average_salary_calculation/MPC_node/average_gender_salary.mpc"
    click PlayerDoc "https://github.com/moda-gov-tw/pets-applications/blob/main/secure_multiparty_computation/privacy-preserving_statistical_average_salary_calculation/Player-Data/README.md"

    %% Styling
    classDef root fill:#EFEFEF,stroke:#333,stroke-width:2px
    classDef python fill:#ADD8E6,stroke:#333
    classDef node fill:#FFA500,stroke:#333
    classDef data fill:#7CFC00,stroke:#333,shape:cylinder
    classDef script fill:#D3D3D3,stroke:#333
    classDef config fill:#D3D3D3,stroke:#333
    classDef server fill:#FFB6C1,stroke:#333
    classDef client fill:#DDA0DD,stroke:#333
    classDef asset fill:#FFA500,stroke:#333
    classDef code fill:#D3D3D3,stroke:#333
    classDef doc fill:#D3D3D3,stroke:#333
```
