# gnueaj/machine-unlearning-comparator architecture

> Architecture diagram of the GitHub repository gnueaj/machine-unlearning-comparator, 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/gnueaj/machine-unlearning-comparator
- Repository: https://github.com/gnueaj/machine-unlearning-comparator

## Overview

##### Main System Components
- Frontend: A React/TypeScript single-page application that provides rich visualization of experimental results, unlearning method comparisons, and interactive elements (e.g., charts, tables, and filters). It involves many components (Accuracy graphs, CKA line charts, experiments tables, etc.) and utility functions for API calls.
- Backend: A Python-based server (likely using frameworks such as FastAPI or Flask, judging by the “routers”, “services”, and “threads” directories) that exposes APIs to start training, execute different unlearning methods (Fine-Tuning, Gradient-Ascent, Random-Labeling, Custom, and Retraining), run privacy attacks, and serve static files (e.g., index.html).
- Data Handling: The backend includes a structured “data” folder with JSON files that likely represent pre-processed datasets or configurations for experiments.
- Concurrency & Task Management: Threads directories indicate that the backend offloads long-running tasks (training and unlearning procedures) into separate threads to improve responsiveness.
- Utility Modules: Modules for attack simulations, evaluation, data visualization, and helper functions support both the machine learning operations and result presentations.

##### Relationships and Interactions
- The Frontend communicates with the Backend via RESTful API calls (exemplified by endpoints in the routers directories such as train, unlearn, and data).
- Within the Backend, API routers receive requests and then trigger specific services that encapsulate the core machine unlearning logic.
- Each service (located in the “services” directory) might launch a corresponding task in the “threads” directory to execute the method asynchronously.
- Utility modules are integrated by services and routers to support tasks like data loading, attacking the model, evaluating performance metrics, and rendering visualization data.
- The project also includes configuration management (in the config directory) which defines settings required for both training and evaluation.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The clear segregation between frontend and backend, as well as further modularization within the backend (routers for handling HTTP endpoints, services for business logic, threads for asynchronous execution, and utilities for common functionalities).
- Service-Oriented: Each unlearning method (FT, GA, RL, custom, retrain) is encapsulated as a distinct service, promoting modular testing and comparison.
- Asynchronous Processing: By using threads, the backend design accommodates potentially long-running training and unlearning tasks without blocking API responses.
- Extensibility: The custom method integration allows users to plug in their own unlearning techniques, which is vital for benchmarking new research ideas.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend Layer"
        FE["Frontend React App"]:::frontend
        FE_Components["Visualization Components"]:::frontend
        FE_API["API Utilities"]:::frontend
    end

    subgraph "Backend Layer"
        APIRouters["API Routing"]:::backend
        Services["Unlearning & Training Services"]:::backend
        Threads["Background Task Threads"]:::backend
        DataRepo["Data Handling"]:::backend
        Config["Configuration Management"]:::backend
        Utils["Utility Modules"]:::backend
    end

    FE -->|"APIRequest"| APIRouters
    FE_API -->|"APICall"| APIRouters
    APIRouters -->|"RouteToService"| Services
    Services -->|"TriggerAsyncTask"| Threads
    DataRepo -->|"ProvidesData"| Services
    Config -->|"ProvidesSettings"| Services
    Utils -->|"SupportsService"| Services
    Services -->|"DeliversResults"| FE

    click FE "https://github.com/gnueaj/machine-unlearning-comparator/tree/main/frontend/"
    click FE_Components "https://github.com/gnueaj/machine-unlearning-comparator/tree/main/frontend/src/components/"
    click FE_API "https://github.com/gnueaj/machine-unlearning-comparator/tree/main/frontend/src/utils/api/"
    click APIRouters "https://github.com/gnueaj/machine-unlearning-comparator/tree/main/backend/app/routers/"
    click Services "https://github.com/gnueaj/machine-unlearning-comparator/tree/main/backend/app/services/"
    click Threads "https://github.com/gnueaj/machine-unlearning-comparator/tree/main/backend/app/threads/"
    click DataRepo "https://github.com/gnueaj/machine-unlearning-comparator/tree/main/backend/data/"
    click Config "https://github.com/gnueaj/machine-unlearning-comparator/blob/main/backend/app/config/settings.py"
    click Utils "https://github.com/gnueaj/machine-unlearning-comparator/tree/main/backend/app/utils/"

    classDef frontend fill:#bbf,stroke:#333,stroke-width:2px;
    classDef backend fill:#cfc,stroke:#333,stroke-width:2px;
```
