# rli8145/provenance architecture

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

- Interactive diagram: https://gitdiagram.com/rli8145/provenance
- Repository: https://github.com/rli8145/provenance

## Overview

Provenance captures and signs photos on-device, anchors attestations to Solana, and verifies exact or recompressed images. The graph includes the app, browser extension, backend, chain program, and registry mirror. Backend routes and some app/extension wiring are represented from the README and file tree; unsampled implementation details are not inferred beyond documented behavior.

Main entry points: [`backend/src/http.ts`](https://github.com/rli8145/provenance/blob/main/backend/src/http.ts) (HTTP API), [`backend/src/server.ts`](https://github.com/rli8145/provenance/blob/main/backend/src/server.ts) (Backend Server), [`extension/background.js`](https://github.com/rli8145/provenance/blob/main/extension/background.js) (Verification Worker), [`lib/registry.ts`](https://github.com/rli8145/provenance/blob/main/lib/registry.ts) (App Registry API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_mobile["Mobile App"]
  node_capture_screen["Capture Screen<br/>[capture.tsx]"]
  node_manifest["Canonical Manifest<br/>[manifest.ts]"]
  node_device_key["Device Key<br/>[deviceKey.ts]"]
  node_mobile_registry["App Registry API<br/>[registry.ts]"]
  node_verify_screen["Verify Screen<br/>[verify.tsx]"]
  node_verdict_logic["Verdict Logic<br/>[verdict.ts]"]
  node_registry_screen["Registry Screen<br/>[registry.tsx]"]
  node_record_detail["Record Detail<br/>[&#91;hash&#93;.tsx]"]
end

subgraph group_browser["Browser Extension"]
  node_extension_popup["Extension Popup<br/>[popup.js]"]
  node_extension_content["Page Content Script<br/>[content.js]"]
  node_badge_scanner["Feed Badge Scanner<br/>[badges.js]"]
  node_extension_worker["Verification Worker<br/>[background.js]"]
end

subgraph group_backend["Backend Services"]
  node_backend_server["Backend Server<br/>[server.ts]"]
  node_http_api["HTTP API<br/>[http.ts]"]
  node_image_phash["Image pHash<br/>[imagePhash.ts]"]
  node_vector_search["pHash Vector Search<br/>[phashVector.ts]"]
  node_lookup_logic["Lookup Logic<br/>[lookup.ts]"]
  node_chain_client["Chain Client<br/>[chain.ts]"]
  node_mongo_client["Mongo Client<br/>[mongo.ts]"]
end

subgraph group_chain["Solana Attestation"]
  node_solana_ledger[("Solana Ledger")]
  node_attestation_program["Attestation Program<br/>[lib.rs]"]
end

subgraph group_registry["Registry Mirror"]
  node_mongo_mirror[("Mongo Registry")]
end

node_camera_user(("Camera User"))
node_extension_user(("Browser User"))
node_solana_explorer["Solana Explorer"]

node_camera_user -->|"captures photo"| node_capture_screen
node_capture_screen -->|"builds manifest"| node_manifest
node_capture_screen -->|"signs manifest"| node_device_key
node_capture_screen -->|"hashes and attests"| node_mobile_registry
node_mobile_registry -->|"POST /attest"| node_backend_server
node_backend_server -->|"dispatches requests"| node_http_api
node_http_api -->|"computes pHash"| node_image_phash
node_http_api -->|"submits attestation"| node_chain_client
node_chain_client -->|"submits transaction"| node_attestation_program
node_attestation_program -->|"writes PDA"| node_solana_ledger
node_http_api -->|"indexes record"| node_mongo_client
node_mongo_client -->|"writes mirror"| node_mongo_mirror
node_verify_screen -->|"requests verdict"| node_verdict_logic
node_verdict_logic -->|"reads derived PDA"| node_solana_ledger
node_verdict_logic -->|"requests fallback match"| node_backend_server
node_backend_server -->|"dispatches lookup"| node_http_api
node_http_api -->|"routes lookup"| node_lookup_logic
node_lookup_logic -->|"searches candidates"| node_mongo_client
node_lookup_logic -->|"confirms match"| node_chain_client
node_mongo_client -->|"reads candidates"| node_mongo_mirror
node_registry_screen -->|"loads attestations"| node_mobile_registry
node_record_detail -->|"loads record"| node_mobile_registry
node_mobile_registry -->|"requests recent records"| node_backend_server
node_extension_user -->|"enables scanning"| node_extension_popup
node_extension_popup -->|"toggles badges"| node_badge_scanner
node_extension_content -->|"requests image verdict"| node_extension_worker
node_badge_scanner -->|"requests image verdict"| node_extension_worker
node_extension_worker -->|"fetches lookup and verify"| node_backend_server
node_extension_worker -->|"checks exact hash"| node_solana_ledger
node_extension_worker -.->|"links transaction"| node_solana_explorer
node_record_detail -.->|"links transaction"| node_solana_explorer
node_vector_search -->|"searches pHash index"| node_mongo_mirror
node_http_api -->|"requests similar images"| node_vector_search

click node_capture_screen "https://github.com/rli8145/provenance/blob/main/app/(tabs)/capture.tsx"
click node_manifest "https://github.com/rli8145/provenance/blob/main/lib/manifest.ts"
click node_device_key "https://github.com/rli8145/provenance/blob/main/lib/deviceKey.ts"
click node_mobile_registry "https://github.com/rli8145/provenance/blob/main/lib/registry.ts"
click node_verify_screen "https://github.com/rli8145/provenance/blob/main/app/(tabs)/verify.tsx"
click node_verdict_logic "https://github.com/rli8145/provenance/blob/main/lib/verdict.ts"
click node_registry_screen "https://github.com/rli8145/provenance/blob/main/app/(tabs)/registry.tsx"
click node_record_detail "https://github.com/rli8145/provenance/blob/main/app/record/%5Bhash%5D.tsx"
click node_extension_popup "https://github.com/rli8145/provenance/blob/main/extension/popup.js"
click node_extension_content "https://github.com/rli8145/provenance/blob/main/extension/content.js"
click node_badge_scanner "https://github.com/rli8145/provenance/blob/main/extension/badges.js"
click node_extension_worker "https://github.com/rli8145/provenance/blob/main/extension/background.js"
click node_backend_server "https://github.com/rli8145/provenance/blob/main/backend/src/server.ts"
click node_http_api "https://github.com/rli8145/provenance/blob/main/backend/src/http.ts"
click node_image_phash "https://github.com/rli8145/provenance/blob/main/backend/src/imagePhash.ts"
click node_vector_search "https://github.com/rli8145/provenance/blob/main/backend/src/phashVector.ts"
click node_lookup_logic "https://github.com/rli8145/provenance/blob/main/backend/src/lookup.ts"
click node_chain_client "https://github.com/rli8145/provenance/blob/main/backend/src/chain.ts"
click node_mongo_client "https://github.com/rli8145/provenance/blob/main/backend/src/mongo.ts"
click node_attestation_program "https://github.com/rli8145/provenance/blob/main/program/programs/provenance/src/lib.rs"

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_capture_screen,node_manifest,node_device_key,node_mobile_registry,node_verify_screen,node_verdict_logic,node_registry_screen,node_record_detail,node_camera_user,node_extension_user toneBlue
class node_extension_popup,node_extension_content,node_badge_scanner,node_extension_worker toneAmber
class node_backend_server,node_http_api,node_image_phash,node_vector_search,node_lookup_logic,node_chain_client,node_mongo_client toneMint
class node_solana_ledger,node_attestation_program toneRose
class node_mongo_mirror,node_solana_explorer toneIndigo
```

## Components

### Mobile App

- [Capture Screen](https://github.com/rli8145/provenance/blob/main/app/(tabs)/capture.tsx): `app/(tabs)/capture.tsx`
- [Canonical Manifest](https://github.com/rli8145/provenance/blob/main/lib/manifest.ts): `lib/manifest.ts`
- [Device Key](https://github.com/rli8145/provenance/blob/main/lib/deviceKey.ts): `lib/deviceKey.ts`
- [App Registry API](https://github.com/rli8145/provenance/blob/main/lib/registry.ts): `lib/registry.ts`
- [Verify Screen](https://github.com/rli8145/provenance/blob/main/app/(tabs)/verify.tsx): `app/(tabs)/verify.tsx`
- [Verdict Logic](https://github.com/rli8145/provenance/blob/main/lib/verdict.ts): `lib/verdict.ts`
- [Registry Screen](https://github.com/rli8145/provenance/blob/main/app/(tabs)/registry.tsx): `app/(tabs)/registry.tsx`
- [Record Detail](https://github.com/rli8145/provenance/blob/main/app/record/%5Bhash%5D.tsx): `app/record/[hash].tsx`

### Browser Extension

- [Extension Popup](https://github.com/rli8145/provenance/blob/main/extension/popup.js): `extension/popup.js`
- [Page Content Script](https://github.com/rli8145/provenance/blob/main/extension/content.js): `extension/content.js`
- [Feed Badge Scanner](https://github.com/rli8145/provenance/blob/main/extension/badges.js): `extension/badges.js`
- [Verification Worker](https://github.com/rli8145/provenance/blob/main/extension/background.js): `extension/background.js`

### Backend Services

- [Backend Server](https://github.com/rli8145/provenance/blob/main/backend/src/server.ts): `backend/src/server.ts`
- [HTTP API](https://github.com/rli8145/provenance/blob/main/backend/src/http.ts): `backend/src/http.ts`
- [Image pHash](https://github.com/rli8145/provenance/blob/main/backend/src/imagePhash.ts): `backend/src/imagePhash.ts`
- [pHash Vector Search](https://github.com/rli8145/provenance/blob/main/backend/src/phashVector.ts): `backend/src/phashVector.ts`
- [Lookup Logic](https://github.com/rli8145/provenance/blob/main/backend/src/lookup.ts): `backend/src/lookup.ts`
- [Chain Client](https://github.com/rli8145/provenance/blob/main/backend/src/chain.ts): `backend/src/chain.ts`
- [Mongo Client](https://github.com/rli8145/provenance/blob/main/backend/src/mongo.ts): `backend/src/mongo.ts`

### Solana Attestation

- **Solana Ledger**
- [Attestation Program](https://github.com/rli8145/provenance/blob/main/program/programs/provenance/src/lib.rs): `program/programs/provenance/src/lib.rs`

### Registry Mirror

- **Mongo Registry**

### Other components

- **Camera User**
- **Browser User**
- **Solana Explorer**

## Connections

- Camera User → Capture Screen: captures photo
- Capture Screen → Canonical Manifest: builds manifest
- Capture Screen → Device Key: signs manifest
- Capture Screen → App Registry API: hashes and attests
- App Registry API → Backend Server: POST /attest
- Backend Server → HTTP API: dispatches requests
- HTTP API → Image pHash: computes pHash
- HTTP API → Chain Client: submits attestation
- Chain Client → Attestation Program: submits transaction
- Attestation Program → Solana Ledger: writes PDA
- HTTP API → Mongo Client: indexes record
- Mongo Client → Mongo Registry: writes mirror
- Verify Screen → Verdict Logic: requests verdict
- Verdict Logic → Solana Ledger: reads derived PDA
- Verdict Logic → Backend Server: requests fallback match
- Backend Server → HTTP API: dispatches lookup
- HTTP API → Lookup Logic: routes lookup
- Lookup Logic → Mongo Client: searches candidates
- Lookup Logic → Chain Client: confirms match
- Mongo Client → Mongo Registry: reads candidates
- Registry Screen → App Registry API: loads attestations
- Record Detail → App Registry API: loads record
- App Registry API → Backend Server: requests recent records
- Browser User → Extension Popup: enables scanning
- Extension Popup → Feed Badge Scanner: toggles badges
- Page Content Script → Verification Worker: requests image verdict
- Feed Badge Scanner → Verification Worker: requests image verdict
- Verification Worker → Backend Server: fetches lookup and verify
- Verification Worker → Solana Ledger: checks exact hash
- Verification Worker → Solana Explorer: links transaction
- Record Detail → Solana Explorer: links transaction
- pHash Vector Search → Mongo Registry: searches pHash index
- HTTP API → pHash Vector Search: requests similar images
