# atomicmemory/llm-wiki-compiler architecture

> Architecture diagram of the GitHub repository atomicmemory/llm-wiki-compiler, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/atomicmemory/llm-wiki-compiler
- Repository: https://github.com/atomicmemory/llm-wiki-compiler

## Overview

1. **What this repo is**
   - `llmwiki` is a Node.js/TypeScript CLI that turns raw inputs in `sources/` into a persistent markdown wiki in `wiki/`.
   - The architectural center is a compile pipeline, not a live retrieval service: sources are ingested, compiled, queried, and optionally fed back into the wiki.

2. **Top-level execution model**
   - `src/cli.ts` is the entrypoint, and `src/commands/*` contains the user-facing verbs: `ingest`, `compile`, `query`, `lint`, and `watch`.
   - Each command is a thin orchestration layer over shared compiler, provider, and utility modules.

3. **Input boundary: source ingestion**
   - `src/ingest/file.ts` and `src/ingest/web.ts` form the boundary where external content enters the system.
   - Ingested artifacts are normalized into local source files, with the README noting truncation metadata for oversized inputs so downstream compilation knows content may be partial.

4. **Core pipeline: two-phase compilation**
   - The compiler lives under `src/compiler/*` and follows a two-phase flow described in the README:
     - Phase 1: extract concepts from all changed sources.
     - Phase 2: generate wiki pages from the merged concept set.
   - This design removes order dependence and allows shared concepts from multiple sources to converge into one page.

5. **Change detection and incremental rebuilds**
   - `src/compiler/hasher.ts` and `src/compiler/deps.ts` support incremental compilation by detecting which sources changed and what downstream pages depend on them.
   - `src/utils/state.ts` likely stores compile state between runs, while `src/utils/lock.ts` suggests the repo prevents concurrent compiles or writes.
   - The result is that only changed sources re-enter the LLM-backed part of the pipeline.

6. **Concept extraction, resolution, and page generation**
   - `src/compiler/prompts.ts` holds the LLM prompts used for extraction and page synthesis.
   - `src/compiler/resolver.ts` and `src/compiler/obsidian.ts` handle wiki-style linking and Obsidian-compatible page structure.
   - `src/compiler/orphan.ts` indicates the system also tracks unlinked or unused pages, which feeds the lint/health model.

7. **Indexing and navigation output**
   - `src/compiler/indexgen.ts` generates the wiki index page.
   - Output is organized as `wiki/concepts/`, `wiki/queries/`, and `wiki/index.md`, making the compiled artifact browsable as static markdown.
   - The README’s `[[wikilink]]` behavior is part of this output boundary: generated pages are meant to be traversed as an interlinked knowledge base.

8. **Query subsystem and compounding knowledge**
   - `src/commands/query.ts` routes questions against the compiled wiki, rather than querying raw sources directly.
   - `--save` turns an answer into a new markdown page, which immediately becomes part of the next compile/index pass.
   - This creates a feedback loop: query answers are not ephemeral; they become new durable knowledge in `wiki/queries/`.

9. **Linting and quality checks**
   - `src/linter/*` implements repository-specific health checks such as broken links, empty pages, and orphans.
   - This is a separate validation pass over the compiled wiki, not part of ingestion or query execution.

10. **LLM provider boundary**
   - `src/utils/provider.ts` plus `src/providers/anthropic.ts`, `openai.ts`, and `ollama.ts` abstract model backends.
   - The README says Anthropic is the primary supported path today, but the codebase is already shaped around a provider interface, which keeps the compiler decoupled from any single vendor.

11. **Shared utilities and I/O concerns**
   - `src/utils/markdown.ts`, `output.ts`, `constants.ts`, and `types.ts` hold common formatting, terminal output, and shared domain types.
   - `src/utils/llm.ts` is the likely shared call layer for prompt execution and response handling.

12. **Watch mode and automation**
   - `src/commands/watch.ts` wraps the same compile pipeline in filesystem-triggered automation, rebuilding when `sources/` changes.
   - This is not a separate build system; it is a convenience loop around the same incremental compiler.

13. **Repository shape and verification**
   - `examples/basic/` contains a pre-generated wiki that demonstrates the artifact structure without requiring API access.
   - `test/*` is broad and architecture-revealing: there are tests for hashing, resolver behavior, index generation, provider compatibility, ingest truncation, linting, and query save flows.
   - That test spread mirrors the main boundaries of the system: ingestion, compilation, linking, query/save, and validation.

Main entry points: [`src/compiler/index.ts`](https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/compiler/index.ts) (Compiler core), [`src/utils/provider.ts`](https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/utils/provider.ts) (Provider API), [`src/cli.ts`](https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/cli.ts) (CLI entry), [`src/commands/ingest.ts`](https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/commands/ingest.ts) (Ingest)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g1["CLI"]
  node_n1["CLI entry<br/>entrypoint<br/>[cli.ts]"]
  node_n2["Ingest<br/>command<br/>[ingest.ts]"]
  node_n3["Compile<br/>command<br/>[compile.ts]"]
  node_n4["Query<br/>command<br/>[query.ts]"]
  node_n5["Lint<br/>command<br/>[lint.ts]"]
  node_n6["Watch<br/>command<br/>[watch.ts]"]
end

subgraph group_g2["Pipeline"]
  node_n7["File ingest<br/>source import<br/>[file.ts]"]
  node_n8["Web ingest<br/>source import<br/>[web.ts]"]
  node_n9["Compiler core<br/>pipeline<br/>[index.ts]"]
  node_n10{{"Hasher<br/>incremental<br/>[hasher.ts]"}}
  node_n11{{"Deps<br/>dependency graph<br/>[deps.ts]"}}
  node_n12["Prompts<br/>[prompts.ts]"]
  node_n13["Resolver<br/>linking<br/>[resolver.ts]"]
  node_n14["Obsidian<br/>wiki format<br/>[obsidian.ts]"]
  node_n15["Index generator<br/>navigation<br/>[indexgen.ts]"]
  node_n16{{"Orphans<br/>health<br/>[orphan.ts]"}}
end

subgraph group_g3["Model I/O"]
  node_n17["Provider API<br/>adapter<br/>[provider.ts]"]
  node_n18["Anthropic<br/>provider<br/>[anthropic.ts]"]
  node_n19["OpenAI<br/>provider<br/>[openai.ts]"]
  node_n20["Ollama<br/>provider<br/>[ollama.ts]"]
  node_n21["LLM client<br/>call layer<br/>[llm.ts]"]
end

subgraph group_g4["Validation"]
  node_n22["Linter core<br/>validation<br/>[index.ts]"]
  node_n23["Lint rules<br/>[rules.ts]"]
end

subgraph group_g5["Shared"]
  node_n24["Markdown<br/>formatting<br/>[markdown.ts]"]
  node_n25[("State<br/>persistence<br/>[state.ts]")]
  node_n26{{"Lock<br/>concurrency<br/>[lock.ts]"}}
  node_n27["Output<br/>terminal I/O<br/>[output.ts]"]
  node_n28["Types<br/>[types.ts]"]
  node_n29["Constants<br/>config values<br/>[constants.ts]"]
end

node_n1 -->|"dispatches"| node_n2
node_n1 -->|"dispatches"| node_n3
node_n1 -->|"dispatches"| node_n4
node_n1 -->|"dispatches"| node_n5
node_n1 -->|"dispatches"| node_n6
node_n2 -->|"uses"| node_n7
node_n2 -->|"uses"| node_n8
node_n3 -->|"runs"| node_n9
node_n4 -->|"queries"| node_n9
node_n5 -->|"runs"| node_n22
node_n6 -->|"loops"| node_n9
node_n9 -->|"detects changes"| node_n10
node_n9 -->|"tracks deps"| node_n11
node_n9 -->|"prompts"| node_n12
node_n9 -->|"resolves links"| node_n13
node_n9 -->|"writes pages"| node_n14
node_n9 -->|"builds index"| node_n15
node_n9 -->|"reports orphans"| node_n16
node_n9 -->|"calls model API"| node_n17
node_n17 -->|"implements"| node_n18
node_n17 -->|"implements"| node_n19
node_n17 -->|"implements"| node_n20
node_n17 -->|"delegates"| node_n21
node_n22 -->|"applies"| node_n23
node_n4 -.->|"reads index"| node_n15
node_n3 -->|"persists state"| node_n25
node_n9 -->|"serializes"| node_n26
node_n14 -->|"formats"| node_n24
node_n15 -->|"formats"| node_n24
node_n2 -->|"reports"| node_n27
node_n3 -->|"reports"| node_n27
node_n4 -->|"reports"| node_n27
node_n22 -->|"reports"| node_n27
node_n9 -->|"shares types"| node_n28
node_n17 -->|"uses"| node_n29

click node_n1 "https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/cli.ts"
click node_n2 "https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/commands/ingest.ts"
click node_n3 "https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/commands/compile.ts"
click node_n4 "https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/commands/query.ts"
click node_n5 "https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/commands/lint.ts"
click node_n6 "https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/commands/watch.ts"
click node_n7 "https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/ingest/file.ts"
click node_n8 "https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/ingest/web.ts"
click node_n9 "https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/compiler/index.ts"
click node_n10 "https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/compiler/hasher.ts"
click node_n11 "https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/compiler/deps.ts"
click node_n12 "https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/compiler/prompts.ts"
click node_n13 "https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/compiler/resolver.ts"
click node_n14 "https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/compiler/obsidian.ts"
click node_n15 "https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/compiler/indexgen.ts"
click node_n16 "https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/compiler/orphan.ts"
click node_n17 "https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/utils/provider.ts"
click node_n18 "https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/providers/anthropic.ts"
click node_n19 "https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/providers/openai.ts"
click node_n20 "https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/providers/ollama.ts"
click node_n21 "https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/utils/llm.ts"
click node_n22 "https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/linter/index.ts"
click node_n23 "https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/linter/rules.ts"
click node_n24 "https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/utils/markdown.ts"
click node_n25 "https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/utils/state.ts"
click node_n26 "https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/utils/lock.ts"
click node_n27 "https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/utils/output.ts"
click node_n28 "https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/utils/types.ts"
click node_n29 "https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/utils/constants.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_n1,node_n2,node_n3,node_n4,node_n5,node_n6 toneBlue
class node_n7,node_n8,node_n9,node_n10,node_n11,node_n12,node_n13,node_n14,node_n15,node_n16 toneAmber
class node_n17,node_n18,node_n19,node_n20,node_n21 toneMint
class node_n22,node_n23 toneRose
class node_n24,node_n25,node_n26,node_n27,node_n28,node_n29 toneIndigo
```

## Components

### CLI

User-facing command entrypoints and orchestration.

- [CLI entry](https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/cli.ts): entrypoint · Main executable that dispatches subcommands. · `src/cli.ts`
- [Ingest](https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/commands/ingest.ts): command · Imports external content into local source files. · `src/commands/ingest.ts`
- [Compile](https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/commands/compile.ts): command · Runs the two-phase wiki compilation pipeline. · `src/commands/compile.ts`
- [Query](https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/commands/query.ts): command · Answers questions from the compiled wiki and can save results. · `src/commands/query.ts`
- [Lint](https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/commands/lint.ts): command · Checks compiled wiki health and consistency. · `src/commands/lint.ts`
- [Watch](https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/commands/watch.ts): command · Rebuilds automatically when sources change. · `src/commands/watch.ts`

### Pipeline

Core ingest and compile flow that turns sources into wiki pages.

- [File ingest](https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/ingest/file.ts): source import · Normalizes local file inputs into repository sources. · `src/ingest/file.ts`
- [Web ingest](https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/ingest/web.ts): source import · Fetches and normalizes web content into local sources. · `src/ingest/web.ts`
- [Compiler core](https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/compiler/index.ts): pipeline · Coordinates incremental compilation across the repository. · `src/compiler/index.ts`
- [Hasher](https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/compiler/hasher.ts): incremental · Detects changed sources for selective recompilation. · `src/compiler/hasher.ts`
- [Deps](https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/compiler/deps.ts): dependency graph · Tracks downstream page dependencies for rebuilds. · `src/compiler/deps.ts`
- [Prompts](https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/compiler/prompts.ts): llm prompts · Defines extraction and page-generation prompts. · `src/compiler/prompts.ts`
- [Resolver](https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/compiler/resolver.ts): linking · Resolves concepts and wiki links across pages. · `src/compiler/resolver.ts`
- [Obsidian](https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/compiler/obsidian.ts): wiki format · Builds Obsidian-compatible page structure and links. · `src/compiler/obsidian.ts`
- [Index generator](https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/compiler/indexgen.ts): navigation · Creates the wiki index page for browseable output. · `src/compiler/indexgen.ts`
- [Orphans](https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/compiler/orphan.ts): health · Identifies unlinked or unused wiki pages. · `src/compiler/orphan.ts`

### Model I/O

LLM provider abstraction and shared request handling.

- [Provider API](https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/utils/provider.ts): adapter · Abstracts model backends behind a common interface. · `src/utils/provider.ts`
- [Anthropic](https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/providers/anthropic.ts): provider · Primary model backend implementation. · `src/providers/anthropic.ts`
- [OpenAI](https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/providers/openai.ts): provider · OpenAI backend implementation. · `src/providers/openai.ts`
- [Ollama](https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/providers/ollama.ts): provider · Local model backend implementation. · `src/providers/ollama.ts`
- [LLM client](https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/utils/llm.ts): call layer · Shared request and response handling for model calls. · `src/utils/llm.ts`

### Validation

Wiki health checks and repository-specific linting.

- [Linter core](https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/linter/index.ts): validation · Runs repository-specific wiki checks. · `src/linter/index.ts`
- [Lint rules](https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/linter/rules.ts): rules · Implements checks for links, empty pages, and orphans. · `src/linter/rules.ts`

### Shared

Cross-cutting utilities used by the commands and compiler.

- [Markdown](https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/utils/markdown.ts): formatting · Shared markdown formatting and page helpers. · `src/utils/markdown.ts`
- [State](https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/utils/state.ts): persistence · Stores incremental compile state between runs. · `src/utils/state.ts`
- [Lock](https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/utils/lock.ts): concurrency · Prevents overlapping compiles or writes. · `src/utils/lock.ts`
- [Output](https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/utils/output.ts): terminal I/O · Centralized user-facing output and status messages. · `src/utils/output.ts`
- [Types](https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/utils/types.ts): shared types · Common domain types across the toolchain. · `src/utils/types.ts`
- [Constants](https://github.com/atomicmemory/llm-wiki-compiler/blob/main/src/utils/constants.ts): config values · Shared constants used throughout the repository. · `src/utils/constants.ts`

## Connections

- CLI entry → Ingest: dispatches · CLI routes to ingest commands.
- CLI entry → Compile: dispatches · CLI routes to compile commands.
- CLI entry → Query: dispatches · CLI routes to query commands.
- CLI entry → Lint: dispatches · CLI routes to lint commands.
- CLI entry → Watch: dispatches · CLI routes to watch commands.
- Ingest → File ingest: uses · File ingestion handles local inputs.
- Ingest → Web ingest: uses · Web ingestion handles remote inputs.
- Compile → Compiler core: runs · Compile command invokes the compiler pipeline.
- Query → Compiler core: queries · Query reads from compiled wiki outputs.
- Lint → Linter core: runs · Lint command invokes validation checks.
- Watch → Compiler core: loops · Watch mode repeatedly triggers compilation.
- Compiler core → Hasher: detects changes · Compiler uses hashing to find changed sources.
- Compiler core → Deps: tracks deps · Compiler uses dependency information for rebuilds.
- Compiler core → Prompts: prompts · Compiler uses prompt templates for extraction and synthesis.
- Compiler core → Resolver: resolves links · Compiler normalizes concepts and links.
- Compiler core → Obsidian: writes pages · Compiler emits wiki-compatible markdown pages.
- Compiler core → Index generator: builds index · Compiler generates the wiki index page.
- Compiler core → Orphans: reports orphans · Compiler tracks unused or unlinked pages.
- Compiler core → Provider API: calls model API · Compiler delegates model access through the provider abstraction.
- Provider API → Anthropic: implements · Anthropic is a provider backend.
- Provider API → OpenAI: implements · OpenAI is a provider backend.
- Provider API → Ollama: implements · Ollama is a provider backend.
- Provider API → LLM client: delegates · Provider calls are executed through the shared LLM client.
- Linter core → Lint rules: applies · Linter core runs the rule set.
- Query → Index generator: reads index · Query can use the browsable wiki index as part of the compiled corpus.
- Compile → State: persists state · Compilation writes and reads incremental state.
- Compiler core → Lock: serializes · Compiler uses a lock to prevent concurrent runs.
- Obsidian → Markdown: formats · Wiki page generation relies on markdown helpers.
- Index generator → Markdown: formats · Index generation relies on markdown helpers.
- Ingest → Output: reports · Ingest commands surface status through shared output.
- Compile → Output: reports · Compile commands surface status through shared output.
- Query → Output: reports · Query commands surface status through shared output.
- Linter core → Output: reports · Lint commands surface status through shared output.
- Compiler core → Types: shares types · Compiler components use shared domain types.
- Provider API → Constants: uses · Provider and pipeline code share constants.
