# urfave/cli architecture

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

- Interactive diagram: https://gitdiagram.com/urfave/cli
- Repository: https://github.com/urfave/cli

## Overview

urfave/cli is a Go library for building declarative command-line applications. An application author defines commands, arguments, and typed flags; a caller runs the command, which parses input, selects commands, and invokes application actions. The package also provides help, shell completion, and flag-value sources, with documentation generation exposed as a capability. The main execution handoffs are only partly visible in the excerpts, so unverified links are dashed; documented capabilities are retained without asserting unsampled call paths.

Main entry points: [`command_run.go`](https://github.com/urfave/cli/blob/main/command_run.go) (Run command), [`flag.go`](https://github.com/urfave/cli/blob/main/flag.go) (Flag definitions), [`help.go`](https://github.com/urfave/cli/blob/main/help.go) (Help output), [`command.go`](https://github.com/urfave/cli/blob/main/command.go) (Command model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_execution["Command execution"]
  node_runner["Run command<br/>[command_run.go]"]
  node_commandmodel["Command model<br/>[command.go]"]
  node_setup["Command setup<br/>[command_setup.go]"]
  node_parser["Flag parser<br/>[command_parse.go]"]
  node_dispatch["Command dispatch<br/>[command_run.go]"]
end

subgraph group_inputs["Inputs and flags"]
  node_arguments["Positional arguments<br/>[args.go]"]
  node_flagapi["Flag definitions<br/>[flag.go]"]
  node_flagvalues["Typed flag values<br/>[flag_impl.go]"]
  node_boolflags["Inverse boolean flags"]
  node_value_sources["Value sources<br/>[value_source.go]"]
end

subgraph group_interfaces["User-facing features"]
  node_help["Help output<br/>[help.go]"]
  node_help_templates["Help rendering<br/>[help_template.go]"]
  node_help_plain["Plain help rendering<br/>[help_notemplate.go]"]
  node_completion["Shell completion<br/>[completion.go]"]
  node_fish["Fish completion<br/>[fish.go]"]
  node_docs["Docs generation<br/>[docs.go]"]
end

node_author(("Application author"))
node_action(("Application action"))

node_author -->|"defines commands"| node_commandmodel
node_author -->|"runs"| node_runner
node_runner -.->|"initializes"| node_setup
node_runner -.->|"parses input"| node_parser
node_runner -.->|"dispatches commands"| node_dispatch
node_dispatch -.->|"invokes action"| node_action
node_runner -.->|"provides arguments"| node_arguments
node_parser -.->|"sets flags"| node_flagapi
node_flagapi -.->|"uses values"| node_flagvalues
node_flagapi -.->|"supports boolean flags"| node_boolflags
node_flagvalues -.->|"reads fallback values"| node_value_sources
node_runner -.->|"shows help"| node_help
node_help -.->|"renders templates"| node_help_templates
node_help -.->|"renders without templates"| node_help_plain
node_runner -.->|"supports completion"| node_completion
node_completion -.->|"supports Fish"| node_fish
node_commandmodel -.->|"exposes doc generation"| node_docs

click node_runner "https://github.com/urfave/cli/blob/main/command_run.go"
click node_commandmodel "https://github.com/urfave/cli/blob/main/command.go"
click node_setup "https://github.com/urfave/cli/blob/main/command_setup.go"
click node_parser "https://github.com/urfave/cli/blob/main/command_parse.go"
click node_dispatch "https://github.com/urfave/cli/blob/main/command_run.go"
click node_arguments "https://github.com/urfave/cli/blob/main/args.go"
click node_flagapi "https://github.com/urfave/cli/blob/main/flag.go"
click node_flagvalues "https://github.com/urfave/cli/blob/main/flag_impl.go"
click node_boolflags "https://github.com/urfave/cli/blob/main/flag_bool_with_inverse.go"
click node_value_sources "https://github.com/urfave/cli/blob/main/value_source.go"
click node_help "https://github.com/urfave/cli/blob/main/help.go"
click node_help_templates "https://github.com/urfave/cli/blob/main/help_template.go"
click node_help_plain "https://github.com/urfave/cli/blob/main/help_notemplate.go"
click node_completion "https://github.com/urfave/cli/blob/main/completion.go"
click node_fish "https://github.com/urfave/cli/blob/main/fish.go"
click node_docs "https://github.com/urfave/cli/blob/main/docs.go"

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_runner,node_commandmodel,node_setup,node_parser,node_dispatch toneBlue
class node_arguments,node_flagapi,node_flagvalues,node_boolflags,node_value_sources toneAmber
class node_help,node_help_templates,node_help_plain,node_completion,node_fish,node_docs toneMint
class node_author,node_action toneIndigo
```

## Components

### Command execution

- [Run command](https://github.com/urfave/cli/blob/main/command_run.go): `command_run.go`
- [Command model](https://github.com/urfave/cli/blob/main/command.go): `command.go`
- [Command setup](https://github.com/urfave/cli/blob/main/command_setup.go): `command_setup.go`
- [Flag parser](https://github.com/urfave/cli/blob/main/command_parse.go): `command_parse.go`
- [Command dispatch](https://github.com/urfave/cli/blob/main/command_run.go): `command_run.go`

### Inputs and flags

- [Positional arguments](https://github.com/urfave/cli/blob/main/args.go): `args.go`
- [Flag definitions](https://github.com/urfave/cli/blob/main/flag.go): `flag.go`
- [Typed flag values](https://github.com/urfave/cli/blob/main/flag_impl.go): `flag_impl.go`
- [Inverse boolean flags](https://github.com/urfave/cli/blob/main/flag_bool_with_inverse.go): `flag_bool_with_inverse.go`
- [Value sources](https://github.com/urfave/cli/blob/main/value_source.go): `value_source.go`

### User-facing features

- [Help output](https://github.com/urfave/cli/blob/main/help.go): `help.go`
- [Help rendering](https://github.com/urfave/cli/blob/main/help_template.go): `help_template.go`
- [Plain help rendering](https://github.com/urfave/cli/blob/main/help_notemplate.go): `help_notemplate.go`
- [Shell completion](https://github.com/urfave/cli/blob/main/completion.go): `completion.go`
- [Fish completion](https://github.com/urfave/cli/blob/main/fish.go): `fish.go`
- [Docs generation](https://github.com/urfave/cli/blob/main/docs.go): `docs.go`

### Other components

- **Application author**
- **Application action**

## Connections

- Application author → Command model: defines commands (evidence: `README.md`)
- Application author → Run command: runs (evidence: `README.md`)
- Run command → Command setup: initializes
- Run command → Flag parser: parses input
- Run command → Command dispatch: dispatches commands (evidence: `command_run.go`)
- Command dispatch → Application action: invokes action
- Run command → Positional arguments: provides arguments
- Flag parser → Flag definitions: sets flags
- Flag definitions → Typed flag values: uses values
- Flag definitions → Inverse boolean flags: supports boolean flags
- Typed flag values → Value sources: reads fallback values
- Run command → Help output: shows help
- Help output → Help rendering: renders templates
- Help output → Plain help rendering: renders without templates
- Run command → Shell completion: supports completion
- Shell completion → Fish completion: supports Fish
- Command model → Docs generation: exposes doc generation
