# `LlmCore.Config.Loader`
[🔗](https://github.com/fosferon/llm_core/blob/v0.3.0/lib/llm_core/config/loader.ex#L1)

Loads llm_core configuration files (routing, providers, etc.) from disk and updates the store.

Handles the full TOML loading pipeline: reading multiple config layers, deep-merging,
resolving environment variable placeholders, normalizing provider definitions, and
broadcasting change notifications to dependent processes.

## Configuration Layers (later overrides earlier)

1. **Compiled defaults** — `priv/config/llm_core.toml` (bundled with the library)
2. **Global override** — `~/.llm_core/config/llm_core.toml`
3. **Project override** — `<project>/.llm_core/llm_core.toml`
4. **Environment variable** — path in `LLM_CORE_CONFIG`
5. **Custom path** — explicit `:path` option

## Environment Variable Interpolation

TOML values like `"${ANTHROPIC_API_KEY}"` are resolved at load time.
Supports defaults: `"${OLLAMA_URL:http://localhost:11434}"`.

## Key Functions

  * `reload_providers/1` — Full TOML load + provider normalization + store update
  * `reload_routing/1` — Load and apply routing rules only
  * `load_config/1` — Read merged TOML without mutating runtime state

# `load_config`

```elixir
@spec load_config(keyword()) :: {:ok, map()}
```

Returns the merged TOML configuration without mutating runtime state.

# `load_routing`

```elixir
@spec load_routing(keyword()) ::
  {:ok, LlmCore.Router.RoutingTable.t()} | {:error, term()}
```

Loads the routing configuration from disk without mutating the store.

# `reload_providers`

```elixir
@spec reload_providers(keyword()) ::
  {:ok, %{optional(String.t()) =&gt; LlmCore.Provider.Definition.t()}}
  | {:error, term()}
```

Loads TOML configuration (providers, memory, routing defaults) and writes
the normalized provider metadata to the runtime store.

# `reload_routing`

```elixir
@spec reload_routing(keyword()) ::
  {:ok, LlmCore.Router.RoutingTable.t()} | {:error, term()}
```

Loads the routing configuration and writes it to the runtime store.
Broadcasts change notifications so dependent processes can refresh.

When `routing.yml` is missing, the existing Store routing is preserved
(e.g. a table already installed from TOML via `reload_providers/1`). Only
when the Store has no routing at all does the safe `default => claude`
fallback get installed.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
