Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:1broseidon Ketch Provider Registry Pattern

From Leeroopedia
Knowledge Sources
Domains Architecture, Provider_Registry
Last Updated 2026-10-27 00:00 GMT

Overview

A design pattern in which each search surface (web, code, docs) keeps its backends in an explicitly-ordered, package-level registry of descriptors, so a new backend flows through config discovery, CLI/MCP descriptions, doctor, and auto/multi eligibility by appending one descriptor call.

Theoretical Basis

The provider registry decouples what a backend can do (described statically by a descriptor) from how it is selected (driven by the operator's config and the caller's mode). Each registry is an ordered list of `Provider` descriptors with: an `ID` and `Name` for display; `Usable` (a no-network precondition predicate); `New` (construction that accepts empty credentials and never contacts the service); `Probe` (the doctor health check); `Settings` (the config fields it owns); and surface-specific fields (`AutoRank`/`AutoEligible` for search, `Regexp`/`Qualifiers`/`PartialIndex` for code, `LibraryResolver` for docs).

Construction is gated by `Build`, which calls `Usable` before `New`, so an unconfigured backend fails with its `Setup` message rather than at query time. Registration is explicit, without `init()`, so the order is the stable presentation order and a missing registration is a visible diff. Every shared consumer derives from the slice, so a single append propagates everywhere.

Why three separate registries? Web search, code search, and docs search have different result types, query dialects, and capability sets. Sharing one interface would force the least-common-denominator and lose the per-surface fields (e.g. `Regexp`, `LibraryResolver`). The three `Searcher` interfaces are deliberately independent.

Usage

Use this pattern when a system has multiple interchangeable backends with different capabilities and config requirements, and you want adding a backend to be a one-file change that flows through every consumer. The descriptor-driven approach keeps provider-specific branches out of shared code: a new backend declares what it can do, and the shared consumers read that declaration.

Practical Guide

  1. Implement the backend in one Go file under `search/`, `code/`, or `docs/`: the `Searcher` interface, `New`, `Usable`, `Probe`.
  2. Declare settings on the descriptor (`config.KeyPool` for secrets, `config.Scalar` for URLs).
  3. Set `AutoRank`/`AutoEligible` to join the `auto` chain (search only).
  4. Add code/docs-specific descriptor fields as needed (`Regexp`, `Qualifiers`, `PartialIndex`, `LibraryResolver`).
  5. Append the descriptor call to the `providers` slice — no `init()`.
  6. Write tests; regenerate golden fixtures with `UPDATE_REGISTRY_GOLDENS=1 go test ./cmd/ ./doctor/`.

Related Pages

Implemented By

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment