Architecture#

Grantstamp has one Python package with four entry points, plus a static website:

flowchart LR
  subgraph Owner machine
    CLI[grantstamp CLI] --> FP1[fingerprint engine]
  end
  subgraph User / agent machine
    MCP[MCP server grantstamp-mcp] --> FP2[fingerprint engine]
    HOOK[Claude Code hook grantstamp-hook] --> FP2
    WEB[website check page, in-browser JS] --> FPJ[JS strings + SHA-256]
  end
  subgraph Registry server
    API[FastAPI /v1] --> AUTH[RFC 9421 signatures, rate limits, PoW]
    API --> MATCH[matching and bands]
    API --> POL[policies, licence tokens]
    API --> LOG[transparency log, receipts]
    API --> ALERT[alerts and webhooks]
    MATCH --> DB[(SQLite or Postgres)]
    POL --> DB
    LOG --> DB
    ALERT --> DB
  end
  FP1 -- signed stamp registration --> API
  FP2 -- digests + use + tokens --> API
  FPJ -- digests --> API
  ALERT -- Slack / Discord / JSON webhook --> OWNERHOOK[owner's channel]
  GHA[GitHub Action: daily witness] -- fetch signed log head --> API

Components#

Component Code Runs where Talks to
Fingerprint engine src/grantstamp/fingerprint/ wherever content is (owner or user machine) nothing (offline)
Registry API server/src/grantstamp_server/app.py (AGPL-3.0) your server (Render, VPS, Docker) database, webhooks, DoH for domain checks
Matching grantstamp_server/matching.py registry database
Storage grantstamp_server/db.py, grantstamp_server/store.py registry SQLite (default) or Postgres
CLI src/grantstamp/cli.py owner and agent machines registry
MCP server src/grantstamp/mcp_server.py user machine, launched by the AI client over stdio registry
Claude Code hook src/grantstamp/hook.py user machine, launched by Claude Code registry
Website src/grantstamp/site/ GitHub Pages and the registry itself registry API (CORS)

Data model#

erDiagram
  OWNER ||--o{ KEY : signs-with
  OWNER ||--o{ DOMAIN : verifies
  OWNER ||--o{ STAMP : registers
  STAMP ||--o{ FILE : contains
  FILE ||--o{ FEATURE : has
  STAMP ||--o{ EVENT : matched-by
  OWNER ||--o{ ALERT : receives
  STAMP ||--o{ DISPUTE : challenged-by
  AGENT ||--o{ KEY : signs-with
  LOG_ENTRY }o--|| LOG_ENTRY : chains-to

Security boundaries#

Request flow: POST /v1/check#

  1. Authenticate: anonymous, or a signed agent or owner request (unknown keys can be discovered through Signature-Agent).
  2. Rate-limit by caller class. Anonymous callers can add quota with a proof-of-work header.
  3. Parse the bundle and drop background features (common runtime strings and chunks).
  4. Look up exact SHA-256s and look up each similarity layer's hashes in the inverted index.
  5. Suppress features shared by three or more different owners.
  6. Grade each (query file, registered file) pair, aggregate per stamp, and apply marker and manifest claims.
  7. For medium and above, evaluate the owner's policy for the use, purpose and licence tokens. Medium turns deny into ask.
  8. Record events and raise alerts (match, probing), then deliver webhooks in the background.
  9. Return the bands, decisions, guidance text and a receipt signed by the registry.

Scaling path#

Stage Change
Prototype (now) 1 instance; SQLite or Postgres; in-memory rate limits. Measured with 3,000 registered files on a 2-CPU machine: 15 ms median check, about 58 checks a second, about 76 KB of database per executable (bench/LOAD.md)
Thousands of stamps Postgres; connection pool; Redis rate limits; CDN in front of the API
Millions of files Fixed-size sketches per file in place of one index row per feature; tables partitioned by hash; batch upload via object storage
Billions of files Move the feats index to a key-value store (e.g. ScyllaDB or RocksDB), shard by hash prefix; the log becomes a Merkle tree served as static tiles with inclusion proofs
Function-level similarity Add an approximate-nearest-neighbour index (e.g. pgvector or FAISS) for code embeddings
Speed Port the fingerprint core to Rust (same protocol constants) and ship it as a wheel and as WebAssembly for the browser

Source of this page on GitHub. Documentation for Grantstamp 0.2, licensed CC BY 4.0.