# tgomez-f/minishell architecture

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

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

## Overview

Minishell is an interactive Unix-shell implementation. Its main workflow reads a command line, tokenizes and expands it, builds commands, then dispatches builtins or external processes with redirections and pipelines; environment state and signals support that loop. The README documents these capabilities, while the excerpts show key calls in input, parsing, dispatch, and builtin handling. Several parsing and pipeline implementations are indexed but unsampled, so their documented roles are included without guessing their internal call paths.

Main entry points: [`src/main/main.c`](https://github.com/tgomez-f/minishell/blob/main/src/main/main.c) (Main loop), [`src/exec/executor.c`](https://github.com/tgomez-f/minishell/blob/main/src/exec/executor.c) (Command dispatcher), [`src/builtins/exec_builtins.c`](https://github.com/tgomez-f/minishell/blob/main/src/builtins/exec_builtins.c) (Builtin commands), [`src/parsing/init_shell.c`](https://github.com/tgomez-f/minishell/blob/main/src/parsing/init_shell.c) (Shell and environment state)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interaction["Shell interaction"]
  node_main["Main loop<br/>[main.c]"]
  node_input["Input reader<br/>[get_input.c]"]
  node_signals["Signal handlers<br/>[touch_control.c]"]
end

subgraph group_parse["Command parsing"]
  node_tokenize["Tokenizer<br/>[tokenize_line.c]"]
  node_syntax["Syntax validation<br/>[valid_syntax.c]"]
  node_expand["Variable expansion<br/>[expander.c]"]
  node_commands["Command construction<br/>[build_cmds_list.c]"]
  node_heredoc["Here-doc input<br/>[create_heredoc.c]"]
end

subgraph group_runtime["Execution runtime"]
  node_executor["Command dispatcher<br/>[executor.c]"]
  node_builtin["Builtin commands<br/>[exec_builtins.c]"]
  node_env_builtins["Environment builtins"]
  node_external["External commands<br/>[find_cmd_path.c]"]
  node_pipeline["Pipeline runner<br/>[exec_pipe_line.c]"]
  node_redirect["Redirections<br/>[redirections.c]"]
  node_pipe_redirect["Pipe wiring<br/>[pipe_redirection.c]"]
end

subgraph group_support["Shell state and utilities"]
  node_shell_state["Shell and environment state<br/>[init_shell.c]"]
  node_libft["Libft utilities"]
end

node_user(("Shell user"))
node_processes["Processes and file descriptors"]

node_user -->|"enters commands"| node_input
node_main -->|"reads input"| node_input
node_main -->|"initializes"| node_signals
node_main -->|"tokenizes line"| node_tokenize
node_tokenize -->|"validates syntax"| node_syntax
node_main -->|"expands tokens"| node_expand
node_main -->|"builds commands"| node_commands
node_commands -.->|"collects here-docs"| node_heredoc
node_main -->|"dispatches commands"| node_executor
node_executor -->|"runs builtins"| node_builtin
node_builtin -->|"handles export"| node_env_builtins
node_executor -->|"resolves command path"| node_external
node_executor -->|"runs pipelines"| node_pipeline
node_executor -->|"applies redirections"| node_redirect
node_pipeline -.->|"sets pipe descriptors"| node_pipe_redirect
node_executor -->|"forks and waits"| node_processes
node_external -->|"executes command"| node_processes
node_redirect -->|"changes file descriptors"| node_processes
node_main -->|"initializes state"| node_shell_state
node_expand -.->|"uses environment"| node_shell_state
node_builtin -.->|"updates shell state"| node_shell_state

click node_main "https://github.com/tgomez-f/minishell/blob/main/src/main/main.c"
click node_input "https://github.com/tgomez-f/minishell/blob/main/src/main/get_input.c"
click node_signals "https://github.com/tgomez-f/minishell/blob/main/src/signals/touch_control.c"
click node_tokenize "https://github.com/tgomez-f/minishell/blob/main/src/parsing/tokenize_line.c"
click node_syntax "https://github.com/tgomez-f/minishell/blob/main/src/parsing/valid_syntax.c"
click node_expand "https://github.com/tgomez-f/minishell/blob/main/src/parsing/expander.c"
click node_commands "https://github.com/tgomez-f/minishell/blob/main/src/parsing/build_cmds_list.c"
click node_heredoc "https://github.com/tgomez-f/minishell/blob/main/src/parsing/create_heredoc.c"
click node_executor "https://github.com/tgomez-f/minishell/blob/main/src/exec/executor.c"
click node_builtin "https://github.com/tgomez-f/minishell/blob/main/src/builtins/exec_builtins.c"
click node_env_builtins "https://github.com/tgomez-f/minishell/blob/main/src/builtins/export/builtins_fname_export.c"
click node_external "https://github.com/tgomez-f/minishell/blob/main/src/exec/find_cmd_path.c"
click node_pipeline "https://github.com/tgomez-f/minishell/blob/main/src/exec/exec_pipe_line.c"
click node_redirect "https://github.com/tgomez-f/minishell/blob/main/src/exec/redirections/redirections.c"
click node_pipe_redirect "https://github.com/tgomez-f/minishell/blob/main/src/exec/redirections/pipe_redirection.c"
click node_shell_state "https://github.com/tgomez-f/minishell/blob/main/src/parsing/init_shell.c"
click node_libft "https://github.com/tgomez-f/minishell/tree/main/includes/LIBFT/src"

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_main,node_input,node_signals,node_user toneBlue
class node_tokenize,node_syntax,node_expand,node_commands,node_heredoc toneAmber
class node_executor,node_builtin,node_env_builtins,node_external,node_pipeline,node_redirect,node_pipe_redirect toneMint
class node_shell_state,node_libft toneRose
class node_processes toneIndigo
```

## Components

### Shell interaction

- [Main loop](https://github.com/tgomez-f/minishell/blob/main/src/main/main.c): `src/main/main.c`
- [Input reader](https://github.com/tgomez-f/minishell/blob/main/src/main/get_input.c): `src/main/get_input.c`
- [Signal handlers](https://github.com/tgomez-f/minishell/blob/main/src/signals/touch_control.c): `src/signals/touch_control.c`

### Command parsing

- [Tokenizer](https://github.com/tgomez-f/minishell/blob/main/src/parsing/tokenize_line.c): `src/parsing/tokenize_line.c`
- [Syntax validation](https://github.com/tgomez-f/minishell/blob/main/src/parsing/valid_syntax.c): `src/parsing/valid_syntax.c`
- [Variable expansion](https://github.com/tgomez-f/minishell/blob/main/src/parsing/expander.c): `src/parsing/expander.c`
- [Command construction](https://github.com/tgomez-f/minishell/blob/main/src/parsing/build_cmds_list.c): `src/parsing/build_cmds_list.c`
- [Here-doc input](https://github.com/tgomez-f/minishell/blob/main/src/parsing/create_heredoc.c): `src/parsing/create_heredoc.c`

### Execution runtime

- [Command dispatcher](https://github.com/tgomez-f/minishell/blob/main/src/exec/executor.c): `src/exec/executor.c`
- [Builtin commands](https://github.com/tgomez-f/minishell/blob/main/src/builtins/exec_builtins.c): `src/builtins/exec_builtins.c`
- [Environment builtins](https://github.com/tgomez-f/minishell/blob/main/src/builtins/export/builtins_fname_export.c): `src/builtins/export/builtins_fname_export.c`
- [External commands](https://github.com/tgomez-f/minishell/blob/main/src/exec/find_cmd_path.c): `src/exec/find_cmd_path.c`
- [Pipeline runner](https://github.com/tgomez-f/minishell/blob/main/src/exec/exec_pipe_line.c): `src/exec/exec_pipe_line.c`
- [Redirections](https://github.com/tgomez-f/minishell/blob/main/src/exec/redirections/redirections.c): `src/exec/redirections/redirections.c`
- [Pipe wiring](https://github.com/tgomez-f/minishell/blob/main/src/exec/redirections/pipe_redirection.c): `src/exec/redirections/pipe_redirection.c`

### Shell state and utilities

- [Shell and environment state](https://github.com/tgomez-f/minishell/blob/main/src/parsing/init_shell.c): `src/parsing/init_shell.c`
- [Libft utilities](https://github.com/tgomez-f/minishell/tree/main/includes/LIBFT/src): `includes/LIBFT/src`

### Other components

- **Shell user**
- **Processes and file descriptors**

## Connections

- Shell user → Input reader: enters commands
- Main loop → Input reader: reads input (evidence: `src/main/main.c`)
- Main loop → Signal handlers: initializes (evidence: `src/main/main.c`)
- Main loop → Tokenizer: tokenizes line (evidence: `src/main/main.c`)
- Tokenizer → Syntax validation: validates syntax (evidence: `src/parsing/tokenize_line.c`)
- Main loop → Variable expansion: expands tokens (evidence: `src/main/main.c`)
- Main loop → Command construction: builds commands (evidence: `src/main/main.c`)
- Command construction → Here-doc input: collects here-docs
- Main loop → Command dispatcher: dispatches commands (evidence: `src/main/main.c`)
- Command dispatcher → Builtin commands: runs builtins (evidence: `src/exec/executor.c`)
- Builtin commands → Environment builtins: handles export (evidence: `src/builtins/exec_builtins.c`)
- Command dispatcher → External commands: resolves command path (evidence: `src/exec/executor.c`)
- Command dispatcher → Pipeline runner: runs pipelines (evidence: `src/exec/executor.c`)
- Command dispatcher → Redirections: applies redirections (evidence: `src/exec/executor.c`)
- Pipeline runner → Pipe wiring: sets pipe descriptors
- Command dispatcher → Processes and file descriptors: forks and waits (evidence: `src/exec/executor.c`)
- External commands → Processes and file descriptors: executes command
- Redirections → Processes and file descriptors: changes file descriptors
- Main loop → Shell and environment state: initializes state (evidence: `src/main/main.c`)
- Variable expansion → Shell and environment state: uses environment
- Builtin commands → Shell and environment state: updates shell state
