# contentauth/c2pa-c architecture

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

## Overview

##### Project type and purpose
- This is an open-source C++ library (c2pa_cpp) that exposes C and C++ APIs for reading, validating, and writing C2PA manifests inside media files.
- It sits as a wrapper around a set of pre-built dynamic libraries from the c2pa-rs (Rust) implementation, providing a CMake-friendly interface for C++ applications.

##### File structure
- Top-level build/config:
- CMakeLists.txt, Makefile – orchestrate building the core library, examples, and tests.
- .github/workflows/*.yml – CI pipelines for linting, building, testing, and release.
- Core library:
- /c2pa.hpp – public C++ header API.
- src/c2pa.cpp – implementation wrapping calls into the Rust dynamic libraries.
- Examples:
- examples/demo.cpp, training.cpp – sample apps showing read/validate and write workflows.
- examples/CMakeLists.txt – build scripts for the samples.
- Tests:
- tests/*.cpp, tests/fixtures – unit and integration tests, including CLI-style tests (cmd_signer), file_stream tests, version tests.
- tests/CMakeLists.txt – build and link the test binaries.
- Documentation:
- docs/usage.md, docs/c_api.md – guides on using the public API.

##### Key points from the README
- The library is intended to be added via CMake FetchContent to any CMake-based project.
- It automatically selects the right c2pa-rs dynamic library per platform or allows building your own.
- You link your executable against the c2pa_cpp target to get the C++ APIs.

##### Main components
a. Application layer (consumer)
– Your C++ application or CLI tool (examples/demo.cpp, your “myapp”)
– Links to the c2pa_cpp CMake target
b. c2pa_cpp library
– Public API (include/c2pa.hpp)
– Implementation (src/c2pa.cpp)
– Build system (CMakeLists.txt, Makefile)
c. Underlying c2pa-rs dynamic libraries (Rust modules)
– Crypto & manifest processing engines
– Platform-specific shared libs (.so/.dylib/.dll)
d. Media files & Manifests
– Supported image/video formats (PNG, JPEG, etc.)
– In-file C2PA manifests (embedded metadata)
e. Test harness & examples
– Unit tests
– CLI-style tests (cmd_signer)
– Example apps demonstrating read/write flows

##### Relationships and data flow
- The application invokes c2pa_cpp APIs →
- c2pa_cpp forwards calls via FFI into the Rust dynamic libraries →
- Rust libs parse or serialize C2PA manifests in media files →
- Results (validation status, manifest JSON, modified files) are returned back up through c2pa_cpp →
- Application consumes or displays results.

##### Architectural patterns & design principles
- Wrapper/Facade: c2pa_cpp hides FFI complexity behind a clean C++ API.
- Modular layering: separation of build system, public API, implementation, and external dependencies.
- Test-driven design: comprehensive unit & integration tests exercising both API and CLI behaviors.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Application Layer
    subgraph "Application Layer" 
        direction TB
        Demo["demo.cpp"]:::cpp
        Training["training.cpp"]:::cpp
        ExCMake["CMakeLists.txt"]:::infra
    end

    %% Core Library
    subgraph "c2pa_cpp Library" 
        direction TB
        PublicAPI["c2pa.hpp"]:::cpp
        Impl["c2pa.cpp"]:::cpp
        LibCMake["CMakeLists.txt"]:::infra
        Makefile["Makefile"]:::infra
    end

    %% Rust Dynamic Libraries
    RustLibs["c2pa-rs Shared Libs"]:::rust

    %% Media Files & Manifests
    subgraph "Media Files & Manifests" 
        direction TB
        Fixture1["training.json"]:::media
        Fixture2["ed25519.pem"]:::media
        Fixture3["ed25519.pub"]:::media
        Fixture4["es256_certs.pem"]:::media
        Fixture5["es256_private.key"]:::media
    end

    %% Test Harness & Integration Tests
    subgraph "Tests & Fixtures" 
        direction TB
        TestCMake["CMakeLists.txt"]:::infra
        BuilderTest["builder.test.cpp"]:::test
        CmdSignerCPP["cmd_signer.cpp"]:::test
        CmdSignerH["cmd_signer.hpp"]:::test
        FileStreamH["file_stream.h"]:::test
        ReadTest["read_file.test.cpp"]:::test
        ReaderTest["reader.test.cpp"]:::test
        VersionTest["version.test.cpp"]:::test
        TestC["test.c"]:::test
        TestCPP["test.cpp"]:::test
        UnitH["unit_test.h"]:::test
    end

    %% Documentation
    subgraph Documentation
        direction TB
        Usage["usage.md"]:::doc
        CAPI["c_api.md"]:::doc
        README["README.md"]:::doc
    end

    %% Relationships
    Demo -->|"link via CMake"| PublicAPI
    Training -->|"link via CMake"| PublicAPI
    ExCMake -->|build-time| LibCMake
    LibCMake -->|orchestrates| PublicAPI
    Makefile -->|orchestrates| Impl
    PublicAPI -->|"calls FFI"| Impl
    Impl -->|"loads shared libs"| RustLibs
    RustLibs -->|-->|Fixture1
    RustLibs -.->|-->|Fixture2
    RustLibs -.->|-->|Fixture3
    RustLibs -.->|-->|Fixture4
    RustLibs -.->|-->|Fixture5

    BuilderTest -->|"uses API"| PublicAPI
    CmdSignerCPP -->|"uses CLI"| Impl
    ReadTest -->|"reads manifests"| Impl
    ReaderTest -->|"validates"| Impl
    VersionTest -->|"checks version"| PublicAPI
    TestCPP -->|"misc"| PublicAPI
    TestC -->|"C API tests"| PublicAPI
    FileStreamH -->|"support"| Impl
    UnitH -->|"unit headers"| Impl
    TestCMake -->|builds| BuilderTest

    Usage -->|"docs for API"| PublicAPI
    CAPI -->|"docs for C API"| PublicAPI
    README -->|"overview/readme"| PublicAPI

    %% Click Events
    click Demo "https://github.com/contentauth/c2pa-c/blob/main/examples/demo.cpp"
    click Training "https://github.com/contentauth/c2pa-c/blob/main/examples/training.cpp"
    click ExCMake "https://github.com/contentauth/c2pa-c/blob/main/examples/CMakeLists.txt"
    click PublicAPI "https://github.com/contentauth/c2pa-c/blob/main/include/c2pa.hpp"
    click Impl "https://github.com/contentauth/c2pa-c/blob/main/src/c2pa.cpp"
    click LibCMake "https://github.com/contentauth/c2pa-c/blob/main/src/CMakeLists.txt"
    click Makefile "https://github.com/contentauth/c2pa-c/tree/main/Makefile"
    click BuilderTest "https://github.com/contentauth/c2pa-c/blob/main/tests/builder.test.cpp"
    click CmdSignerCPP "https://github.com/contentauth/c2pa-c/blob/main/tests/cmd_signer.cpp"
    click CmdSignerH "https://github.com/contentauth/c2pa-c/blob/main/tests/cmd_signer.hpp"
    click FileStreamH "https://github.com/contentauth/c2pa-c/blob/main/tests/file_stream.h"
    click ReadTest "https://github.com/contentauth/c2pa-c/blob/main/tests/read_file.test.cpp"
    click ReaderTest "https://github.com/contentauth/c2pa-c/blob/main/tests/reader.test.cpp"
    click VersionTest "https://github.com/contentauth/c2pa-c/blob/main/tests/version.test.cpp"
    click TestC "https://github.com/contentauth/c2pa-c/blob/main/tests/test.c"
    click TestCPP "https://github.com/contentauth/c2pa-c/blob/main/tests/test.cpp"
    click UnitH "https://github.com/contentauth/c2pa-c/blob/main/tests/unit_test.h"
    click TestCMake "https://github.com/contentauth/c2pa-c/blob/main/tests/CMakeLists.txt"
    click Fixture1 "https://github.com/contentauth/c2pa-c/blob/main/tests/fixtures/training.json"
    click Fixture2 "https://github.com/contentauth/c2pa-c/blob/main/tests/fixtures/ed25519.pem"
    click Fixture3 "https://github.com/contentauth/c2pa-c/blob/main/tests/fixtures/ed25519.pub"
    click Fixture4 "https://github.com/contentauth/c2pa-c/blob/main/tests/fixtures/es256_certs.pem"
    click Fixture5 "https://github.com/contentauth/c2pa-c/blob/main/tests/fixtures/es256_private.key"
    click Usage "https://github.com/contentauth/c2pa-c/blob/main/docs/usage.md"
    click CAPI "https://github.com/contentauth/c2pa-c/blob/main/docs/c_api.md"
    click README "https://github.com/contentauth/c2pa-c/blob/main/README.md"

    %% Styles
    classDef cpp fill:#DDEEFF,stroke:#3399FF,color:#000;
    classDef rust fill:#E8F5E9,stroke:#43A047,color:#000;
    classDef infra fill:#F5F5F5,stroke:#888888,color:#000;
    classDef media fill:#FFEBEE,stroke:#E53935,color:#000;
    classDef test fill:#FFF3E0,stroke:#FB8C00,color:#000;
    classDef doc fill:#E3F2FD,stroke:#1E88E5,color:#000;
```
