# saugardev/zkmedia architecture

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

## Overview

##### Project Type and Purpose
- The project is a full-stack application with a strong focus on zero-knowledge proofs applied to image transformations. Its purpose is to let users edit images while generating cryptographic proofs of the transformations. These proofs can then be verified on-chain using a smart contract.
- The system involves both off-chain processing (using Rust libraries and SP1 programs for proof generation) and on-chain verification (smart contract deployed on a blockchain), with a modern web-based UI for real-time editing.

##### Main Components (as Nodes
- Image Processing Library (located at /img-editor/lib)
- This Rust library handles image transformations.
- It is compiled to WebAssembly (WASM) for browser usage and to RISC-V for SP1 proof generation.

- SP1 Program (located at /img-editor/program)
- Acts as the core system that applies transformations and builds proofs for image modifications.

- Prover API (located at /img-editor/api)
- Developed using Axum, it handles requests from the UI, applies the image processing library and SP1 program to generate proofs.

- Image Verifier (found under /img-editor/verifier)
- A smart contract (ImageVerifier.sol) for verifying the generated proofs on-chain, ensuring immutable provenance.

- User Interface (located at /ui)
- This is a Next.js application that provides a real-time image editing experience.
- It loads the WASM module from the Rust library, manages the editing process in the browser, and communicates with the Prover API.

##### Relationships and Interactions
- The UI interacts with the Prover API:
- User edits an image via UI. The editor loads the WASM module for real-time rendering.
- Once editing is complete, the original image and applied transformations are sent to the Prover API.

- The Prover API processes these inputs:
- It calls into the SP1 program (which in turn may invoke functions from the image processing library) to generate the proof.

- The resulting proof is then designed to be submitted to the Image Verifier smart contract:
- This contract checks the proof’s integrity on-chain, ensuring the provenance of image transformation.

- There is also an internal linkage:
- The Image Processing Library is central since it is used both on the client side (via WASM in the UI) and on the backend (via direct Rust usage) by the SP1 program.

##### Architectural Patterns and Design Principles
- Separation of Concerns:
- Each component (UI, API, Library, SP1 program, Smart Contract) has a clear responsibility.
- Layered Architecture:
- Presentation Layer (UI) → Application Logic (API and SP1 program) → Domain Logic (Image Processing Library) → Verification (Smart Contract).
- Use of WASM for performance and cross-environment compatibility.
- Communication Patterns:
- RESTful API calls or equivalent interactions between the UI and API.
- On-chain interactions initiated by external transaction calls (for verification of proofs).

##### Relevant Technologies, Frameworks, and Libraries
- Rust: for building the core image processing library, SP1 program, and API.
- WebAssembly (WASM): for compiling Rust code for browser use.
- Axum: Rust framework used in the Prover API.
- Next.js: for the user interface.
- SP1 framework: for zero-knowledge proof generation.
- Solidity (or similar smart contract language): for the Image Verifier contract.
- Additional services in the UI (like blockchain, database, and IPFS services) indicate integrations with external systems.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend Layer"
        UI["User Interface (Next.js UI)"]:::frontend
    end

    subgraph "Backend Layer"
        API["Prover API (Axum)"]:::backend
        SP1["SP1 Program (Rust)"]:::backend
        LIB["Image Processing Library (Rust/WASM)"]:::backend
    end

    subgraph "Blockchain Layer"
        SC["Image Verifier Contract (Solidity)"]:::blockchain
    end

    UI -->|"REST"| API
    API -->|"CallProofGen"| SP1
    SP1 -->|"UsesTransforms"| LIB
    SP1 -->|"SubmitProof"| SC
    UI -.->|"LoadWASM"| LIB

    click UI "https://github.com/saugardev/zkmedia/tree/main/ui"
    click API "https://github.com/saugardev/zkmedia/tree/main/img-editor/api"
    click SP1 "https://github.com/saugardev/zkmedia/tree/main/img-editor/program"
    click LIB "https://github.com/saugardev/zkmedia/tree/main/img-editor/lib"
    click SC "https://github.com/saugardev/zkmedia/tree/main/img-editor/verifier"

    classDef frontend fill:#FFCC00,stroke:#333,stroke-width:2px;
    classDef backend fill:#99CCFF,stroke:#333,stroke-width:2px;
    classDef blockchain fill:#CCFFCC,stroke:#333,stroke-width:2px;
```
