# nvbn/thefuck architecture

> Architecture diagram of the GitHub repository nvbn/thefuck, 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/nvbn/thefuck
- Repository: https://github.com/nvbn/thefuck

## Overview

The Fuck is a command-line assistant that diagnoses a failed previous shell command, proposes rule-based corrections, and optionally runs a selected correction. The main path runs from shell alias or CLI invocation through argument and history handling, command construction, correction matching, interactive selection, and execution. Shell-specific adapters, configurable settings, output readers, and logging support that workflow. The README documents broad rule coverage and confirmation/repeat options; individual rule implementations are not sampled, so their internal matching details are not expanded here.

Main entry points: [`thefuck/entrypoints/fix_command.py`](https://github.com/nvbn/thefuck/blob/master/thefuck/entrypoints/fix_command.py) (Fix command), [`thefuck/entrypoints/main.py`](https://github.com/nvbn/thefuck/blob/master/thefuck/entrypoints/main.py) (Command dispatcher), [`thefuck/conf.py`](https://github.com/nvbn/thefuck/blob/master/thefuck/conf.py) (Settings), [`thefuck/types.py`](https://github.com/nvbn/thefuck/blob/master/thefuck/types.py) (Command model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["CLI and shell entry"]
  node_launcher["CLI launcher<br/>[fastentrypoints.py]"]
  node_main["Command dispatcher<br/>[main.py]"]
  node_parser["Argument parser<br/>[argument_parser.py]"]
  node_alias["Alias generation<br/>[alias.py]"]
  node_shell_logger["Shell logger<br/>[shell_logger.py]"]
end

subgraph group_correction["Correction workflow"]
  node_fix["Fix command<br/>[fix_command.py]"]
  node_command["Command model<br/>[types.py]"]
  node_corrector["Correction engine<br/>[corrector.py]"]
  node_ui["Command selection<br/>[ui.py]"]
  node_output_readers["Output readers"]
end

subgraph group_rules["Rules and configuration"]
  node_rules["Correction rules"]
  node_settings["Settings<br/>[conf.py]"]
  node_constants["Runtime constants<br/>[const.py]"]
  node_logs["Logging and feedback<br/>[logs.py]"]
end

subgraph group_platform["Shell and platform support"]
  node_shell_adapters["Shell adapters"]
  node_system["OS interface"]
  node_utilities["Shared utilities<br/>[utils.py]"]
  node_exceptions["Runtime exceptions<br/>[exceptions.py]"]
end

node_user(("Shell user"))

node_user -->|"invokes"| node_launcher
node_launcher -.->|"starts"| node_main
node_main -->|"parses arguments"| node_parser
node_main -->|"requests alias"| node_alias
node_main -->|"dispatches fixes"| node_fix
node_main -->|"dispatches logging"| node_shell_logger
node_alias -->|"formats shell alias"| node_shell_adapters
node_fix -->|"initializes"| node_settings
node_fix -->|"builds command"| node_command
node_fix -->|"requests candidates"| node_corrector
node_corrector -->|"matches rules"| node_rules
node_corrector -->|"uses command model"| node_command
node_fix -->|"selects candidate"| node_ui
node_ui -.->|"runs selected command"| node_command
node_command -->|"reads command output"| node_output_readers
node_fix -->|"handles empty command"| node_exceptions
node_parser -->|"uses placeholder"| node_constants
node_settings -->|"loads defaults"| node_constants
node_settings -->|"uses platform paths"| node_system
node_fix -->|"reports workflow"| node_logs
node_output_readers -->|"reports read failures"| node_logs
node_shell_adapters -->|"uses shell settings"| node_settings
node_shell_adapters -->|"uses shared helpers"| node_utilities
node_utilities -->|"uses platform paths"| node_system
node_shell_logger -->|"logs shell output"| node_logs
node_fix -->|"finds history executables"| node_utilities

click node_launcher "https://github.com/nvbn/thefuck/blob/master/fastentrypoints.py"
click node_main "https://github.com/nvbn/thefuck/blob/master/thefuck/entrypoints/main.py"
click node_parser "https://github.com/nvbn/thefuck/blob/master/thefuck/argument_parser.py"
click node_alias "https://github.com/nvbn/thefuck/blob/master/thefuck/entrypoints/alias.py"
click node_shell_logger "https://github.com/nvbn/thefuck/blob/master/thefuck/entrypoints/shell_logger.py"
click node_fix "https://github.com/nvbn/thefuck/blob/master/thefuck/entrypoints/fix_command.py"
click node_command "https://github.com/nvbn/thefuck/blob/master/thefuck/types.py"
click node_corrector "https://github.com/nvbn/thefuck/blob/master/thefuck/corrector.py"
click node_rules "https://github.com/nvbn/thefuck/tree/master/thefuck/rules"
click node_ui "https://github.com/nvbn/thefuck/blob/master/thefuck/ui.py"
click node_output_readers "https://github.com/nvbn/thefuck/tree/master/thefuck/output_readers"
click node_settings "https://github.com/nvbn/thefuck/blob/master/thefuck/conf.py"
click node_constants "https://github.com/nvbn/thefuck/blob/master/thefuck/const.py"
click node_logs "https://github.com/nvbn/thefuck/blob/master/thefuck/logs.py"
click node_shell_adapters "https://github.com/nvbn/thefuck/tree/master/thefuck/shells"
click node_system "https://github.com/nvbn/thefuck/tree/master/thefuck/system"
click node_utilities "https://github.com/nvbn/thefuck/blob/master/thefuck/utils.py"
click node_exceptions "https://github.com/nvbn/thefuck/blob/master/thefuck/exceptions.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_launcher,node_main,node_parser,node_alias,node_shell_logger,node_user toneBlue
class node_fix,node_command,node_corrector,node_ui,node_output_readers toneAmber
class node_rules,node_settings,node_constants,node_logs toneMint
class node_shell_adapters,node_system,node_utilities,node_exceptions toneRose
```

## Components

### CLI and shell entry

- [CLI launcher](https://github.com/nvbn/thefuck/blob/master/fastentrypoints.py): `fastentrypoints.py`
- [Command dispatcher](https://github.com/nvbn/thefuck/blob/master/thefuck/entrypoints/main.py): `thefuck/entrypoints/main.py`
- [Argument parser](https://github.com/nvbn/thefuck/blob/master/thefuck/argument_parser.py): `thefuck/argument_parser.py`
- [Alias generation](https://github.com/nvbn/thefuck/blob/master/thefuck/entrypoints/alias.py): `thefuck/entrypoints/alias.py`
- [Shell logger](https://github.com/nvbn/thefuck/blob/master/thefuck/entrypoints/shell_logger.py): `thefuck/entrypoints/shell_logger.py`

### Correction workflow

- [Fix command](https://github.com/nvbn/thefuck/blob/master/thefuck/entrypoints/fix_command.py): `thefuck/entrypoints/fix_command.py`
- [Command model](https://github.com/nvbn/thefuck/blob/master/thefuck/types.py): `thefuck/types.py`
- [Correction engine](https://github.com/nvbn/thefuck/blob/master/thefuck/corrector.py): `thefuck/corrector.py`
- [Command selection](https://github.com/nvbn/thefuck/blob/master/thefuck/ui.py): `thefuck/ui.py`
- [Output readers](https://github.com/nvbn/thefuck/tree/master/thefuck/output_readers): `thefuck/output_readers`

### Rules and configuration

- [Correction rules](https://github.com/nvbn/thefuck/tree/master/thefuck/rules): `thefuck/rules`
- [Settings](https://github.com/nvbn/thefuck/blob/master/thefuck/conf.py): `thefuck/conf.py`
- [Runtime constants](https://github.com/nvbn/thefuck/blob/master/thefuck/const.py): `thefuck/const.py`
- [Logging and feedback](https://github.com/nvbn/thefuck/blob/master/thefuck/logs.py): `thefuck/logs.py`

### Shell and platform support

- [Shell adapters](https://github.com/nvbn/thefuck/tree/master/thefuck/shells): `thefuck/shells`
- [OS interface](https://github.com/nvbn/thefuck/tree/master/thefuck/system): `thefuck/system`
- [Shared utilities](https://github.com/nvbn/thefuck/blob/master/thefuck/utils.py): `thefuck/utils.py`
- [Runtime exceptions](https://github.com/nvbn/thefuck/blob/master/thefuck/exceptions.py): `thefuck/exceptions.py`

### Other components

- **Shell user**

## Connections

- Shell user → CLI launcher: invokes (evidence: `README.md`)
- CLI launcher → Command dispatcher: starts
- Command dispatcher → Argument parser: parses arguments (evidence: `thefuck/entrypoints/main.py`)
- Command dispatcher → Alias generation: requests alias (evidence: `thefuck/entrypoints/main.py`)
- Command dispatcher → Fix command: dispatches fixes (evidence: `thefuck/entrypoints/main.py`)
- Command dispatcher → Shell logger: dispatches logging (evidence: `thefuck/entrypoints/main.py`)
- Alias generation → Shell adapters: formats shell alias (evidence: `thefuck/entrypoints/alias.py`)
- Fix command → Settings: initializes (evidence: `thefuck/entrypoints/fix_command.py`)
- Fix command → Command model: builds command (evidence: `thefuck/entrypoints/fix_command.py`)
- Fix command → Correction engine: requests candidates (evidence: `thefuck/entrypoints/fix_command.py`)
- Correction engine → Correction rules: matches rules (evidence: `README.md`)
- Correction engine → Command model: uses command model (evidence: `thefuck/corrector.py`)
- Fix command → Command selection: selects candidate (evidence: `thefuck/entrypoints/fix_command.py`)
- Command selection → Command model: runs selected command
- Command model → Output readers: reads command output (evidence: `thefuck/types.py`)
- Fix command → Runtime exceptions: handles empty command (evidence: `thefuck/entrypoints/fix_command.py`)
- Argument parser → Runtime constants: uses placeholder (evidence: `thefuck/argument_parser.py`)
- Settings → Runtime constants: loads defaults (evidence: `thefuck/conf.py`)
- Settings → OS interface: uses platform paths (evidence: `thefuck/conf.py`)
- Fix command → Logging and feedback: reports workflow (evidence: `thefuck/entrypoints/fix_command.py`)
- Output readers → Logging and feedback: reports read failures (evidence: `thefuck/output_readers/read_log.py`)
- Shell adapters → Settings: uses shell settings (evidence: `thefuck/shells/fish.py`)
- Shell adapters → Shared utilities: uses shared helpers (evidence: `thefuck/shells/fish.py`)
- Shared utilities → OS interface: uses platform paths (evidence: `thefuck/utils.py`)
- Shell logger → Logging and feedback: logs shell output (evidence: `thefuck/entrypoints/shell_logger.py`)
- Fix command → Shared utilities: finds history executables (evidence: `thefuck/entrypoints/fix_command.py`)
