# sania-2520/veriunlearn architecture

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

- Interactive diagram: https://gitdiagram.com/sania-2520/veriunlearn
- Repository: https://github.com/sania-2520/veriunlearn

## Overview

#### Purpose and topology
VeriUnlearn is a privacy-focused conversational-AI platform that trains and serves LoRA-adapted models, processes deletion/unlearning requests, and issues cryptographic evidence that removed data no longer affects a model. The canonical product layout is the `packages/` monorepo: frontend → Nginx → FastAPI backend → ML engine, with asynchronous work handled by Celery.

#### Entry points and user surface
The Next.js dashboard provides authentication, administration, model/training, RAG, audit, monitoring, and unlearning workflows. Its API client boundary is separate from page components.
- `packages/frontend/src/app/page.tsx`
- `packages/frontend/src/app/dashboard/unlearning/page.tsx`
- `packages/frontend/src/lib/api/client.ts`

The FastAPI application is the primary server entry point; versioned handlers expose auth, datasets, training, unlearning, verification, compliance, and related enterprise APIs.
- `packages/backend/app/main.py`
- `packages/backend/app/api/v1/unlearning.py`
- `packages/backend/app/api/v1/verification.py`

#### Backend domain and persistence boundary
The backend follows a domain/infrastructure split: API handlers and dependencies invoke domain services through interfaces, while repositories persist infrastructure models. Core middleware, RBAC, rate limiting, configuration, and secrets management govern request entry.
- `packages/backend/app/domain/unlearning/services.py`
- `packages/backend/app/infrastructure/database/repositories/unlearning.py`
- `packages/backend/app/core/security.py`

PostgreSQL is the system-of-record database, with Alembic migrations in `packages/backend/alembic/`. Redis provides caching and Celery coordination.

#### Training and model lifecycle
The ML engine owns PyTorch model execution and lifecycle: data preparation, LoRA training, continual-learning mechanisms, experiment/MLflow tracking, model registration, inference, and benchmark execution. The backend reaches it through an explicit external ML-engine adapter rather than embedding all model logic in route handlers.
- `packages/ml-engine/training/lora_trainer.py`
- `packages/ml-engine/training/model_registry.py`
- `packages/backend/app/infrastructure/external/ml_engine.py`

Model artifacts are intended for MinIO; MLflow tracks training experiments. Qdrant supports vector/RAG storage.

#### Unlearning pipeline
A deletion request enters the backend domain, is scheduled as a Celery task, then the ML engine selects or executes SISA, influence-function, or certified-removal algorithms. The hybrid controller provides adaptive algorithm selection. Result status and artifacts return through backend APIs and persistence.
- `packages/backend/app/workers/unlearning_tasks.py`
- `packages/ml-engine/unlearning/e2e_pipeline.py`
- `packages/ml-engine/unlearning/hybrid_controller.py`

This asynchronous boundary isolates potentially long-running GPU/CPU model operations from HTTP request handling. Kubernetes deploys the backend, Celery worker, and ML engine separately.

#### Verification, audit, and compliance
After unlearning, verification evaluates privacy/quality, builds Merkle evidence, signs certificates, and supports zk-SNARK proof generation. Audit and compliance domains preserve traceability; blockchain anchoring is exposed as an external integration.
- `packages/ml-engine/verification/merkle_tree.py`
- `packages/ml-engine/verification/signatures.py`
- `packages/ml-engine/verification/zksnark_service.py`
- `packages/backend/app/infrastructure/external/blockchain.py`

Relevant API/domain boundaries include audit, compliance, and verification rather than the model algorithms themselves.

#### Deployment and operations
Docker supports local composition; Nginx is the edge reverse proxy. Production infrastructure targets Kubernetes through raw manifests, Kustomize overlays, and a Helm chart; Terraform provisions AWS EKS. Prometheus, Grafana, Loki, and Alertmanager provide metrics, dashboards, logs, and alerting.
- `docker-compose.yml`
- `nginx/default.conf`
- `infra/kubernetes/base/kustomization.yaml`
- `infra/kubernetes/helm/veriunlearn/Chart.yaml`
- `infra/terraform/modules/eks/main.tf`

Main entry points: [`packages/ml-engine/training/lora_trainer.py`](https://github.com/sania-2520/veriunlearn/blob/main/packages/ml-engine/training/lora_trainer.py) (ML engine), [`packages/backend/app/workers/unlearning_tasks.py`](https://github.com/sania-2520/veriunlearn/blob/main/packages/backend/app/workers/unlearning_tasks.py) (Celery unlearning worker), [`packages/backend/app/main.py`](https://github.com/sania-2520/veriunlearn/blob/main/packages/backend/app/main.py) (FastAPI application), [`infra/kubernetes/base/kustomization.yaml`](https://github.com/sania-2520/veriunlearn/blob/main/infra/kubernetes/base/kustomization.yaml) (Kubernetes deployment)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_product["Product surface"]
  node_dashboard["Next.js dashboard<br/>frontend<br/>[page.tsx]"]
  node_api_client["API client<br/>frontend boundary<br/>[client.ts]"]
  node_nginx["Nginx edge<br/>reverse proxy<br/>[default.conf]"]
end

subgraph group_backend["Backend &amp; async"]
  node_fastapi["FastAPI application<br/>HTTP API<br/>[main.py]"]
  node_unlearning_api["Unlearning &amp; verification APIs<br/>API handlers<br/>[unlearning.py]"]
  node_unlearning_domain["Unlearning domain service<br/>[services.py]"]
  node_unlearning_repo["Unlearning repository<br/>persistence adapter<br/>[unlearning.py]"]
  node_celery_tasks["Celery unlearning worker<br/>async worker"]
  node_ml_adapter["ML-engine adapter<br/>external adapter<br/>[ml_engine.py]"]
end

subgraph group_ml["ML lifecycle"]
  node_ml_engine["ML engine<br/>model runtime<br/>[lora_trainer.py]"]
  node_model_registry["Model registry<br/>model lifecycle<br/>[model_registry.py]"]
  node_unlearning_pipeline["Unlearning pipeline<br/>ML pipeline<br/>[e2e_pipeline.py]"]
  node_hybrid_controller["Hybrid controller<br/>algorithm selector"]
end

subgraph group_evidence["Verification"]
  node_evidence_service["Evidence &amp; proof service<br/>verification pipeline<br/>[merkle_tree.py]"]
  node_blockchain["Blockchain anchoring<br/>external integration<br/>[blockchain.py]"]
end

subgraph group_platform["Data &amp; platform"]
  node_postgres[("PostgreSQL<br/>system of record<br/>[env.py]")]
  node_redis[("Redis<br/>cache and broker")]
  node_model_artifacts[("MinIO model artifacts<br/>object storage")]
  node_mlflow["MLflow<br/>experiment tracking"]
  node_qdrant[("Qdrant<br/>vector store")]
  node_kubernetes{{"Kubernetes deployment<br/>production platform<br/>[kustomization.yaml]"}}
  node_observability["Monitoring stack<br/>operations"]
end

node_dashboard -->|"uses"| node_api_client
node_api_client -->|"HTTPS API calls"| node_nginx
node_nginx -->|"proxies"| node_fastapi
node_fastapi -->|"routes requests"| node_unlearning_api
node_unlearning_api -->|"invokes"| node_unlearning_domain
node_unlearning_domain -->|"persists status"| node_unlearning_repo
node_unlearning_repo -->|"stores records"| node_postgres
node_unlearning_domain -->|"schedules deletion"| node_celery_tasks
node_celery_tasks -->|"broker coordination"| node_redis
node_celery_tasks -->|"dispatches job"| node_ml_adapter
node_ml_adapter -->|"calls"| node_ml_engine
node_ml_engine -->|"registers versions"| node_model_registry
node_ml_engine -->|"reads and writes artifacts"| node_model_artifacts
node_ml_engine -->|"tracks experiments"| node_mlflow
node_ml_engine -->|"serves RAG vectors"| node_qdrant
node_ml_engine -->|"runs deletion"| node_unlearning_pipeline
node_unlearning_pipeline -->|"selects algorithm"| node_hybrid_controller
node_unlearning_pipeline -->|"submits result"| node_evidence_service
node_evidence_service -->|"anchors evidence"| node_blockchain
node_evidence_service -->|"records certificate status"| node_unlearning_repo
node_kubernetes -.->|"deploys"| node_fastapi
node_kubernetes -.->|"deploys"| node_celery_tasks
node_kubernetes -.->|"deploys"| node_ml_engine
node_fastapi -.->|"emits telemetry"| node_observability
node_celery_tasks -.->|"emits telemetry"| node_observability
node_ml_engine -.->|"emits telemetry"| node_observability

click node_dashboard "https://github.com/sania-2520/veriunlearn/blob/main/packages/frontend/src/app/dashboard/unlearning/page.tsx"
click node_api_client "https://github.com/sania-2520/veriunlearn/blob/main/packages/frontend/src/lib/api/client.ts"
click node_nginx "https://github.com/sania-2520/veriunlearn/blob/main/nginx/default.conf"
click node_fastapi "https://github.com/sania-2520/veriunlearn/blob/main/packages/backend/app/main.py"
click node_unlearning_api "https://github.com/sania-2520/veriunlearn/blob/main/packages/backend/app/api/v1/unlearning.py"
click node_unlearning_domain "https://github.com/sania-2520/veriunlearn/blob/main/packages/backend/app/domain/unlearning/services.py"
click node_unlearning_repo "https://github.com/sania-2520/veriunlearn/blob/main/packages/backend/app/infrastructure/database/repositories/unlearning.py"
click node_celery_tasks "https://github.com/sania-2520/veriunlearn/blob/main/packages/backend/app/workers/unlearning_tasks.py"
click node_ml_adapter "https://github.com/sania-2520/veriunlearn/blob/main/packages/backend/app/infrastructure/external/ml_engine.py"
click node_ml_engine "https://github.com/sania-2520/veriunlearn/blob/main/packages/ml-engine/training/lora_trainer.py"
click node_model_registry "https://github.com/sania-2520/veriunlearn/blob/main/packages/ml-engine/training/model_registry.py"
click node_unlearning_pipeline "https://github.com/sania-2520/veriunlearn/blob/main/packages/ml-engine/unlearning/e2e_pipeline.py"
click node_hybrid_controller "https://github.com/sania-2520/veriunlearn/blob/main/packages/ml-engine/unlearning/hybrid_controller.py"
click node_evidence_service "https://github.com/sania-2520/veriunlearn/blob/main/packages/ml-engine/verification/merkle_tree.py"
click node_blockchain "https://github.com/sania-2520/veriunlearn/blob/main/packages/backend/app/infrastructure/external/blockchain.py"
click node_postgres "https://github.com/sania-2520/veriunlearn/blob/main/packages/backend/alembic/env.py"
click node_kubernetes "https://github.com/sania-2520/veriunlearn/blob/main/infra/kubernetes/base/kustomization.yaml"

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_dashboard,node_api_client,node_nginx toneBlue
class node_fastapi,node_unlearning_api,node_unlearning_domain,node_unlearning_repo,node_celery_tasks,node_ml_adapter toneAmber
class node_ml_engine,node_model_registry,node_unlearning_pipeline,node_hybrid_controller toneMint
class node_evidence_service,node_blockchain toneRose
class node_postgres,node_redis,node_model_artifacts,node_mlflow,node_qdrant,node_kubernetes,node_observability toneIndigo
```

## Components

### Product surface

- [Next.js dashboard](https://github.com/sania-2520/veriunlearn/blob/main/packages/frontend/src/app/dashboard/unlearning/page.tsx): frontend · User workflows for models, RAG, audit, and unlearning. · `packages/frontend/src/app/dashboard/unlearning/page.tsx`
- [API client](https://github.com/sania-2520/veriunlearn/blob/main/packages/frontend/src/lib/api/client.ts): frontend boundary · `packages/frontend/src/lib/api/client.ts`
- [Nginx edge](https://github.com/sania-2520/veriunlearn/blob/main/nginx/default.conf): reverse proxy · `nginx/default.conf`

### Backend & async

- [FastAPI application](https://github.com/sania-2520/veriunlearn/blob/main/packages/backend/app/main.py): HTTP API · Versioned enterprise API entry point. · `packages/backend/app/main.py`
- [Unlearning & verification APIs](https://github.com/sania-2520/veriunlearn/blob/main/packages/backend/app/api/v1/unlearning.py): API handlers · `packages/backend/app/api/v1/unlearning.py`
- [Unlearning domain service](https://github.com/sania-2520/veriunlearn/blob/main/packages/backend/app/domain/unlearning/services.py): domain service · Coordinates deletion lifecycle through interfaces. · `packages/backend/app/domain/unlearning/services.py`
- [Unlearning repository](https://github.com/sania-2520/veriunlearn/blob/main/packages/backend/app/infrastructure/database/repositories/unlearning.py): persistence adapter · `packages/backend/app/infrastructure/database/repositories/unlearning.py`
- [Celery unlearning worker](https://github.com/sania-2520/veriunlearn/blob/main/packages/backend/app/workers/unlearning_tasks.py): async worker · Runs long-lived deletion jobs outside HTTP requests. · `packages/backend/app/workers/unlearning_tasks.py`
- [ML-engine adapter](https://github.com/sania-2520/veriunlearn/blob/main/packages/backend/app/infrastructure/external/ml_engine.py): external adapter · `packages/backend/app/infrastructure/external/ml_engine.py`

### ML lifecycle

- [ML engine](https://github.com/sania-2520/veriunlearn/blob/main/packages/ml-engine/training/lora_trainer.py): model runtime · Executes training, inference, unlearning, and benchmarks. · `packages/ml-engine/training/lora_trainer.py`
- [Model registry](https://github.com/sania-2520/veriunlearn/blob/main/packages/ml-engine/training/model_registry.py): model lifecycle · Registers trained model versions. · `packages/ml-engine/training/model_registry.py`
- [Unlearning pipeline](https://github.com/sania-2520/veriunlearn/blob/main/packages/ml-engine/unlearning/e2e_pipeline.py): ML pipeline · Executes SISA, influence, or certified removal. · `packages/ml-engine/unlearning/e2e_pipeline.py`
- [Hybrid controller](https://github.com/sania-2520/veriunlearn/blob/main/packages/ml-engine/unlearning/hybrid_controller.py): algorithm selector · Adaptively selects the unlearning strategy. · `packages/ml-engine/unlearning/hybrid_controller.py`

### Verification

- [Evidence & proof service](https://github.com/sania-2520/veriunlearn/blob/main/packages/ml-engine/verification/merkle_tree.py): verification pipeline · Builds Merkle evidence, signatures, and zk proofs. · `packages/ml-engine/verification/merkle_tree.py`
- [Blockchain anchoring](https://github.com/sania-2520/veriunlearn/blob/main/packages/backend/app/infrastructure/external/blockchain.py): external integration · `packages/backend/app/infrastructure/external/blockchain.py`

### Data & platform

- [PostgreSQL](https://github.com/sania-2520/veriunlearn/blob/main/packages/backend/alembic/env.py): system of record · Schema evolution is managed by Alembic. · `packages/backend/alembic/env.py`
- **Redis**: cache and broker · Provides caching and Celery coordination.
- **MinIO model artifacts**: object storage
- **MLflow**: experiment tracking
- **Qdrant**: vector store · Stores vectors for RAG.
- [Kubernetes deployment](https://github.com/sania-2520/veriunlearn/blob/main/infra/kubernetes/base/kustomization.yaml): production platform · Deploys backend, workers, and ML engine independently. · `infra/kubernetes/base/kustomization.yaml`
- **Monitoring stack**: operations · Prometheus, Grafana, Loki, and Alertmanager.

## Connections

- Next.js dashboard → API client: uses
- API client → Nginx edge: HTTPS API calls
- Nginx edge → FastAPI application: proxies
- FastAPI application → Unlearning & verification APIs: routes requests
- Unlearning & verification APIs → Unlearning domain service: invokes
- Unlearning domain service → Unlearning repository: persists status
- Unlearning repository → PostgreSQL: stores records
- Unlearning domain service → Celery unlearning worker: schedules deletion
- Celery unlearning worker → Redis: broker coordination
- Celery unlearning worker → ML-engine adapter: dispatches job
- ML-engine adapter → ML engine: calls
- ML engine → Model registry: registers versions
- ML engine → MinIO model artifacts: reads and writes artifacts
- ML engine → MLflow: tracks experiments
- ML engine → Qdrant: serves RAG vectors
- ML engine → Unlearning pipeline: runs deletion
- Unlearning pipeline → Hybrid controller: selects algorithm
- Unlearning pipeline → Evidence & proof service: submits result
- Evidence & proof service → Blockchain anchoring: anchors evidence
- Evidence & proof service → Unlearning repository: records certificate status
- Kubernetes deployment → FastAPI application: deploys
- Kubernetes deployment → Celery unlearning worker: deploys
- Kubernetes deployment → ML engine: deploys
- FastAPI application → Monitoring stack: emits telemetry
- Celery unlearning worker → Monitoring stack: emits telemetry
- ML engine → Monitoring stack: emits telemetry
