# polslag/minishell architecture

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

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

## Overview

Minishell is an interactive C shell: it reads a command line, turns it into commands, then executes shell built-ins or external commands. Its documented capabilities include pipes, redirections, heredocs, environment expansion and environment-management built-ins. The excerpts show the prompt loop, token validation, command parsing and expansion calls; several execution and integration links are not sampled, so those are marked unverified rather than inferred as definite calls.

Main entry points: [`src/shell.c`](https://github.com/polslag/minishell/blob/main/src/shell.c) (Interactive loop), [`src/parser.c`](https://github.com/polslag/minishell/blob/main/src/parser.c) (Command parser), [`src/exec.c`](https://github.com/polslag/minishell/blob/main/src/exec.c) (Command execution), [`src/env_setup.c`](https://github.com/polslag/minishell/blob/main/src/env_setup.c) (Environment state)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["Input and parsing"]
  node_shell["Interactive loop<br/>[shell.c]"]
  node_lexer["Lexer<br/>[token.c]"]
  node_syntax["Syntax checks<br/>[syntax.c]"]
  node_parser["Command parser<br/>[parser.c]"]
  node_parser_helpers["Parse helpers<br/>[parser_utils.c]"]
  node_commands["Command lists<br/>[command.c]"]
  node_expansion["Word expansion<br/>[expand.c]"]
  node_heredoc["Heredoc input<br/>[heredoc.c]"]
  node_heredoc_expansion["Heredoc expansion<br/>[heredoc_expand.c]"]
end

subgraph group_runtime["Shell runtime"]
  node_execution["Command execution<br/>[exec.c]"]
  node_execution_run["Execution dispatch<br/>[exec_run.c]"]
  node_redirection["Redirections<br/>[redir.c]"]
  node_path_lookup["Executable lookup<br/>[utils_path.c]"]
end

subgraph group_environment["Environment and built-ins"]
  node_environment_state[("Environment state<br/>[env_setup.c]")]
  node_environment_helpers["Environment helpers<br/>[env_utils.c]"]
  node_builtins["Shell built-ins"]
end

subgraph group_support["Shared utilities"]
  node_libft["C utility library<br/>[libft.h]"]
  node_shell_types["Shell data types<br/>[minishell.h]"]
end

node_user(("Shell user"))

node_user -->|"enters commands"| node_shell
node_shell -->|"tokenizes input"| node_lexer
node_shell -->|"checks tokens"| node_syntax
node_shell -->|"parses commands"| node_commands
node_commands -->|"calls parser"| node_parser
node_parser -->|"adds words"| node_parser_helpers
node_parser -->|"expands words"| node_expansion
node_parser -->|"creates redirections"| node_redirection
node_shell -->|"executes commands"| node_execution
node_execution -.->|"dispatches execution"| node_execution_run
node_execution -.->|"applies redirections"| node_redirection
node_execution -.->|"resolves executables"| node_path_lookup
node_execution -.->|"dispatches built-ins"| node_builtins
node_expansion -.->|"looks up variables"| node_environment_state
node_heredoc -.->|"expands input"| node_heredoc_expansion
node_shell -.->|"initializes state"| node_environment_state
node_builtins -.->|"updates environment"| node_environment_state
node_parser -.->|"supports heredocs"| node_heredoc
node_shell -->|"uses shared types"| node_shell_types
node_parser -->|"uses shared types"| node_shell_types
node_parser_helpers -->|"uses string helpers"| node_libft

click node_shell "https://github.com/polslag/minishell/blob/main/src/shell.c"
click node_lexer "https://github.com/polslag/minishell/blob/main/src/token.c"
click node_syntax "https://github.com/polslag/minishell/blob/main/src/syntax.c"
click node_parser "https://github.com/polslag/minishell/blob/main/src/parser.c"
click node_parser_helpers "https://github.com/polslag/minishell/blob/main/src/parser_utils.c"
click node_commands "https://github.com/polslag/minishell/blob/main/src/command.c"
click node_expansion "https://github.com/polslag/minishell/blob/main/src/expand.c"
click node_heredoc "https://github.com/polslag/minishell/blob/main/src/heredoc.c"
click node_heredoc_expansion "https://github.com/polslag/minishell/blob/main/src/heredoc_expand.c"
click node_execution "https://github.com/polslag/minishell/blob/main/src/exec.c"
click node_execution_run "https://github.com/polslag/minishell/blob/main/src/exec_run.c"
click node_redirection "https://github.com/polslag/minishell/blob/main/src/redir.c"
click node_path_lookup "https://github.com/polslag/minishell/blob/main/src/utils_path.c"
click node_environment_state "https://github.com/polslag/minishell/blob/main/src/env_setup.c"
click node_environment_helpers "https://github.com/polslag/minishell/blob/main/src/env_utils.c"
click node_builtins "https://github.com/polslag/minishell/tree/main/src/builtins"
click node_libft "https://github.com/polslag/minishell/blob/main/lib/libft-pilagach/libft.h"
click node_shell_types "https://github.com/polslag/minishell/blob/main/include/minishell.h"

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_shell,node_lexer,node_syntax,node_parser,node_parser_helpers,node_commands,node_expansion,node_heredoc,node_heredoc_expansion,node_user toneBlue
class node_execution,node_execution_run,node_redirection,node_path_lookup toneAmber
class node_environment_state,node_environment_helpers,node_builtins toneMint
class node_libft,node_shell_types toneRose
```

## Components

### Input and parsing

- [Interactive loop](https://github.com/polslag/minishell/blob/main/src/shell.c): `src/shell.c`
- [Lexer](https://github.com/polslag/minishell/blob/main/src/token.c): `src/token.c`
- [Syntax checks](https://github.com/polslag/minishell/blob/main/src/syntax.c): `src/syntax.c`
- [Command parser](https://github.com/polslag/minishell/blob/main/src/parser.c): `src/parser.c`
- [Parse helpers](https://github.com/polslag/minishell/blob/main/src/parser_utils.c): `src/parser_utils.c`
- [Command lists](https://github.com/polslag/minishell/blob/main/src/command.c): `src/command.c`
- [Word expansion](https://github.com/polslag/minishell/blob/main/src/expand.c): `src/expand.c`
- [Heredoc input](https://github.com/polslag/minishell/blob/main/src/heredoc.c): `src/heredoc.c`
- [Heredoc expansion](https://github.com/polslag/minishell/blob/main/src/heredoc_expand.c): `src/heredoc_expand.c`

### Shell runtime

- [Command execution](https://github.com/polslag/minishell/blob/main/src/exec.c): `src/exec.c`
- [Execution dispatch](https://github.com/polslag/minishell/blob/main/src/exec_run.c): `src/exec_run.c`
- [Redirections](https://github.com/polslag/minishell/blob/main/src/redir.c): `src/redir.c`
- [Executable lookup](https://github.com/polslag/minishell/blob/main/src/utils_path.c): `src/utils_path.c`

### Environment and built-ins

- [Environment state](https://github.com/polslag/minishell/blob/main/src/env_setup.c): `src/env_setup.c`
- [Environment helpers](https://github.com/polslag/minishell/blob/main/src/env_utils.c): `src/env_utils.c`
- [Shell built-ins](https://github.com/polslag/minishell/tree/main/src/builtins): `src/builtins`

### Shared utilities

- [C utility library](https://github.com/polslag/minishell/blob/main/lib/libft-pilagach/libft.h): `lib/libft-pilagach/libft.h`
- [Shell data types](https://github.com/polslag/minishell/blob/main/include/minishell.h): `include/minishell.h`

### Other components

- **Shell user**

## Connections

- Shell user → Interactive loop: enters commands
- Interactive loop → Lexer: tokenizes input (evidence: `src/shell.c`)
- Interactive loop → Syntax checks: checks tokens (evidence: `src/shell.c`)
- Interactive loop → Command lists: parses commands (evidence: `src/shell.c`)
- Command lists → Command parser: calls parser (evidence: `src/command.c`)
- Command parser → Parse helpers: adds words (evidence: `src/parser.c`)
- Command parser → Word expansion: expands words (evidence: `src/parser.c`)
- Command parser → Redirections: creates redirections (evidence: `src/parser.c`)
- Interactive loop → Command execution: executes commands (evidence: `src/shell.c`)
- Command execution → Execution dispatch: dispatches execution
- Command execution → Redirections: applies redirections
- Command execution → Executable lookup: resolves executables
- Command execution → Shell built-ins: dispatches built-ins
- Word expansion → Environment state: looks up variables
- Heredoc input → Heredoc expansion: expands input
- Interactive loop → Environment state: initializes state
- Shell built-ins → Environment state: updates environment
- Command parser → Heredoc input: supports heredocs
- Interactive loop → Shell data types: uses shared types (evidence: `src/shell.c`)
- Command parser → Shell data types: uses shared types (evidence: `src/parser.c`)
- Parse helpers → C utility library: uses string helpers (evidence: `src/parser_utils.c`)
