canonry

Architecture

Overview

Canonry is a self-hosted, agent-first AEO platform. It measures brand mentions and domain citations for tracked queries across its supported providers. Its content engine and integrations use those observations. The Local adapter captures no structured sources, so its answers contribute to mention measurements only.

A project can define named locations and a default location. An Advanced Measurement plan also assigns queries and measurement contexts to Properties and markets.

Local Architecture

The local installation runs as a single Node.js process with SQLite and an in-process job runner.

flowchart LR
  User["Analyst"]
  Target["AI answer engines"]

  subgraph Process["canonry serve"]
    direction LR
    SPA["Static SPA<br/>/"] --> API["Fastify API<br/>/api/v1/*"]
    API --> JobRunner["In-process<br/>job runner"]
    API --> SQLite["SQLite"]
    JobRunner --> Registry["Provider<br/>Registry"]
    Registry --> Gemini["provider-gemini"]
    Registry --> OpenAI["provider-openai"]
    Registry --> OpenRouter["provider-openrouter (model routes)"]
    Registry --> Muse["provider-muse"]
    Registry --> Claude["provider-claude"]
    Registry --> Perplexity["provider-perplexity"]
    Registry --> Local["provider-local"]
    Registry --> CDP["provider-cdp"]
    Registry --> AnswerServices["provider-answer-services (profiles)"]
    JobRunner --> SQLite
  end

  User --> SPA
  User -. CLI .-> API
  Gemini --> Target
  OpenAI --> Target
  OpenRouter --> Target
  Muse --> Target
  Claude --> Target
  Perplexity --> Target
  Local --> Target
  CDP --> Target
  AnswerServices --> Target

Key components

Data flow

  1. Analyst runs canonry run <project> with the project default location, an explicit --location, --all-locations, or no location context
  2. API creates a run record and enqueues a job
  3. The job runner executes the run’s selected providers and queries. A published plan supplies frozen execution slots. Each adapter receives the requested location and reports its treatment.
  4. Each saved answer records its mention and citation observations by query and provider. Plan-aware runs also record the execution ID and location context.
  5. Transitions (lost, emerging) are computed at query time by comparing each measured snapshot with the last measured one before it. A not-measured snapshot is skipped, so it never gains or loses a citation
  6. Dashboard polls API for results and renders visibility data

Module Dependency Graph

flowchart TD
  subgraph Apps
    web["apps/web"]
    api["apps/api"]
  end

  subgraph Packages
    canonry["packages/canonry"]
    routes["packages/api-routes"]
    contracts["packages/contracts"]
    db["packages/db"]
    config["packages/config"]
    intelligence["packages/intelligence"]
  end

  subgraph Providers
    gemini["provider-gemini"]
    openai["provider-openai"]
    openrouter["provider-openrouter"]
    muse["provider-muse"]
    claude["provider-claude"]
    local["provider-local"]
    perplexity["provider-perplexity"]
    cdp["provider-cdp"]
    answerServices["provider-answer-services"]
  end

  subgraph Integrations
    gsc["integration-google"]
    ga4["integration-google-analytics"]
    bing["integration-bing"]
    wp["integration-wordpress"]
  end

  web -.-> contracts
  api --> routes & db & config & contracts

  canonry --> routes
  canonry --> db
  canonry --> config
  canonry --> contracts
  canonry --> intelligence
  canonry --> gemini & openai & openrouter & muse & claude & local & perplexity & cdp & answerServices

  routes --> db
  routes --> contracts
  routes --> gsc & ga4 & bing & wp

  gemini & openai & openrouter & muse & claude & local & perplexity & cdp & answerServices --> contracts
  gsc & ga4 & bing & wp --> contracts
  db --> contracts

Key rules:

Run Lifecycle

stateDiagram-v2
  [*] --> queued: POST /runs
  queued --> running: Job runner picks up
  running --> completed: All providers succeed
  running --> partial: Some providers fail
  running --> failed: All providers fail
  running --> cancelled: User cancels

  completed --> [*]
  partial --> [*]
  failed --> [*]
  cancelled --> [*]

Transitions:

Provider System

The shared ProviderAdapter interface defines execution, normalization, and optional capabilities such as batch dispatch and text generation. The provider registry registers configured connections. OpenRouter model routes and search answer service profiles use their connection’s credentials and quota. Each route requires explicit selection.

The job runner executes the selected work and normalizes responses before it persists them in query_snapshots. Plan-aware runs can store several answers for one query and provider when the execution contexts differ.

Ad-hoc research uses the same provider adapters through a separate research_runs → research_run_queries executor. It persists returned answer evidence and applies the same provider quota guards, but it never creates a tracked query, shared run, snapshot, insight, notification, or schedule event.

Deployment Model

Run canonry serve on your own machine, a VPS, or a container. One process serves the SPA and REST API, runs jobs and schedules, and uses SQLite. See the deployment guide for setup.

The standalone apps/api entry point mounts the shared REST routes on Cloud Run and uses SQLite. The full engine runs through canonry serve.

Service Boundaries

Design Constraints

Score Families

These remain separate to avoid mixing Agent Readiness with live-answer visibility.

Agent Layer

Canonry ships a built-in AI agent (Aero) backed by @earendil-works/pi-agent-core, plus a webhook path for external agents (Claude Code, Codex, custom). See packages/canonry/src/agent/AGENTS.md for the full surface.

The agent layer is a consumer of the same CLI/API surface — nothing in it is privileged. Per AGENTS.md, “If an AI agent can’t do something with canonry <command> --format json or an HTTP call, it’s a bug.”

Sentiment integration

packages/canonry bundles @canonry/canonry-integration-typesafe, whose only internal dependency is contracts. The adapter owns pinned Jev request construction and parsing; the host owns credentials and scheduling. Evidence is resolved to exact original sentence spans. Offline corpus scoring and the independent-evaluation targets, not yet met, live under evals/sentiment/.