# sel-l/minishell2 architecture

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

- Interactive diagram: https://gitdiagram.com/sel-l/minishell2
- Repository: https://github.com/sel-l/minishell2

## Overview

Minishell’s main workflow is an interactive prompt that reads a command, parses it into executable structure, and runs built-ins or external programs; it also supports environment expansion, pipes, redirections, heredocs, and signal handling. Sampled source confirms the main loop, environment initialization, AST execution, pipe dispatch, expansion, and heredoc preparation. Several parsing and execution details are represented from the README and file tree; links without direct excerpt evidence are marked dashed with null evidence.

Main entry points: [`src/execution/execution.c`](https://github.com/sel-l/minishell2/blob/main/src/execution/execution.c) (Execution dispatcher), [`src/main.c`](https://github.com/sel-l/minishell2/blob/main/src/main.c) (Shell loop), [`src/parsing/ft_readline.c`](https://github.com/sel-l/minishell2/blob/main/src/parsing/ft_readline.c) (Prompt input), [`src/parsing/parsing.c`](https://github.com/sel-l/minishell2/blob/main/src/parsing/parsing.c) (Parse and validate)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["Input and parsing"]
  node_loop["Shell loop<br/>[main.c]"]
  node_readline["Prompt input<br/>[ft_readline.c]"]
  node_parser["Parse and validate<br/>[parsing.c]"]
  node_lexer["Tokenize commands<br/>[tokenizer.c]"]
  node_ast["Command AST<br/>[ast_parse_cmd.c]"]
end

subgraph group_state["Shell state"]
  node_expansion["Variable expansion<br/>[expansion.c]"]
  node_environment[("Environment state<br/>[env_op.c]")]
  node_signals["Signal handling<br/>[signals.c]"]
end

subgraph group_runtime["Command runtime"]
  node_executor["Execution dispatcher<br/>[execution.c]"]
  node_pipes["Pipeline processes<br/>[execution.c]"]
  node_redirections["Apply redirections<br/>[apply_redir.c]"]
  node_heredoc["Heredoc input<br/>[heredoc.c]"]
  node_builtins["Built-in commands<br/>[builtin.c]"]
  node_external["External programs<br/>[get_path.c]"]
end

subgraph group_support["Runtime support"]
  node_contracts["Shell interfaces<br/>[main_minishell.h]"]
  node_libft["C utility library<br/>[libft.h]"]
  node_gnl["Line reader utility<br/>[get_next_line.c]"]
end

node_user(("Shell user"))

node_user -->|"starts shell"| node_loop
node_loop -->|"reads prompt"| node_readline
node_readline -.->|"submits command"| node_parser
node_parser -.->|"tokenizes input"| node_lexer
node_lexer -.->|"builds command tree"| node_ast
node_ast -.->|"expands words"| node_expansion
node_expansion -->|"reads variables"| node_environment
node_loop -->|"initializes environment"| node_environment
node_loop -->|"executes AST"| node_executor
node_loop -->|"sets signal modes"| node_signals
node_executor -->|"dispatches pipes"| node_pipes
node_executor -.->|"dispatches built-ins"| node_builtins
node_executor -.->|"runs programs"| node_external
node_executor -.->|"applies redirections"| node_redirections
node_executor -->|"prepares heredocs"| node_heredoc
node_user -.->|"requests pipelines"| node_pipes
node_user -.->|"requests redirection"| node_redirections
node_user -.->|"provides delimiter input"| node_heredoc

click node_loop "https://github.com/sel-l/minishell2/blob/main/src/main.c"
click node_readline "https://github.com/sel-l/minishell2/blob/main/src/parsing/ft_readline.c"
click node_parser "https://github.com/sel-l/minishell2/blob/main/src/parsing/parsing.c"
click node_lexer "https://github.com/sel-l/minishell2/blob/main/src/tokenizer/tokenizer.c"
click node_ast "https://github.com/sel-l/minishell2/blob/main/src/ast/ast_parse_cmd.c"
click node_expansion "https://github.com/sel-l/minishell2/blob/main/src/expansion/expansion.c"
click node_environment "https://github.com/sel-l/minishell2/blob/main/src/env/env_op.c"
click node_signals "https://github.com/sel-l/minishell2/blob/main/src/signals/signals.c"
click node_executor "https://github.com/sel-l/minishell2/blob/main/src/execution/execution.c"
click node_pipes "https://github.com/sel-l/minishell2/blob/main/src/execution/execution.c"
click node_redirections "https://github.com/sel-l/minishell2/blob/main/src/execution/apply_redir.c"
click node_heredoc "https://github.com/sel-l/minishell2/blob/main/src/heredoc/heredoc.c"
click node_builtins "https://github.com/sel-l/minishell2/blob/main/src/builtins/builtin.c"
click node_external "https://github.com/sel-l/minishell2/blob/main/src/execution/get_path.c"
click node_contracts "https://github.com/sel-l/minishell2/blob/main/headers/main_minishell.h"
click node_libft "https://github.com/sel-l/minishell2/blob/main/libft/libft.h"
click node_gnl "https://github.com/sel-l/minishell2/blob/main/libft/gnl/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_loop,node_readline,node_parser,node_lexer,node_ast,node_user toneBlue
class node_expansion,node_environment,node_signals toneAmber
class node_executor,node_pipes,node_redirections,node_heredoc,node_builtins,node_external toneMint
class node_contracts,node_libft,node_gnl toneRose
```

## Components

### Input and parsing

- [Shell loop](https://github.com/sel-l/minishell2/blob/main/src/main.c): `src/main.c`
- [Prompt input](https://github.com/sel-l/minishell2/blob/main/src/parsing/ft_readline.c): `src/parsing/ft_readline.c`
- [Parse and validate](https://github.com/sel-l/minishell2/blob/main/src/parsing/parsing.c): `src/parsing/parsing.c`
- [Tokenize commands](https://github.com/sel-l/minishell2/blob/main/src/tokenizer/tokenizer.c): `src/tokenizer/tokenizer.c`
- [Command AST](https://github.com/sel-l/minishell2/blob/main/src/ast/ast_parse_cmd.c): `src/ast/ast_parse_cmd.c`

### Shell state

- [Variable expansion](https://github.com/sel-l/minishell2/blob/main/src/expansion/expansion.c): `src/expansion/expansion.c`
- [Environment state](https://github.com/sel-l/minishell2/blob/main/src/env/env_op.c): `src/env/env_op.c`
- [Signal handling](https://github.com/sel-l/minishell2/blob/main/src/signals/signals.c): `src/signals/signals.c`

### Command runtime

- [Execution dispatcher](https://github.com/sel-l/minishell2/blob/main/src/execution/execution.c): `src/execution/execution.c`
- [Pipeline processes](https://github.com/sel-l/minishell2/blob/main/src/execution/execution.c): `src/execution/execution.c`
- [Apply redirections](https://github.com/sel-l/minishell2/blob/main/src/execution/apply_redir.c): `src/execution/apply_redir.c`
- [Heredoc input](https://github.com/sel-l/minishell2/blob/main/src/heredoc/heredoc.c): `src/heredoc/heredoc.c`
- [Built-in commands](https://github.com/sel-l/minishell2/blob/main/src/builtins/builtin.c): `src/builtins/builtin.c`
- [External programs](https://github.com/sel-l/minishell2/blob/main/src/execution/get_path.c): `src/execution/get_path.c`

### Runtime support

- [Shell interfaces](https://github.com/sel-l/minishell2/blob/main/headers/main_minishell.h): `headers/main_minishell.h`
- [C utility library](https://github.com/sel-l/minishell2/blob/main/libft/libft.h): `libft/libft.h`
- [Line reader utility](https://github.com/sel-l/minishell2/blob/main/libft/gnl/get_next_line.c): `libft/gnl/get_next_line.c`

### Other components

- **Shell user**

## Connections

- Shell user → Shell loop: starts shell
- Shell loop → Prompt input: reads prompt (evidence: `src/main.c`)
- Prompt input → Parse and validate: submits command
- Parse and validate → Tokenize commands: tokenizes input
- Tokenize commands → Command AST: builds command tree
- Command AST → Variable expansion: expands words
- Variable expansion → Environment state: reads variables (evidence: `src/expansion/expansion.c`)
- Shell loop → Environment state: initializes environment (evidence: `src/main.c`)
- Shell loop → Execution dispatcher: executes AST (evidence: `src/main.c`)
- Shell loop → Signal handling: sets signal modes (evidence: `src/main.c`)
- Execution dispatcher → Pipeline processes: dispatches pipes (evidence: `src/execution/execution.c`)
- Execution dispatcher → Built-in commands: dispatches built-ins
- Execution dispatcher → External programs: runs programs
- Execution dispatcher → Apply redirections: applies redirections
- Execution dispatcher → Heredoc input: prepares heredocs (evidence: `src/execution/execution.c`)
- Shell user → Pipeline processes: requests pipelines
- Shell user → Apply redirections: requests redirection
- Shell user → Heredoc input: provides delimiter input
