# fmtlib/fmt architecture

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

- Interactive diagram: https://gitdiagram.com/fmtlib/fmt
- Repository: https://github.com/fmtlib/fmt

## Overview

{fmt} is a C++ formatting library. The principal workflow accepts a format string and typed arguments, formats them into output, and either returns the result or writes it to a destination. Extensions cover compile-time formatting, printf compatibility, chrono and range formatting, Unicode character types, colors, and standard-library types; OS and stream adapters provide additional output paths. The graph reflects README-described usage and SOURCE INDEX references; unsampled implementation details are not inferred.

Main entry points: [`include/fmt/format.h`](https://github.com/fmtlib/fmt/blob/main/include/fmt/format.h) (Format engine), [`src/fmt.cc`](https://github.com/fmtlib/fmt/blob/main/src/fmt.cc) (C++ module), [`include/fmt/os.h`](https://github.com/fmtlib/fmt/blob/main/include/fmt/os.h) (OS file API), [`include/fmt/core.h`](https://github.com/fmtlib/fmt/blob/main/include/fmt/core.h) (Core API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Formatting core"]
  node_api["Core API<br/>[core.h]"]
  node_engine["Format engine<br/>[format.h]"]
  node_implementation["Format internals<br/>[format-inl.h]"]
  node_arguments["Argument store<br/>[args.h]"]
end

subgraph group_extensions["Formatting extensions"]
  node_compiled["Compiled formats<br/>[compile.h]"]
  node_printf["Printf compatibility<br/>[printf.h]"]
  node_chrono["Chrono formatting<br/>[chrono.h]"]
  node_ranges["Ranges and tuples<br/>[ranges.h]"]
  node_unicode["Unicode formats<br/>[xchar.h]"]
  node_colors["Color and styles<br/>[color.h]"]
  node_enums["Enum formatting<br/>[enum.h]"]
  node_stdtypes["Standard types<br/>[std.h]"]
end

subgraph group_outputs["Output adapters"]
  node_ostream["Stream adapter<br/>[ostream.h]"]
  node_osapi["OS file API<br/>[os.h]"]
  node_capi["C API<br/>[fmt-c.h]"]
end

subgraph group_runtime["Compiled runtime"]
  node_osruntime["OS implementation<br/>[os.cc]"]
  node_module["C++ module<br/>[fmt.cc]"]
end

node_user(("C++ caller"))
node_result["Formatted output"]

node_user -->|"calls"| node_api
node_api -->|"formats with"| node_engine
node_engine -->|"uses"| node_implementation
node_engine -->|"returns or writes"| node_result
node_user -->|"compiles formats"| node_compiled
node_user -->|"uses printf API"| node_printf
node_user -->|"formats dates"| node_chrono
node_user -->|"formats containers"| node_ranges
node_user -->|"uses character types"| node_unicode
node_user -->|"prints styled text"| node_colors
node_user -.->|"formats enums"| node_enums
node_user -.->|"formats standard types"| node_stdtypes
node_user -.->|"uses stream adapter"| node_ostream
node_user -->|"writes files"| node_osapi
node_osapi -->|"implemented by"| node_osruntime
node_user -.->|"uses C interface"| node_capi
node_module -->|"includes"| node_engine
node_module -->|"includes"| node_chrono
node_module -->|"includes"| node_colors
node_module -->|"includes"| node_compiled
node_module -->|"includes"| node_osapi
node_engine -->|"includes"| node_api
node_arguments -->|"supports arguments"| node_engine
node_compiled -->|"uses"| node_engine
node_printf -->|"uses"| node_engine
node_chrono -->|"uses"| node_engine
node_ranges -->|"uses"| node_engine
node_colors -->|"uses"| node_engine
node_ostream -->|"formats through"| node_engine
node_osapi -->|"formats through"| node_engine

click node_api "https://github.com/fmtlib/fmt/blob/main/include/fmt/core.h"
click node_engine "https://github.com/fmtlib/fmt/blob/main/include/fmt/format.h"
click node_implementation "https://github.com/fmtlib/fmt/blob/main/include/fmt/format-inl.h"
click node_arguments "https://github.com/fmtlib/fmt/blob/main/include/fmt/args.h"
click node_compiled "https://github.com/fmtlib/fmt/blob/main/include/fmt/compile.h"
click node_printf "https://github.com/fmtlib/fmt/blob/main/include/fmt/printf.h"
click node_chrono "https://github.com/fmtlib/fmt/blob/main/include/fmt/chrono.h"
click node_ranges "https://github.com/fmtlib/fmt/blob/main/include/fmt/ranges.h"
click node_unicode "https://github.com/fmtlib/fmt/blob/main/include/fmt/xchar.h"
click node_colors "https://github.com/fmtlib/fmt/blob/main/include/fmt/color.h"
click node_enums "https://github.com/fmtlib/fmt/blob/main/include/fmt/enum.h"
click node_stdtypes "https://github.com/fmtlib/fmt/blob/main/include/fmt/std.h"
click node_ostream "https://github.com/fmtlib/fmt/blob/main/include/fmt/ostream.h"
click node_osapi "https://github.com/fmtlib/fmt/blob/main/include/fmt/os.h"
click node_capi "https://github.com/fmtlib/fmt/blob/main/include/fmt/fmt-c.h"
click node_osruntime "https://github.com/fmtlib/fmt/blob/main/src/os.cc"
click node_module "https://github.com/fmtlib/fmt/blob/main/src/fmt.cc"

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_api,node_engine,node_implementation,node_arguments toneBlue
class node_compiled,node_printf,node_chrono,node_ranges,node_unicode,node_colors,node_enums,node_stdtypes toneAmber
class node_ostream,node_osapi,node_capi toneMint
class node_osruntime,node_module toneRose
class node_user,node_result toneIndigo
```

## Components

### Formatting core

- [Core API](https://github.com/fmtlib/fmt/blob/main/include/fmt/core.h): `include/fmt/core.h`
- [Format engine](https://github.com/fmtlib/fmt/blob/main/include/fmt/format.h): `include/fmt/format.h`
- [Format internals](https://github.com/fmtlib/fmt/blob/main/include/fmt/format-inl.h): `include/fmt/format-inl.h`
- [Argument store](https://github.com/fmtlib/fmt/blob/main/include/fmt/args.h): `include/fmt/args.h`

### Formatting extensions

- [Compiled formats](https://github.com/fmtlib/fmt/blob/main/include/fmt/compile.h): `include/fmt/compile.h`
- [Printf compatibility](https://github.com/fmtlib/fmt/blob/main/include/fmt/printf.h): `include/fmt/printf.h`
- [Chrono formatting](https://github.com/fmtlib/fmt/blob/main/include/fmt/chrono.h): `include/fmt/chrono.h`
- [Ranges and tuples](https://github.com/fmtlib/fmt/blob/main/include/fmt/ranges.h): `include/fmt/ranges.h`
- [Unicode formats](https://github.com/fmtlib/fmt/blob/main/include/fmt/xchar.h): `include/fmt/xchar.h`
- [Color and styles](https://github.com/fmtlib/fmt/blob/main/include/fmt/color.h): `include/fmt/color.h`
- [Enum formatting](https://github.com/fmtlib/fmt/blob/main/include/fmt/enum.h): `include/fmt/enum.h`
- [Standard types](https://github.com/fmtlib/fmt/blob/main/include/fmt/std.h): `include/fmt/std.h`

### Output adapters

- [Stream adapter](https://github.com/fmtlib/fmt/blob/main/include/fmt/ostream.h): `include/fmt/ostream.h`
- [OS file API](https://github.com/fmtlib/fmt/blob/main/include/fmt/os.h): `include/fmt/os.h`
- [C API](https://github.com/fmtlib/fmt/blob/main/include/fmt/fmt-c.h): `include/fmt/fmt-c.h`

### Compiled runtime

- [OS implementation](https://github.com/fmtlib/fmt/blob/main/src/os.cc): `src/os.cc`
- [C++ module](https://github.com/fmtlib/fmt/blob/main/src/fmt.cc): `src/fmt.cc`

### Other components

- **C++ caller**
- **Formatted output**

## Connections

- C++ caller → Core API: calls (evidence: `README.md`)
- Core API → Format engine: formats with (evidence: `include/fmt/core.h`)
- Format engine → Format internals: uses (evidence: `include/fmt/format.h`)
- Format engine → Formatted output: returns or writes (evidence: `README.md`)
- C++ caller → Compiled formats: compiles formats (evidence: `README.md`)
- C++ caller → Printf compatibility: uses printf API (evidence: `README.md`)
- C++ caller → Chrono formatting: formats dates (evidence: `README.md`)
- C++ caller → Ranges and tuples: formats containers (evidence: `README.md`)
- C++ caller → Unicode formats: uses character types (evidence: `include/fmt/xchar.h`)
- C++ caller → Color and styles: prints styled text (evidence: `README.md`)
- C++ caller → Enum formatting: formats enums
- C++ caller → Standard types: formats standard types
- C++ caller → Stream adapter: uses stream adapter
- C++ caller → OS file API: writes files (evidence: `README.md`)
- OS file API → OS implementation: implemented by (evidence: `src/os.cc`)
- C++ caller → C API: uses C interface
- C++ module → Format engine: includes (evidence: `src/fmt.cc`)
- C++ module → Chrono formatting: includes (evidence: `src/fmt.cc`)
- C++ module → Color and styles: includes (evidence: `src/fmt.cc`)
- C++ module → Compiled formats: includes (evidence: `src/fmt.cc`)
- C++ module → OS file API: includes (evidence: `src/fmt.cc`)
- Format engine → Core API: includes (evidence: `include/fmt/format.h`)
- Argument store → Format engine: supports arguments (evidence: `include/fmt/args.h`)
- Compiled formats → Format engine: uses (evidence: `include/fmt/compile.h`)
- Printf compatibility → Format engine: uses (evidence: `include/fmt/printf.h`)
- Chrono formatting → Format engine: uses (evidence: `include/fmt/chrono.h`)
- Ranges and tuples → Format engine: uses (evidence: `include/fmt/ranges.h`)
- Color and styles → Format engine: uses (evidence: `include/fmt/color.h`)
- Stream adapter → Format engine: formats through (evidence: `include/fmt/ostream.h`)
- OS file API → Format engine: formats through (evidence: `include/fmt/os.h`)
