# pkhienko/minishell architecture

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

- Interactive diagram: https://gitdiagram.com/pkhienko/minishell
- Repository: https://github.com/pkhienko/minishell

## Overview

Minishell is an interactive Unix shell: it reads a line, tokenizes and validates shell syntax, expands variables, builds piped command records, then executes built-ins or external programs with redirection and exit-status handling. The README also documents prompt history, environment mutation, heredocs, and signal handling. The main loop and executor excerpts establish the central calls; broader feature links use README evidence because their implementation files were not sampled.

Main entry points: [`sources/shell/main.c`](https://github.com/pkhienko/minishell/blob/master/sources/shell/main.c) (Shell loop), [`sources/executor/execution.c`](https://github.com/pkhienko/minishell/blob/master/sources/executor/execution.c) (Executor), [`sources/init/built_cmd.c`](https://github.com/pkhienko/minishell/blob/master/sources/init/built_cmd.c) (Command builder), [`libft/include/libft.h`](https://github.com/pkhienko/minishell/blob/master/libft/include/libft.h) (C utility library)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interaction["Interactive shell"]
  node_readline["Readline"]
  node_loop["Shell loop<br/>[main.c]"]
  node_prompt["Prompt<br/>[prompt.c]"]
  node_signals["Signal handling<br/>[signal.c]"]
end

subgraph group_language["Input processing"]
  node_lexer["Lexer and parser"]
  node_builder["Command builder<br/>[built_cmd.c]"]
  node_command_model["Command records<br/>[command.h]"]
end

subgraph group_execution["Command execution"]
  node_executor["Executor<br/>[execution.c]"]
  node_io["Pipes and redirects<br/>[io_file.c]"]
  node_heredoc["Heredoc input<br/>[heredoc.c]"]
  node_builtins["Built-in commands"]
  node_external["External programs"]
  node_errors["Command errors"]
end

subgraph group_state["Shell state"]
  node_environment[("Environment")]
  node_libft["C utility library<br/>[libft.h]"]
  node_printf["Formatted output<br/>[ft_printf.c]"]
  node_gnl["Line reader<br/>[get_next_line.c]"]
end

node_user(("Shell user"))

node_user -->|"enters input"| node_readline
node_readline -->|"provides lines"| node_loop
node_loop -->|"gets prompt"| node_prompt
node_loop -->|"tokenizes input"| node_lexer
node_loop -->|"builds commands"| node_builder
node_loop -->|"executes commands"| node_executor
node_lexer -->|"expands variables"| node_environment
node_builder -->|"creates records"| node_command_model
node_builder -->|"creates pipe fds"| node_io
node_executor -->|"dispatches built-ins"| node_builtins
node_executor -->|"executes programs"| node_external
node_executor -->|"sets and restores"| node_io
node_executor -->|"checks heredoc status"| node_heredoc
node_builtins -->|"updates variables"| node_environment
node_loop -->|"handles interrupts"| node_signals
node_executor -->|"reports failures"| node_errors
node_libft -->|"provides implementation"| node_printf
node_libft -->|"provides implementation"| node_gnl

click node_loop "https://github.com/pkhienko/minishell/blob/master/sources/shell/main.c"
click node_prompt "https://github.com/pkhienko/minishell/blob/master/sources/shell/prompt.c"
click node_signals "https://github.com/pkhienko/minishell/blob/master/sources/signal/signal.c"
click node_lexer "https://github.com/pkhienko/minishell/tree/master/sources/lexer"
click node_builder "https://github.com/pkhienko/minishell/blob/master/sources/init/built_cmd.c"
click node_command_model "https://github.com/pkhienko/minishell/blob/master/include/command.h"
click node_executor "https://github.com/pkhienko/minishell/blob/master/sources/executor/execution.c"
click node_io "https://github.com/pkhienko/minishell/blob/master/sources/io_file/io_file.c"
click node_heredoc "https://github.com/pkhienko/minishell/blob/master/sources/executor/heredoc.c"
click node_builtins "https://github.com/pkhienko/minishell/tree/master/sources/builtins"
click node_errors "https://github.com/pkhienko/minishell/tree/master/sources/error"
click node_environment "https://github.com/pkhienko/minishell/tree/master/sources/env"
click node_libft "https://github.com/pkhienko/minishell/blob/master/libft/include/libft.h"
click node_printf "https://github.com/pkhienko/minishell/blob/master/libft/src/printf/ft_printf.c"
click node_gnl "https://github.com/pkhienko/minishell/blob/master/libft/src/get_next_line/get_next_line.c"

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_readline,node_loop,node_prompt,node_signals,node_user toneBlue
class node_lexer,node_builder,node_command_model toneAmber
class node_executor,node_io,node_heredoc,node_builtins,node_external,node_errors toneMint
class node_environment,node_libft,node_printf,node_gnl toneRose
```

## Components

### Interactive shell

- **Readline**
- [Shell loop](https://github.com/pkhienko/minishell/blob/master/sources/shell/main.c): `sources/shell/main.c`
- [Prompt](https://github.com/pkhienko/minishell/blob/master/sources/shell/prompt.c): `sources/shell/prompt.c`
- [Signal handling](https://github.com/pkhienko/minishell/blob/master/sources/signal/signal.c): `sources/signal/signal.c`

### Input processing

- [Lexer and parser](https://github.com/pkhienko/minishell/tree/master/sources/lexer): `sources/lexer`
- [Command builder](https://github.com/pkhienko/minishell/blob/master/sources/init/built_cmd.c): `sources/init/built_cmd.c`
- [Command records](https://github.com/pkhienko/minishell/blob/master/include/command.h): `include/command.h`

### Command execution

- [Executor](https://github.com/pkhienko/minishell/blob/master/sources/executor/execution.c): `sources/executor/execution.c`
- [Pipes and redirects](https://github.com/pkhienko/minishell/blob/master/sources/io_file/io_file.c): `sources/io_file/io_file.c`
- [Heredoc input](https://github.com/pkhienko/minishell/blob/master/sources/executor/heredoc.c): `sources/executor/heredoc.c`
- [Built-in commands](https://github.com/pkhienko/minishell/tree/master/sources/builtins): `sources/builtins`
- **External programs**
- [Command errors](https://github.com/pkhienko/minishell/tree/master/sources/error): `sources/error`

### Shell state

- [Environment](https://github.com/pkhienko/minishell/tree/master/sources/env): `sources/env`
- [C utility library](https://github.com/pkhienko/minishell/blob/master/libft/include/libft.h): `libft/include/libft.h`
- [Formatted output](https://github.com/pkhienko/minishell/blob/master/libft/src/printf/ft_printf.c): `libft/src/printf/ft_printf.c`
- [Line reader](https://github.com/pkhienko/minishell/blob/master/libft/src/get_next_line/get_next_line.c): `libft/src/get_next_line/get_next_line.c`

### Other components

- **Shell user**

## Connections

- Shell user → Readline: enters input
- Readline → Shell loop: provides lines
- Shell loop → Prompt: gets prompt (evidence: `sources/shell/main.c`)
- Shell loop → Lexer and parser: tokenizes input (evidence: `sources/shell/main.c`)
- Shell loop → Command builder: builds commands (evidence: `sources/shell/main.c`)
- Shell loop → Executor: executes commands (evidence: `sources/shell/main.c`)
- Lexer and parser → Environment: expands variables
- Command builder → Command records: creates records (evidence: `sources/init/built_cmd.c`)
- Command builder → Pipes and redirects: creates pipe fds (evidence: `sources/init/built_cmd.c`)
- Executor → Built-in commands: dispatches built-ins (evidence: `sources/executor/execution.c`)
- Executor → External programs: executes programs (evidence: `sources/executor/execution.c`)
- Executor → Pipes and redirects: sets and restores (evidence: `sources/executor/execution.c`)
- Executor → Heredoc input: checks heredoc status (evidence: `sources/executor/execution.c`)
- Built-in commands → Environment: updates variables
- Shell loop → Signal handling: handles interrupts
- Executor → Command errors: reports failures (evidence: `sources/executor/execution.c`)
- C utility library → Formatted output: provides implementation (evidence: `libft/include/libft.h`)
- C utility library → Line reader: provides implementation (evidence: `libft/include/libft.h`)
