# unjs/defu architecture

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

- Interactive diagram: https://gitdiagram.com/unjs/defu
- Repository: https://github.com/unjs/defu
- Video tour (about a minute): https://gitdiagram.com/unjs/defu/video

## Overview

defu is a small TypeScript library for recursively applying defaults to objects. The main workflow accepts a destination and one or more defaults, then returns a merged object; custom merger hooks and function-based variants alter how individual values are handled. Runtime merging and its plain-object check are visible in the sampled source. The README documents the public variants, while the type model is a separate compile-time capability. No external services or persistent state are involved.

Main entry points: [`src/defu.ts`](https://github.com/unjs/defu/blob/main/src/defu.ts) (Merge APIs), [`src/_utils.ts`](https://github.com/unjs/defu/blob/main/src/_utils.ts) (Plain-object check), [`src/types.ts`](https://github.com/unjs/defu/blob/main/src/types.ts) (Merge type model)

## Diagram (Mermaid)

```mermaid
flowchart TD

node_caller(("Library consumer"))
node_merge["Merge APIs<br/>[defu.ts]"]
node_plaincheck["Plain-object check<br/>[_utils.ts]"]
node_typemodel["Merge type model<br/>[types.ts]"]

node_caller -->|"calls"| node_merge
node_merge -->|"checks objects"| node_plaincheck
node_merge -->|"exports types"| node_typemodel

click node_merge "https://github.com/unjs/defu/blob/main/src/defu.ts"
click node_plaincheck "https://github.com/unjs/defu/blob/main/src/_utils.ts"
click node_typemodel "https://github.com/unjs/defu/blob/main/src/types.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_caller,node_typemodel toneIndigo
class node_merge toneMint
class node_plaincheck toneTeal
```

## Components

### Other components

- **Library consumer**
- [Merge APIs](https://github.com/unjs/defu/blob/main/src/defu.ts): `src/defu.ts`
- [Plain-object check](https://github.com/unjs/defu/blob/main/src/_utils.ts): `src/_utils.ts`
- [Merge type model](https://github.com/unjs/defu/blob/main/src/types.ts): `src/types.ts`

## Connections

- Library consumer → Merge APIs: calls (evidence: `README.md`)
- Merge APIs → Plain-object check: checks objects (evidence: `src/defu.ts`)
- Merge APIs → Merge type model: exports types (evidence: `src/defu.ts`)
