# nahuel990/baldanders architecture

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

- Interactive diagram: https://gitdiagram.com/nahuel990/baldanders
- Repository: https://github.com/nahuel990/baldanders

## Overview

Baldanders is a local privacy firewall for LLM conversations and standalone text scrubbing. A user starts a chat or scrub command; the CLI loads configuration, detects sensitive spans locally, replaces them with session tokens, and sends only sanitized conversation content through a selected provider. Replies are streamed or returned, then tokens are restored locally. Optional model download enables offline name and address detection; encrypted session history supports resuming. The graph follows documented behavior and source-index references; some CLI orchestration details are only partially excerpted.

Main entry points: [`src/baldanders/cli.py`](https://github.com/nahuel990/baldanders/blob/main/src/baldanders/cli.py) (CLI workflow), [`src/baldanders/providers/base.py`](https://github.com/nahuel990/baldanders/blob/main/src/baldanders/providers/base.py) (Provider interface), [`src/baldanders/scrubber/engine.py`](https://github.com/nahuel990/baldanders/blob/main/src/baldanders/scrubber/engine.py) (Scrub orchestration), [`src/baldanders/history.py`](https://github.com/nahuel990/baldanders/blob/main/src/baldanders/history.py) (Session history)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interaction["CLI and interaction"]
  node_cli["CLI workflow<br/>[cli.py]"]
  node_ui["Terminal UI<br/>[ui.py]"]
  node_config["User configuration<br/>[config.py]"]
end

subgraph group_protection["Local data protection"]
  node_engine["Scrub orchestration<br/>[engine.py]"]
  node_regex["Deterministic detection<br/>[regex.py]"]
  node_ner["Name/address detection<br/>[ner.py]"]
  node_model["Model cache/download<br/>[model_manager.py]"]
  node_mapping["Token mapping<br/>[mapping.py]"]
end

subgraph group_providers["LLM providers"]
  node_provider_base["Provider interface<br/>[base.py]"]
  node_claude["Claude Code provider<br/>[claude_code.py]"]
  node_codex["Codex provider<br/>[codex.py]"]
  node_grok["Grok provider<br/>[grok.py]"]
  node_anthropic["Anthropic API provider<br/>[anthropic.py]"]
  node_openai["OpenAI-compatible provider<br/>[openai.py]"]
end

subgraph group_persistence["Local state"]
  node_history[("Session history<br/>[history.py]")]
  node_vault["Encryption vault<br/>[vault.py]"]
end

node_user(("User"))
node_external_llm{{"Provider tools and APIs"}}

node_user -->|"starts workflow"| node_cli
node_cli -->|"reads and displays"| node_ui
node_cli -->|"loads settings"| node_config
node_cli -->|"scrubs input"| node_engine
node_engine -->|"detects patterns"| node_regex
node_engine -->|"detects entities"| node_ner
node_engine -->|"creates tokens"| node_mapping
node_engine -->|"uses rules"| node_config
node_ner -->|"uses spans"| node_regex
node_cli -->|"restores reply tokens"| node_mapping
node_cli -->|"dispatches request"| node_provider_base
node_provider_base -->|"implements interface"| node_claude
node_provider_base -->|"implements interface"| node_codex
node_provider_base -->|"implements interface"| node_grok
node_provider_base -->|"implements interface"| node_anthropic
node_provider_base -->|"implements interface"| node_openai
node_claude -->|"runs via CLI"| node_external_llm
node_codex -->|"runs via CLI"| node_external_llm
node_grok -->|"calls provider"| node_external_llm
node_anthropic -->|"calls provider"| node_external_llm
node_openai -->|"calls compatible API"| node_external_llm
node_cli -->|"loads and saves sessions"| node_history
node_history -->|"stores token map"| node_mapping
node_history -->|"encrypts session data"| node_vault
node_cli -->|"downloads model"| node_model
node_model -.->|"provides offline model"| node_ner

click node_cli "https://github.com/nahuel990/baldanders/blob/main/src/baldanders/cli.py"
click node_ui "https://github.com/nahuel990/baldanders/blob/main/src/baldanders/ui.py"
click node_config "https://github.com/nahuel990/baldanders/blob/main/src/baldanders/config.py"
click node_engine "https://github.com/nahuel990/baldanders/blob/main/src/baldanders/scrubber/engine.py"
click node_regex "https://github.com/nahuel990/baldanders/blob/main/src/baldanders/scrubber/regex.py"
click node_ner "https://github.com/nahuel990/baldanders/blob/main/src/baldanders/scrubber/ner.py"
click node_model "https://github.com/nahuel990/baldanders/blob/main/src/baldanders/model_manager.py"
click node_mapping "https://github.com/nahuel990/baldanders/blob/main/src/baldanders/mapping.py"
click node_provider_base "https://github.com/nahuel990/baldanders/blob/main/src/baldanders/providers/base.py"
click node_claude "https://github.com/nahuel990/baldanders/blob/main/src/baldanders/providers/claude_code.py"
click node_codex "https://github.com/nahuel990/baldanders/blob/main/src/baldanders/providers/codex.py"
click node_grok "https://github.com/nahuel990/baldanders/blob/main/src/baldanders/providers/grok.py"
click node_anthropic "https://github.com/nahuel990/baldanders/blob/main/src/baldanders/providers/anthropic.py"
click node_openai "https://github.com/nahuel990/baldanders/blob/main/src/baldanders/providers/openai.py"
click node_history "https://github.com/nahuel990/baldanders/blob/main/src/baldanders/history.py"
click node_vault "https://github.com/nahuel990/baldanders/blob/main/src/baldanders/vault.py"

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_cli,node_ui,node_config,node_user toneBlue
class node_engine,node_regex,node_ner,node_model,node_mapping toneAmber
class node_provider_base,node_claude,node_codex,node_grok,node_anthropic,node_openai,node_external_llm toneMint
class node_history,node_vault toneRose
```

## Components

### CLI and interaction

- [CLI workflow](https://github.com/nahuel990/baldanders/blob/main/src/baldanders/cli.py): `src/baldanders/cli.py`
- [Terminal UI](https://github.com/nahuel990/baldanders/blob/main/src/baldanders/ui.py): `src/baldanders/ui.py`
- [User configuration](https://github.com/nahuel990/baldanders/blob/main/src/baldanders/config.py): `src/baldanders/config.py`

### Local data protection

- [Scrub orchestration](https://github.com/nahuel990/baldanders/blob/main/src/baldanders/scrubber/engine.py): `src/baldanders/scrubber/engine.py`
- [Deterministic detection](https://github.com/nahuel990/baldanders/blob/main/src/baldanders/scrubber/regex.py): `src/baldanders/scrubber/regex.py`
- [Name/address detection](https://github.com/nahuel990/baldanders/blob/main/src/baldanders/scrubber/ner.py): `src/baldanders/scrubber/ner.py`
- [Model cache/download](https://github.com/nahuel990/baldanders/blob/main/src/baldanders/model_manager.py): `src/baldanders/model_manager.py`
- [Token mapping](https://github.com/nahuel990/baldanders/blob/main/src/baldanders/mapping.py): `src/baldanders/mapping.py`

### LLM providers

- [Provider interface](https://github.com/nahuel990/baldanders/blob/main/src/baldanders/providers/base.py): `src/baldanders/providers/base.py`
- [Claude Code provider](https://github.com/nahuel990/baldanders/blob/main/src/baldanders/providers/claude_code.py): `src/baldanders/providers/claude_code.py`
- [Codex provider](https://github.com/nahuel990/baldanders/blob/main/src/baldanders/providers/codex.py): `src/baldanders/providers/codex.py`
- [Grok provider](https://github.com/nahuel990/baldanders/blob/main/src/baldanders/providers/grok.py): `src/baldanders/providers/grok.py`
- [Anthropic API provider](https://github.com/nahuel990/baldanders/blob/main/src/baldanders/providers/anthropic.py): `src/baldanders/providers/anthropic.py`
- [OpenAI-compatible provider](https://github.com/nahuel990/baldanders/blob/main/src/baldanders/providers/openai.py): `src/baldanders/providers/openai.py`

### Local state

- [Session history](https://github.com/nahuel990/baldanders/blob/main/src/baldanders/history.py): `src/baldanders/history.py`
- [Encryption vault](https://github.com/nahuel990/baldanders/blob/main/src/baldanders/vault.py): `src/baldanders/vault.py`

### Other components

- **User**
- **Provider tools and APIs**

## Connections

- User → CLI workflow: starts workflow (evidence: `README.md`)
- CLI workflow → Terminal UI: reads and displays (evidence: `src/baldanders/cli.py`)
- CLI workflow → User configuration: loads settings (evidence: `src/baldanders/cli.py`)
- CLI workflow → Scrub orchestration: scrubs input (evidence: `src/baldanders/cli.py`)
- Scrub orchestration → Deterministic detection: detects patterns (evidence: `src/baldanders/scrubber/engine.py`)
- Scrub orchestration → Name/address detection: detects entities (evidence: `src/baldanders/scrubber/engine.py`)
- Scrub orchestration → Token mapping: creates tokens (evidence: `src/baldanders/scrubber/engine.py`)
- Scrub orchestration → User configuration: uses rules (evidence: `src/baldanders/scrubber/engine.py`)
- Name/address detection → Deterministic detection: uses spans (evidence: `src/baldanders/scrubber/ner.py`)
- CLI workflow → Token mapping: restores reply tokens (evidence: `src/baldanders/cli.py`)
- CLI workflow → Provider interface: dispatches request (evidence: `src/baldanders/cli.py`)
- Provider interface → Claude Code provider: implements interface (evidence: `src/baldanders/providers/claude_code.py`)
- Provider interface → Codex provider: implements interface (evidence: `src/baldanders/providers/codex.py`)
- Provider interface → Grok provider: implements interface (evidence: `src/baldanders/providers/grok.py`)
- Provider interface → Anthropic API provider: implements interface (evidence: `src/baldanders/providers/anthropic.py`)
- Provider interface → OpenAI-compatible provider: implements interface (evidence: `src/baldanders/providers/openai.py`)
- Claude Code provider → Provider tools and APIs: runs via CLI (evidence: `README.md`)
- Codex provider → Provider tools and APIs: runs via CLI (evidence: `README.md`)
- Grok provider → Provider tools and APIs: calls provider (evidence: `README.md`)
- Anthropic API provider → Provider tools and APIs: calls provider (evidence: `README.md`)
- OpenAI-compatible provider → Provider tools and APIs: calls compatible API (evidence: `README.md`)
- CLI workflow → Session history: loads and saves sessions (evidence: `src/baldanders/cli.py`)
- Session history → Token mapping: stores token map (evidence: `src/baldanders/history.py`)
- Session history → Encryption vault: encrypts session data (evidence: `src/baldanders/history.py`)
- CLI workflow → Model cache/download: downloads model (evidence: `README.md`)
- Model cache/download → Name/address detection: provides offline model
