# elstongun/leviathan architecture

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

- Interactive diagram: https://gitdiagram.com/elstongun/leviathan
- Repository: https://github.com/elstongun/leviathan

## Overview

Leviathan maps and indexes records into a SQLite/FTS5 file, then returns compact, cited results through its CLI or optional MCP server. The main workflow is data discovery and mapping, ingestion, indexed retrieval, card construction, and rendering. Other documented capabilities include mapping inference, record updates, browsing and lookup commands, and agent-specific MCP configuration snippets. Edges are limited to relationships visible in excerpts or explicitly documented in the README; unsampled CLI internals are not inferred.

Main entry points: [`src/main.rs`](https://github.com/elstongun/leviathan/blob/main/src/main.rs) (Command-line app), [`src/index.rs`](https://github.com/elstongun/leviathan/blob/main/src/index.rs) (Index and updates), [`src/query.rs`](https://github.com/elstongun/leviathan/blob/main/src/query.rs) (Search and lookup), [`src/card.rs`](https://github.com/elstongun/leviathan/blob/main/src/card.rs) (Result cards)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Mapping and ingestion"]
  node_mapping["Field configuration<br/>[config.rs]"]
  node_inference["Mapping inference<br/>[infer.rs]"]
  node_sources["Record readers<br/>[source.rs]"]
  node_fields["Field mapping<br/>[fields.rs]"]
  node_indexer["Index and updates<br/>[index.rs]"]
  node_store[("SQLite FTS5 index")]
end

subgraph group_retrieval["Search and results"]
  node_query["Search and lookup<br/>[query.rs]"]
  node_cards["Result cards<br/>[card.rs]"]
  node_render["Text rendering<br/>[render.rs]"]
end

subgraph group_interfaces["Agent interfaces"]
  node_cli["Command-line app<br/>[main.rs]"]
  node_mcp["MCP server<br/>[mcp.rs]"]
  node_wrap["Agent config snippets<br/>[wrap.rs]"]
end

subgraph group_internals["Shared text layer"]
  node_text["Text utilities<br/>[text.rs]"]
end

node_user(("Agent or user"))

node_user -->|"runs commands"| node_cli
node_cli -->|"infers mappings"| node_inference
node_cli -->|"builds or updates"| node_indexer
node_cli -->|"requests results"| node_query
node_cli -->|"starts server"| node_mcp
node_cli -->|"prints setup"| node_wrap
node_inference -->|"profiles records"| node_sources
node_inference -->|"proposes mapping"| node_mapping
node_indexer -->|"reads records"| node_sources
node_indexer -->|"uses mapping"| node_mapping
node_indexer -->|"maps records"| node_fields
node_indexer -->|"writes index"| node_store
node_query -->|"searches index"| node_store
node_query -->|"builds results"| node_cards
node_render -->|"renders cards"| node_cards
node_mcp -->|"serves queries"| node_query
node_mcp -->|"formats responses"| node_render
node_wrap -->|"configures launch"| node_mcp
node_fields -->|"normalizes values"| node_text
node_cards -->|"extracts display fields"| node_fields
node_cards -->|"truncates snippets"| node_text

click node_cli "https://github.com/elstongun/leviathan/blob/main/src/main.rs"
click node_mapping "https://github.com/elstongun/leviathan/blob/main/src/config.rs"
click node_inference "https://github.com/elstongun/leviathan/blob/main/src/infer.rs"
click node_sources "https://github.com/elstongun/leviathan/blob/main/src/source.rs"
click node_fields "https://github.com/elstongun/leviathan/blob/main/src/fields.rs"
click node_indexer "https://github.com/elstongun/leviathan/blob/main/src/index.rs"
click node_query "https://github.com/elstongun/leviathan/blob/main/src/query.rs"
click node_cards "https://github.com/elstongun/leviathan/blob/main/src/card.rs"
click node_render "https://github.com/elstongun/leviathan/blob/main/src/render.rs"
click node_mcp "https://github.com/elstongun/leviathan/blob/main/src/mcp.rs"
click node_wrap "https://github.com/elstongun/leviathan/blob/main/src/wrap.rs"
click node_text "https://github.com/elstongun/leviathan/blob/main/src/text.rs"

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_mapping,node_inference,node_sources,node_fields,node_indexer,node_store,node_user toneBlue
class node_query,node_cards,node_render toneAmber
class node_cli,node_mcp,node_wrap toneMint
class node_text toneRose
```

## Components

### Mapping and ingestion

- [Field configuration](https://github.com/elstongun/leviathan/blob/main/src/config.rs): `src/config.rs`
- [Mapping inference](https://github.com/elstongun/leviathan/blob/main/src/infer.rs): `src/infer.rs`
- [Record readers](https://github.com/elstongun/leviathan/blob/main/src/source.rs): `src/source.rs`
- [Field mapping](https://github.com/elstongun/leviathan/blob/main/src/fields.rs): `src/fields.rs`
- [Index and updates](https://github.com/elstongun/leviathan/blob/main/src/index.rs): `src/index.rs`
- **SQLite FTS5 index**

### Search and results

- [Search and lookup](https://github.com/elstongun/leviathan/blob/main/src/query.rs): `src/query.rs`
- [Result cards](https://github.com/elstongun/leviathan/blob/main/src/card.rs): `src/card.rs`
- [Text rendering](https://github.com/elstongun/leviathan/blob/main/src/render.rs): `src/render.rs`

### Agent interfaces

- [Command-line app](https://github.com/elstongun/leviathan/blob/main/src/main.rs): `src/main.rs`
- [MCP server](https://github.com/elstongun/leviathan/blob/main/src/mcp.rs): `src/mcp.rs`
- [Agent config snippets](https://github.com/elstongun/leviathan/blob/main/src/wrap.rs): `src/wrap.rs`

### Shared text layer

- [Text utilities](https://github.com/elstongun/leviathan/blob/main/src/text.rs): `src/text.rs`

### Other components

- **Agent or user**

## Connections

- Agent or user → Command-line app: runs commands (evidence: `README.md`)
- Command-line app → Mapping inference: infers mappings (evidence: `README.md`)
- Command-line app → Index and updates: builds or updates (evidence: `README.md`)
- Command-line app → Search and lookup: requests results (evidence: `README.md`)
- Command-line app → MCP server: starts server (evidence: `README.md`)
- Command-line app → Agent config snippets: prints setup (evidence: `README.md`)
- Mapping inference → Record readers: profiles records (evidence: `src/infer.rs`)
- Mapping inference → Field configuration: proposes mapping (evidence: `src/infer.rs`)
- Index and updates → Record readers: reads records (evidence: `src/index.rs`)
- Index and updates → Field configuration: uses mapping (evidence: `src/index.rs`)
- Index and updates → Field mapping: maps records (evidence: `src/index.rs`)
- Index and updates → SQLite FTS5 index: writes index (evidence: `README.md`)
- Search and lookup → SQLite FTS5 index: searches index (evidence: `README.md`)
- Search and lookup → Result cards: builds results (evidence: `src/query.rs`)
- Text rendering → Result cards: renders cards (evidence: `src/render.rs`)
- MCP server → Search and lookup: serves queries (evidence: `src/mcp.rs`)
- MCP server → Text rendering: formats responses (evidence: `src/mcp.rs`)
- Agent config snippets → MCP server: configures launch (evidence: `src/wrap.rs`)
- Field mapping → Text utilities: normalizes values (evidence: `src/fields.rs`)
- Result cards → Field mapping: extracts display fields (evidence: `src/card.rs`)
- Result cards → Text utilities: truncates snippets (evidence: `src/card.rs`)
