# contentauth/c2pa-min architecture

> Architecture diagram of the GitHub repository contentauth/c2pa-min, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/contentauth/c2pa-min
- Repository: https://github.com/contentauth/c2pa-min

## Overview

##### Project type and purpose
- This is a minimal command-line example application, written in Rust, demonstrating how to sign media assets using the C2PA Rust SDK without OpenSSL.
- It consists of two binaries:
– c2pa_min (main): orchestrates manifest building and external signing
– signer: a standalone signing tool that reads data from stdin, signs with a private key, and writes to stdout

##### File structure
- Cargo.toml / Cargo.lock: Rust project metadata and dependencies (including the C2PA Rust SDK)
- src/main.rs: Main application logic (calls into C2PA Builder & Reader API and invokes the signer)
- src/bin/signer.rs: Standalone signer binary that performs Ed25519 signing
- src/fixtures/: Contains test private key, public key, and certs used by the signer
- compose-dev.yaml, deny.toml, CI workflow: Auxiliary configuration for development, linting, and CI

##### Key insights from the README
- The main binary builds a C2PA manifest using the new API (`Builder` / `Reader`)
- It spawns the signer as a child process, passing payload bytes via stdin
- The signer returns the signed payload via stdout, keeping private keys out of the main process
- The application writes the signed output to a file (e.g., `target/output.jpg`)

##### Main components
a. c2pa_min (Main CLI App)
– Uses C2PA Rust SDK (Builder & Reader modules)
– Invokes `signer` as an external process
– Reads input asset, constructs manifest, writes output file
b. signer (External Signing App)
– Reads raw bytes from stdin
– Loads private key & certs from src/fixtures
– Uses Ed25519 algorithm to sign data
– Emits signed bytes to stdout
c. C2PA Rust Library
– Exposed in main app via `Builder` / `Reader`
– Responsible for packaging metadata into the asset
d. Fixtures (Private/Public Keys, Certificates)
– Stored under src/fixtures
– Accessed only by signer
e. Target/output.jpg (or other asset)
– Final signed asset, which can be verified by external tools

##### Relationships & data flows
1. User invokes `c2pa_min` CLI
2. c2pa_min reads original asset bytes
3. c2pa_min calls into C2PA Builder to generate a manifest and payload that needs signing
4. c2pa_min spawns `signer` process
– Passes payload bytes via stdin pipe
5. signer reads bytes → loads fixtures → signs bytes → writes signed bytes to stdout
6. c2pa_min reads signed bytes from stdout, finalizes the manifest, and writes the output asset to disk
7. The final asset can be validated later with OpenSSL-enabled tools or C2PA verification services

##### Architectural patterns & design principles
- Separation of concerns:
– Main app handles manifest building and I/O orchestration
– Signer app handles key material and cryptographic operations
- Security principle: keys never loaded into the main process
- Modular design: Both binaries are built from the same Cargo workspace but run independently
- Pipe & filter: Unix-style piping (stdin/stdout) to decouple processes

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Components
    User["User"] 
    Main["c2pa_min (Main CLI App)"]:::process
    SDK["C2PA Rust SDK\n(Builder & Reader)"]:::library
    Signer["Signer App"]:::process
    Fixtures["Fixtures\n(keys & certs)"]:::resource
    AssetIn["Input Asset"]:::resource
    Output["Output Asset"]:::resource

    %% Auxiliary Configuration
    subgraph "Auxiliary Configuration"
        Compose["compose-dev.yaml"]:::resource
        Deny["deny.toml"]:::resource
        CI[".github/workflows/ci.yml"]:::resource
    end

    %% Data Flow
    User -->|"invokes CLI"| Main
    Main -->|"reads asset (File I/O)"| AssetIn
    Main -->|"Builder API call"| SDK
    SDK -->|"payload bytes"| Main
    Main -->|"stdin pipe"| Signer
    Signer -->|"loads fixtures"| Fixtures
    Signer -->|"stdout pipe"| Main
    Main -->|"writes output (File I/O)"| Output

    %% Click Events
    click Main "https://github.com/contentauth/c2pa-min/blob/main/src/main.rs"
    click Signer "https://github.com/contentauth/c2pa-min/blob/main/src/bin/signer.rs"
    click SDK "https://github.com/contentauth/c2pa-min/blob/main/Cargo.toml"
    click Fixtures "https://github.com/contentauth/c2pa-min/tree/main/src/fixtures/"
    click Compose "https://github.com/contentauth/c2pa-min/blob/main/compose-dev.yaml"
    click Deny "https://github.com/contentauth/c2pa-min/blob/main/deny.toml"
    click CI "https://github.com/contentauth/c2pa-min/blob/main/.github/workflows/ci.yml"

    %% Styles
    classDef process fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef library fill:#90EE90,stroke:#000,stroke-width:1px
    classDef resource fill:#FFA500,stroke:#000,stroke-width:1px
```
