# thepushkarp/etymology-explorer architecture

> Architecture diagram of the GitHub repository thepushkarp/etymology-explorer, 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/thepushkarp/etymology-explorer
- Repository: https://github.com/thepushkarp/etymology-explorer

## Overview

EtymEx is a multilingual etymology explorer. A visitor searches for a word, then the word page serves a cached entry or presents a live trace; the etymology endpoint coordinates research and structured LLM synthesis for uncached words. The graph also covers pronunciation, suggestions, random words, and supporting usage and corpus features. Edges are limited to calls visible in excerpts, SOURCE INDEX references, or README documentation; some unsampled implementation details and runtime wiring are therefore omitted.

Main entry points: [`lib/research.ts`](https://github.com/thepushkarp/etymology-explorer/blob/main/lib/research.ts) (Source research), [`app/word/[...segments]/page.tsx`](https://github.com/thepushkarp/etymology-explorer/blob/main/app/word/%5B...segments%5D/page.tsx) (Word page), [`app/api/etymology/route.ts`](https://github.com/thepushkarp/etymology-explorer/blob/main/app/api/etymology/route.ts) (Etymology endpoint), [`lib/cache.ts`](https://github.com/thepushkarp/etymology-explorer/blob/main/lib/cache.ts) (Result and audio cache)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Search and results"]
  node_search["Word search<br/>[SearchBox.tsx]"]
  node_wordpage["Word page<br/>[page.tsx]"]
  node_entry["Entry display<br/>[EntryView.tsx]"]
  node_trace["Live trace"]
end

subgraph group_api["API services"]
  node_etymology_api["Etymology endpoint<br/>[route.ts]"]
  node_admin_stats["Admin usage stats<br/>[route.ts]"]
end

subgraph group_research["Research and synthesis"]
  node_research_pipeline["Source research<br/>[research.ts]"]
  node_source_clients["Source clients"]
  node_source_parsing["Etymology parsing<br/>[etymologyParser.ts]"]
  node_llm_synthesis["LLM synthesis<br/>[llm.ts]"]
  node_openrouter["OpenRouter adapter"]
end

subgraph group_state["Caching and safeguards"]
  node_result_cache[("Result and audio cache<br/>[cache.ts]")]
  node_redis[("Redis service<br/>[redis.ts]")]
  node_budget["Spend controls<br/>[costGuard.ts]"]
end

subgraph group_extras["Discovery and audio"]
  node_suggestions_api["Suggestions endpoint<br/>[route.ts]"]
  node_word_suggestions["Suggestion ranking<br/>[wordSuggestions.ts]"]
  node_random_word["Random word endpoint<br/>[route.ts]"]
  node_pronunciation_api["Pronunciation endpoint<br/>[route.ts]"]
  node_elevenlabs["Speech generation<br/>[elevenlabs.ts]"]
  node_ngram_api["N-gram endpoint<br/>[route.ts]"]
  node_ngram_data["N-gram lookup<br/>[ngrams.ts]"]
end

node_visitor(("Visitor"))
node_external_sources["Dictionary and reference sources"]
node_openrouter_service{{"OpenRouter"}}
node_elevenlabs_service{{"ElevenLabs"}}

node_visitor -->|"searches"| node_search
node_visitor -->|"opens word"| node_wordpage
node_search -->|"requests suggestions"| node_suggestions_api
node_wordpage -->|"reads cached entry"| node_result_cache
node_wordpage -->|"renders cached result"| node_entry
node_wordpage -->|"renders live trace"| node_trace
node_trace -->|"streams lookup"| node_etymology_api
node_etymology_api -->|"checks and stores"| node_result_cache
node_etymology_api -->|"runs research"| node_research_pipeline
node_etymology_api -->|"requests synthesis"| node_llm_synthesis
node_research_pipeline -->|"fetches evidence"| node_source_clients
node_research_pipeline -->|"parses source text"| node_source_parsing
node_research_pipeline -->|"extracts roots"| node_openrouter
node_llm_synthesis -->|"uses research context"| node_research_pipeline
node_llm_synthesis -->|"requests completion"| node_openrouter
node_openrouter -->|"calls API"| node_openrouter_service
node_source_clients -->|"fetches reference data"| node_external_sources
node_result_cache -->|"reads and writes"| node_redis
node_budget -->|"tracks spend"| node_redis
node_admin_stats -->|"reads budget"| node_budget
node_admin_stats -->|"reads counters"| node_redis
node_suggestions_api -->|"gets suggestions"| node_word_suggestions
node_random_word -.->|"selects word list"| node_external_sources
node_pronunciation_api -->|"checks and stores audio"| node_result_cache
node_pronunciation_api -->|"requests audio"| node_elevenlabs
node_elevenlabs -.->|"generates speech"| node_elevenlabs_service
node_ngram_api -->|"requests frequency"| node_ngram_data

click node_search "https://github.com/thepushkarp/etymology-explorer/blob/main/components/SearchBox.tsx"
click node_wordpage "https://github.com/thepushkarp/etymology-explorer/blob/main/app/word/%5B...segments%5D/page.tsx"
click node_entry "https://github.com/thepushkarp/etymology-explorer/blob/main/components/EntryView.tsx"
click node_trace "https://github.com/thepushkarp/etymology-explorer/blob/main/components/WordTraceExperience.tsx"
click node_etymology_api "https://github.com/thepushkarp/etymology-explorer/blob/main/app/api/etymology/route.ts"
click node_research_pipeline "https://github.com/thepushkarp/etymology-explorer/blob/main/lib/research.ts"
click node_source_clients "https://github.com/thepushkarp/etymology-explorer/blob/main/lib/multilingualSources.ts"
click node_source_parsing "https://github.com/thepushkarp/etymology-explorer/blob/main/lib/etymologyParser.ts"
click node_llm_synthesis "https://github.com/thepushkarp/etymology-explorer/blob/main/lib/llm.ts"
click node_openrouter "https://github.com/thepushkarp/etymology-explorer/blob/main/lib/openrouterResponses.ts"
click node_result_cache "https://github.com/thepushkarp/etymology-explorer/blob/main/lib/cache.ts"
click node_redis "https://github.com/thepushkarp/etymology-explorer/blob/main/lib/redis.ts"
click node_budget "https://github.com/thepushkarp/etymology-explorer/blob/main/lib/costGuard.ts"
click node_admin_stats "https://github.com/thepushkarp/etymology-explorer/blob/main/app/api/admin/stats/route.ts"
click node_suggestions_api "https://github.com/thepushkarp/etymology-explorer/blob/main/app/api/suggestions/route.ts"
click node_word_suggestions "https://github.com/thepushkarp/etymology-explorer/blob/main/lib/wordSuggestions.ts"
click node_random_word "https://github.com/thepushkarp/etymology-explorer/blob/main/app/api/random-word/route.ts"
click node_pronunciation_api "https://github.com/thepushkarp/etymology-explorer/blob/main/app/api/pronunciation/route.ts"
click node_elevenlabs "https://github.com/thepushkarp/etymology-explorer/blob/main/lib/elevenlabs.ts"
click node_ngram_api "https://github.com/thepushkarp/etymology-explorer/blob/main/app/api/ngram/route.ts"
click node_ngram_data "https://github.com/thepushkarp/etymology-explorer/blob/main/lib/ngrams.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_search,node_wordpage,node_entry,node_trace toneBlue
class node_etymology_api,node_admin_stats toneAmber
class node_research_pipeline,node_source_clients,node_source_parsing,node_llm_synthesis,node_openrouter,node_openrouter_service toneMint
class node_result_cache,node_redis,node_budget toneRose
class node_suggestions_api,node_word_suggestions,node_random_word,node_pronunciation_api,node_elevenlabs,node_ngram_api,node_ngram_data,node_visitor,node_external_sources,node_elevenlabs_service toneIndigo
```

## Components

### Search and results

- [Word search](https://github.com/thepushkarp/etymology-explorer/blob/main/components/SearchBox.tsx): `components/SearchBox.tsx`
- [Word page](https://github.com/thepushkarp/etymology-explorer/blob/main/app/word/%5B...segments%5D/page.tsx): `app/word/[...segments]/page.tsx`
- [Entry display](https://github.com/thepushkarp/etymology-explorer/blob/main/components/EntryView.tsx): `components/EntryView.tsx`
- [Live trace](https://github.com/thepushkarp/etymology-explorer/blob/main/components/WordTraceExperience.tsx): `components/WordTraceExperience.tsx`

### API services

- [Etymology endpoint](https://github.com/thepushkarp/etymology-explorer/blob/main/app/api/etymology/route.ts): `app/api/etymology/route.ts`
- [Admin usage stats](https://github.com/thepushkarp/etymology-explorer/blob/main/app/api/admin/stats/route.ts): `app/api/admin/stats/route.ts`

### Research and synthesis

- [Source research](https://github.com/thepushkarp/etymology-explorer/blob/main/lib/research.ts): `lib/research.ts`
- [Source clients](https://github.com/thepushkarp/etymology-explorer/blob/main/lib/multilingualSources.ts): `lib/multilingualSources.ts`
- [Etymology parsing](https://github.com/thepushkarp/etymology-explorer/blob/main/lib/etymologyParser.ts): `lib/etymologyParser.ts`
- [LLM synthesis](https://github.com/thepushkarp/etymology-explorer/blob/main/lib/llm.ts): `lib/llm.ts`
- [OpenRouter adapter](https://github.com/thepushkarp/etymology-explorer/blob/main/lib/openrouterResponses.ts): `lib/openrouterResponses.ts`

### Caching and safeguards

- [Result and audio cache](https://github.com/thepushkarp/etymology-explorer/blob/main/lib/cache.ts): `lib/cache.ts`
- [Redis service](https://github.com/thepushkarp/etymology-explorer/blob/main/lib/redis.ts): `lib/redis.ts`
- [Spend controls](https://github.com/thepushkarp/etymology-explorer/blob/main/lib/costGuard.ts): `lib/costGuard.ts`

### Discovery and audio

- [Suggestions endpoint](https://github.com/thepushkarp/etymology-explorer/blob/main/app/api/suggestions/route.ts): `app/api/suggestions/route.ts`
- [Suggestion ranking](https://github.com/thepushkarp/etymology-explorer/blob/main/lib/wordSuggestions.ts): `lib/wordSuggestions.ts`
- [Random word endpoint](https://github.com/thepushkarp/etymology-explorer/blob/main/app/api/random-word/route.ts): `app/api/random-word/route.ts`
- [Pronunciation endpoint](https://github.com/thepushkarp/etymology-explorer/blob/main/app/api/pronunciation/route.ts): `app/api/pronunciation/route.ts`
- [Speech generation](https://github.com/thepushkarp/etymology-explorer/blob/main/lib/elevenlabs.ts): `lib/elevenlabs.ts`
- [N-gram endpoint](https://github.com/thepushkarp/etymology-explorer/blob/main/app/api/ngram/route.ts): `app/api/ngram/route.ts`
- [N-gram lookup](https://github.com/thepushkarp/etymology-explorer/blob/main/lib/ngrams.ts): `lib/ngrams.ts`

### Other components

- **Visitor**
- **Dictionary and reference sources**
- **OpenRouter**
- **ElevenLabs**

## Connections

- Visitor → Word search: searches
- Visitor → Word page: opens word
- Word search → Suggestions endpoint: requests suggestions (evidence: `components/SearchBox.tsx`)
- Word page → Result and audio cache: reads cached entry (evidence: `app/word/[...segments]/page.tsx`)
- Word page → Entry display: renders cached result (evidence: `app/word/[...segments]/page.tsx`)
- Word page → Live trace: renders live trace (evidence: `app/word/[...segments]/page.tsx`)
- Live trace → Etymology endpoint: streams lookup
- Etymology endpoint → Result and audio cache: checks and stores (evidence: `app/api/etymology/route.ts`)
- Etymology endpoint → Source research: runs research (evidence: `app/api/etymology/route.ts`)
- Etymology endpoint → LLM synthesis: requests synthesis (evidence: `app/api/etymology/route.ts`)
- Source research → Source clients: fetches evidence (evidence: `lib/research.ts`)
- Source research → Etymology parsing: parses source text (evidence: `lib/research.ts`)
- Source research → OpenRouter adapter: extracts roots (evidence: `lib/research.ts`)
- LLM synthesis → Source research: uses research context (evidence: `lib/llm.ts`)
- LLM synthesis → OpenRouter adapter: requests completion (evidence: `lib/llm.ts`)
- OpenRouter adapter → OpenRouter: calls API (evidence: `lib/openrouterResponses.ts`)
- Source clients → Dictionary and reference sources: fetches reference data
- Result and audio cache → Redis service: reads and writes (evidence: `lib/cache.ts`)
- Spend controls → Redis service: tracks spend (evidence: `lib/costGuard.ts`)
- Admin usage stats → Spend controls: reads budget (evidence: `app/api/admin/stats/route.ts`)
- Admin usage stats → Redis service: reads counters (evidence: `app/api/admin/stats/route.ts`)
- Suggestions endpoint → Suggestion ranking: gets suggestions (evidence: `app/api/suggestions/route.ts`)
- Random word endpoint → Dictionary and reference sources: selects word list
- Pronunciation endpoint → Result and audio cache: checks and stores audio (evidence: `app/api/pronunciation/route.ts`)
- Pronunciation endpoint → Speech generation: requests audio (evidence: `app/api/pronunciation/route.ts`)
- Speech generation → ElevenLabs: generates speech
- N-gram endpoint → N-gram lookup: requests frequency (evidence: `app/api/ngram/route.ts`)
