# whaaaley/opencode-search architecture

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

- Interactive diagram: https://gitdiagram.com/whaaaley/opencode-search
- Repository: https://github.com/whaaaley/opencode-search

## Overview

opencode-search is an OpenCode plugin that exposes nine search tools. OpenCode invokes a tool in `src/search.ts`, which dispatches to a source-specific provider; results are rendered and formatted for the tool response and also posted to the session. Providers query public search APIs or HTML/RSS endpoints, with a shared file-backed cache. The README documents each source and its behavior; provider-to-cache and tool-to-provider links are supported by the source index or excerpts. Some provider internals were not sampled, so details beyond those documented are omitted.

Main entry points: [`src/search.ts`](https://github.com/whaaaley/opencode-search/blob/main/src/search.ts) (Search tools), [`src/cache.ts`](https://github.com/whaaaley/opencode-search/blob/main/src/cache.ts) (File cache), [`src/providers/ddg-search.ts`](https://github.com/whaaaley/opencode-search/blob/main/src/providers/ddg-search.ts) (DuckDuckGo search), [`src/providers/brave-search.ts`](https://github.com/whaaaley/opencode-search/blob/main/src/providers/brave-search.ts) (Brave search)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_plugin["Plugin workflow"]
  node_plugin_entry["Plugin entry<br/>[search.ts]"]
  node_tool_dispatch["Search tools<br/>[search.ts]"]
  node_renderers["Result renderers<br/>[renderers.ts]"]
  node_format["Result formatting<br/>[format.ts]"]
  node_notify["Session notification<br/>[notify.ts]"]
end

subgraph group_web["Web and news"]
  node_ddg["DuckDuckGo search<br/>[ddg-search.ts]"]
  node_brave["Brave search<br/>[brave-search.ts]"]
  node_gnews["Google News search<br/>[gnews-search.ts]"]
end

subgraph group_reference["Knowledge and specs"]
  node_bsky["Bluesky search<br/>[bsky-search.ts]"]
  node_wiki["Wikipedia search<br/>[wiki-search.ts]"]
  node_mdn["MDN search<br/>[mdn-search.ts]"]
  node_rfc["RFC search<br/>[rfc-search.ts]"]
  node_w3c["W3C search<br/>[w3c-search.ts]"]
  node_whatwg["WHATWG search<br/>[whatwg-search.ts]"]
end

subgraph group_shared["Shared services"]
  node_cache[("File cache<br/>[cache.ts]")]
  node_strategies["Fetch strategies<br/>[strategies.ts]"]
  node_html["HTML parsing<br/>[html.ts]"]
  node_safe["Error handling<br/>[safe.ts]"]
  node_normalize["Blurb normalization<br/>[normalize-blurb.ts]"]
end

node_opencode(("OpenCode agent"))
node_ddg_service["DuckDuckGo"]
node_brave_service["Brave Search"]
node_news_service["Google News RSS"]
node_bsky_service["Bluesky AT Protocol"]
node_wiki_service["Wikipedia API"]
node_mdn_service["MDN API"]
node_ietf_service["IETF Datatracker"]
node_w3c_service["W3C API"]
node_whatwg_service["WHATWG index"]

node_opencode -->|"loads plugin"| node_plugin_entry
node_plugin_entry -->|"delegates to"| node_tool_dispatch
node_opencode -->|"invokes tools"| node_tool_dispatch
node_tool_dispatch -->|"calls search"| node_ddg
node_tool_dispatch -->|"calls search"| node_brave
node_tool_dispatch -->|"calls search"| node_gnews
node_tool_dispatch -->|"calls search"| node_bsky
node_tool_dispatch -->|"calls search"| node_wiki
node_tool_dispatch -->|"calls search"| node_mdn
node_tool_dispatch -->|"calls search"| node_rfc
node_tool_dispatch -->|"calls search"| node_w3c
node_tool_dispatch -->|"calls search"| node_whatwg
node_tool_dispatch -->|"selects renderer"| node_renderers
node_tool_dispatch -->|"formats results"| node_format
node_tool_dispatch -->|"posts result"| node_notify
node_tool_dispatch -->|"wraps calls"| node_safe
node_renderers -->|"uses date helpers"| node_format
node_renderers -->|"normalizes blurbs"| node_normalize
node_ddg -->|"reads and writes"| node_cache
node_brave -->|"uses cache"| node_cache
node_gnews -->|"reads and writes"| node_cache
node_bsky -->|"reads and writes"| node_cache
node_wiki -->|"reads and writes"| node_cache
node_mdn -->|"reads and writes"| node_cache
node_rfc -->|"uses cache"| node_cache
node_w3c -->|"reads and writes"| node_cache
node_whatwg -->|"uses cache"| node_cache
node_ddg -->|"runs fallbacks"| node_strategies
node_brave -->|"uses strategies"| node_strategies
node_ddg -->|"parses response"| node_html
node_brave -->|"uses parser"| node_html
node_ddg -->|"fetches results"| node_ddg_service
node_brave -->|"fetches results"| node_brave_service
node_gnews -->|"queries feed"| node_news_service
node_bsky -->|"queries posts"| node_bsky_service
node_wiki -->|"queries articles"| node_wiki_service
node_mdn -->|"queries docs"| node_mdn_service
node_rfc -->|"queries RFCs"| node_ietf_service
node_w3c -->|"queries specs"| node_w3c_service
node_whatwg -->|"fetches index"| node_whatwg_service

click node_plugin_entry "https://github.com/whaaaley/opencode-search/blob/main/search.ts"
click node_tool_dispatch "https://github.com/whaaaley/opencode-search/blob/main/src/search.ts"
click node_renderers "https://github.com/whaaaley/opencode-search/blob/main/src/renderers.ts"
click node_format "https://github.com/whaaaley/opencode-search/blob/main/src/format.ts"
click node_notify "https://github.com/whaaaley/opencode-search/blob/main/src/opencode/notify.ts"
click node_ddg "https://github.com/whaaaley/opencode-search/blob/main/src/providers/ddg-search.ts"
click node_brave "https://github.com/whaaaley/opencode-search/blob/main/src/providers/brave-search.ts"
click node_gnews "https://github.com/whaaaley/opencode-search/blob/main/src/providers/gnews-search.ts"
click node_bsky "https://github.com/whaaaley/opencode-search/blob/main/src/providers/bsky-search.ts"
click node_wiki "https://github.com/whaaaley/opencode-search/blob/main/src/providers/wiki-search.ts"
click node_mdn "https://github.com/whaaaley/opencode-search/blob/main/src/providers/mdn-search.ts"
click node_rfc "https://github.com/whaaaley/opencode-search/blob/main/src/providers/rfc-search.ts"
click node_w3c "https://github.com/whaaaley/opencode-search/blob/main/src/providers/w3c-search.ts"
click node_whatwg "https://github.com/whaaaley/opencode-search/blob/main/src/providers/whatwg-search.ts"
click node_cache "https://github.com/whaaaley/opencode-search/blob/main/src/cache.ts"
click node_strategies "https://github.com/whaaaley/opencode-search/blob/main/src/strategies.ts"
click node_html "https://github.com/whaaaley/opencode-search/blob/main/src/html.ts"
click node_safe "https://github.com/whaaaley/opencode-search/blob/main/src/safe.ts"
click node_normalize "https://github.com/whaaaley/opencode-search/blob/main/src/normalize-blurb.ts"

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_plugin_entry,node_tool_dispatch,node_renderers,node_format,node_notify toneBlue
class node_ddg,node_brave,node_gnews toneAmber
class node_bsky,node_wiki,node_mdn,node_rfc,node_w3c,node_whatwg,node_wiki_service,node_mdn_service,node_w3c_service toneMint
class node_cache,node_strategies,node_html,node_safe,node_normalize toneRose
class node_opencode,node_ddg_service,node_brave_service,node_news_service,node_bsky_service,node_ietf_service,node_whatwg_service toneIndigo
```

## Components

### Plugin workflow

- [Plugin entry](https://github.com/whaaaley/opencode-search/blob/main/search.ts): `search.ts`
- [Search tools](https://github.com/whaaaley/opencode-search/blob/main/src/search.ts): `src/search.ts`
- [Result renderers](https://github.com/whaaaley/opencode-search/blob/main/src/renderers.ts): `src/renderers.ts`
- [Result formatting](https://github.com/whaaaley/opencode-search/blob/main/src/format.ts): `src/format.ts`
- [Session notification](https://github.com/whaaaley/opencode-search/blob/main/src/opencode/notify.ts): `src/opencode/notify.ts`

### Web and news

- [DuckDuckGo search](https://github.com/whaaaley/opencode-search/blob/main/src/providers/ddg-search.ts): `src/providers/ddg-search.ts`
- [Brave search](https://github.com/whaaaley/opencode-search/blob/main/src/providers/brave-search.ts): `src/providers/brave-search.ts`
- [Google News search](https://github.com/whaaaley/opencode-search/blob/main/src/providers/gnews-search.ts): `src/providers/gnews-search.ts`

### Knowledge and specs

- [Bluesky search](https://github.com/whaaaley/opencode-search/blob/main/src/providers/bsky-search.ts): `src/providers/bsky-search.ts`
- [Wikipedia search](https://github.com/whaaaley/opencode-search/blob/main/src/providers/wiki-search.ts): `src/providers/wiki-search.ts`
- [MDN search](https://github.com/whaaaley/opencode-search/blob/main/src/providers/mdn-search.ts): `src/providers/mdn-search.ts`
- [RFC search](https://github.com/whaaaley/opencode-search/blob/main/src/providers/rfc-search.ts): `src/providers/rfc-search.ts`
- [W3C search](https://github.com/whaaaley/opencode-search/blob/main/src/providers/w3c-search.ts): `src/providers/w3c-search.ts`
- [WHATWG search](https://github.com/whaaaley/opencode-search/blob/main/src/providers/whatwg-search.ts): `src/providers/whatwg-search.ts`

### Shared services

- [File cache](https://github.com/whaaaley/opencode-search/blob/main/src/cache.ts): `src/cache.ts`
- [Fetch strategies](https://github.com/whaaaley/opencode-search/blob/main/src/strategies.ts): `src/strategies.ts`
- [HTML parsing](https://github.com/whaaaley/opencode-search/blob/main/src/html.ts): `src/html.ts`
- [Error handling](https://github.com/whaaaley/opencode-search/blob/main/src/safe.ts): `src/safe.ts`
- [Blurb normalization](https://github.com/whaaaley/opencode-search/blob/main/src/normalize-blurb.ts): `src/normalize-blurb.ts`

### Other components

- **OpenCode agent**
- **DuckDuckGo**
- **Brave Search**
- **Google News RSS**
- **Bluesky AT Protocol**
- **Wikipedia API**
- **MDN API**
- **IETF Datatracker**
- **W3C API**
- **WHATWG index**

## Connections

- OpenCode agent → Plugin entry: loads plugin (evidence: `README.md`)
- Plugin entry → Search tools: delegates to (evidence: `search.ts`)
- OpenCode agent → Search tools: invokes tools (evidence: `README.md`)
- Search tools → DuckDuckGo search: calls search (evidence: `src/search.ts`)
- Search tools → Brave search: calls search (evidence: `src/search.ts`)
- Search tools → Google News search: calls search (evidence: `src/search.ts`)
- Search tools → Bluesky search: calls search (evidence: `src/search.ts`)
- Search tools → Wikipedia search: calls search (evidence: `src/search.ts`)
- Search tools → MDN search: calls search (evidence: `src/search.ts`)
- Search tools → RFC search: calls search (evidence: `src/search.ts`)
- Search tools → W3C search: calls search (evidence: `src/search.ts`)
- Search tools → WHATWG search: calls search (evidence: `src/search.ts`)
- Search tools → Result renderers: selects renderer (evidence: `src/search.ts`)
- Search tools → Result formatting: formats results (evidence: `src/search.ts`)
- Search tools → Session notification: posts result (evidence: `src/search.ts`)
- Search tools → Error handling: wraps calls (evidence: `src/search.ts`)
- Result renderers → Result formatting: uses date helpers (evidence: `src/renderers.ts`)
- Result renderers → Blurb normalization: normalizes blurbs (evidence: `src/renderers.ts`)
- DuckDuckGo search → File cache: reads and writes (evidence: `src/providers/ddg-search.ts`)
- Brave search → File cache: uses cache (evidence: `src/providers/brave-search.ts`)
- Google News search → File cache: reads and writes (evidence: `src/providers/gnews-search.ts`)
- Bluesky search → File cache: reads and writes (evidence: `src/providers/bsky-search.ts`)
- Wikipedia search → File cache: reads and writes (evidence: `src/providers/wiki-search.ts`)
- MDN search → File cache: reads and writes (evidence: `src/providers/mdn-search.ts`)
- RFC search → File cache: uses cache (evidence: `src/providers/rfc-search.ts`)
- W3C search → File cache: reads and writes (evidence: `src/providers/w3c-search.ts`)
- WHATWG search → File cache: uses cache (evidence: `src/providers/whatwg-search.ts`)
- DuckDuckGo search → Fetch strategies: runs fallbacks (evidence: `src/providers/ddg-search.ts`)
- Brave search → Fetch strategies: uses strategies (evidence: `src/providers/brave-search.ts`)
- DuckDuckGo search → HTML parsing: parses response (evidence: `src/providers/ddg-search.ts`)
- Brave search → HTML parsing: uses parser (evidence: `src/providers/brave-search.ts`)
- DuckDuckGo search → DuckDuckGo: fetches results (evidence: `README.md`)
- Brave search → Brave Search: fetches results (evidence: `README.md`)
- Google News search → Google News RSS: queries feed (evidence: `README.md`)
- Bluesky search → Bluesky AT Protocol: queries posts (evidence: `README.md`)
- Wikipedia search → Wikipedia API: queries articles (evidence: `README.md`)
- MDN search → MDN API: queries docs (evidence: `README.md`)
- RFC search → IETF Datatracker: queries RFCs (evidence: `README.md`)
- W3C search → W3C API: queries specs (evidence: `README.md`)
- WHATWG search → WHATWG index: fetches index (evidence: `README.md`)
