# msgenan/42cursus-minishell architecture

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

- Interactive diagram: https://gitdiagram.com/msgenan/42cursus-minishell
- Repository: https://github.com/msgenan/42cursus-minishell

## Overview

Minishell is an interactive C shell. Its principal workflow reads a command line, tokenizes and validates it, builds command and redirection structures, expands arguments, then dispatches built-ins or launches external processes with pipes and redirections. The README also documents prompt history, signals, environment management, and heredocs. The graph preserves these documented capabilities; detailed wiring is limited to sampled source, so unsampled subsystem links are omitted where ownership is unclear.

Main entry points: [`src/main.c`](https://github.com/msgenan/42cursus-minishell/blob/main/src/main.c) (Interactive loop), [`src/executor/executor.c`](https://github.com/msgenan/42cursus-minishell/blob/main/src/executor/executor.c) (Executor), [`src/builtins`](https://github.com/msgenan/42cursus-minishell/tree/main/src/builtins) (Built-in commands), [`src/utils/tools/func_tools.c`](https://github.com/msgenan/42cursus-minishell/blob/main/src/utils/tools/func_tools.c) (Command lookup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interaction["Shell interaction"]
  node_main["Interactive loop<br/>[main.c]"]
  node_history["Command history<br/>[main.c]"]
  node_signals["Signal handling<br/>[signal.c]"]
end

subgraph group_syntax["Command processing"]
  node_lexer["Lexer<br/>[lexer.c]"]
  node_syntaxcheck["Syntax validation<br/>[syntax.c]"]
  node_parser["Command parser<br/>[parser.c]"]
  node_expansion["Expansion<br/>[expand.c]"]
end

subgraph group_execution["Command execution"]
  node_executor["Executor<br/>[executor.c]"]
  node_builtin_dispatch["Builtin dispatch<br/>[builtins.c]"]
  node_builtin_commands["Built-in commands"]
  node_redirections["Redirections<br/>[redir_funcs.c]"]
  node_heredoc["Here-documents<br/>[heredoc.c]"]
  node_path_lookup["Command lookup<br/>[func_tools.c]"]
  node_processes["Processes and pipes<br/>[executor.c]"]
end

subgraph group_state["Shell state"]
  node_environment[("Environment state<br/>[environment.c]")]
  node_env_tools["Environment tools<br/>[env_tools.c]"]
  node_export_tools["Export tools<br/>[export_tools.c]"]
end

node_user(("Shell user"))
node_terminal["Terminal and history service"]
node_os["Operating system"]
node_filesystem["Filesystem"]

node_user -->|"enters commands"| node_main
node_main -->|"reads prompt"| node_terminal
node_main -->|"records input"| node_history
node_history -->|"updates history"| node_terminal
node_main -->|"initializes handlers"| node_signals
node_main -->|"tokenizes input"| node_lexer
node_main -->|"validates tokens"| node_syntaxcheck
node_main -->|"parses tokens"| node_parser
node_main -->|"expands commands"| node_expansion
node_expansion -->|"reads variables"| node_environment
node_main -->|"executes commands"| node_executor
node_executor -->|"dispatches built-ins"| node_builtin_dispatch
node_builtin_dispatch -->|"invokes command"| node_builtin_commands
node_builtin_commands -->|"updates environment"| node_environment
node_builtin_commands -->|"uses environment tools"| node_env_tools
node_builtin_commands -->|"uses export tools"| node_export_tools
node_executor -->|"handles heredocs"| node_heredoc
node_executor -->|"applies redirections"| node_redirections
node_executor -->|"launches pipeline"| node_processes
node_processes -->|"forks and executes"| node_os
node_executor -->|"resolves command"| node_path_lookup
node_path_lookup -->|"reads PATH"| node_environment
node_path_lookup -->|"searches executable"| node_filesystem
node_redirections -->|"opens files"| node_filesystem
node_processes -->|"redirects descriptors"| node_filesystem

click node_main "https://github.com/msgenan/42cursus-minishell/blob/main/src/main.c"
click node_history "https://github.com/msgenan/42cursus-minishell/blob/main/src/main.c"
click node_signals "https://github.com/msgenan/42cursus-minishell/blob/main/src/utils/signal.c"
click node_lexer "https://github.com/msgenan/42cursus-minishell/blob/main/src/lexer/lexer.c"
click node_syntaxcheck "https://github.com/msgenan/42cursus-minishell/blob/main/src/utils/syntax.c"
click node_parser "https://github.com/msgenan/42cursus-minishell/blob/main/src/parser/parser.c"
click node_expansion "https://github.com/msgenan/42cursus-minishell/blob/main/src/parser/expand/expand.c"
click node_executor "https://github.com/msgenan/42cursus-minishell/blob/main/src/executor/executor.c"
click node_builtin_dispatch "https://github.com/msgenan/42cursus-minishell/blob/main/src/executor/builtins.c"
click node_builtin_commands "https://github.com/msgenan/42cursus-minishell/tree/main/src/builtins"
click node_redirections "https://github.com/msgenan/42cursus-minishell/blob/main/src/executor/redirections/redir_funcs.c"
click node_heredoc "https://github.com/msgenan/42cursus-minishell/blob/main/src/executor/heredoc.c"
click node_path_lookup "https://github.com/msgenan/42cursus-minishell/blob/main/src/utils/tools/func_tools.c"
click node_processes "https://github.com/msgenan/42cursus-minishell/blob/main/src/executor/executor.c"
click node_environment "https://github.com/msgenan/42cursus-minishell/blob/main/src/executor/environment.c"
click node_env_tools "https://github.com/msgenan/42cursus-minishell/blob/main/src/utils/tools/env_tools.c"
click node_export_tools "https://github.com/msgenan/42cursus-minishell/blob/main/src/utils/tools/export_tools.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_main,node_history,node_signals,node_user toneBlue
class node_lexer,node_syntaxcheck,node_parser,node_expansion toneAmber
class node_executor,node_builtin_dispatch,node_builtin_commands,node_redirections,node_heredoc,node_path_lookup,node_processes toneMint
class node_environment,node_env_tools,node_export_tools toneRose
class node_terminal,node_os,node_filesystem toneIndigo
```

## Components

### Shell interaction

- [Interactive loop](https://github.com/msgenan/42cursus-minishell/blob/main/src/main.c): `src/main.c`
- [Command history](https://github.com/msgenan/42cursus-minishell/blob/main/src/main.c): `src/main.c`
- [Signal handling](https://github.com/msgenan/42cursus-minishell/blob/main/src/utils/signal.c): `src/utils/signal.c`

### Command processing

- [Lexer](https://github.com/msgenan/42cursus-minishell/blob/main/src/lexer/lexer.c): `src/lexer/lexer.c`
- [Syntax validation](https://github.com/msgenan/42cursus-minishell/blob/main/src/utils/syntax.c): `src/utils/syntax.c`
- [Command parser](https://github.com/msgenan/42cursus-minishell/blob/main/src/parser/parser.c): `src/parser/parser.c`
- [Expansion](https://github.com/msgenan/42cursus-minishell/blob/main/src/parser/expand/expand.c): `src/parser/expand/expand.c`

### Command execution

- [Executor](https://github.com/msgenan/42cursus-minishell/blob/main/src/executor/executor.c): `src/executor/executor.c`
- [Builtin dispatch](https://github.com/msgenan/42cursus-minishell/blob/main/src/executor/builtins.c): `src/executor/builtins.c`
- [Built-in commands](https://github.com/msgenan/42cursus-minishell/tree/main/src/builtins): `src/builtins`
- [Redirections](https://github.com/msgenan/42cursus-minishell/blob/main/src/executor/redirections/redir_funcs.c): `src/executor/redirections/redir_funcs.c`
- [Here-documents](https://github.com/msgenan/42cursus-minishell/blob/main/src/executor/heredoc.c): `src/executor/heredoc.c`
- [Command lookup](https://github.com/msgenan/42cursus-minishell/blob/main/src/utils/tools/func_tools.c): `src/utils/tools/func_tools.c`
- [Processes and pipes](https://github.com/msgenan/42cursus-minishell/blob/main/src/executor/executor.c): `src/executor/executor.c`

### Shell state

- [Environment state](https://github.com/msgenan/42cursus-minishell/blob/main/src/executor/environment.c): `src/executor/environment.c`
- [Environment tools](https://github.com/msgenan/42cursus-minishell/blob/main/src/utils/tools/env_tools.c): `src/utils/tools/env_tools.c`
- [Export tools](https://github.com/msgenan/42cursus-minishell/blob/main/src/utils/tools/export_tools.c): `src/utils/tools/export_tools.c`

### Other components

- **Shell user**
- **Terminal and history service**
- **Operating system**
- **Filesystem**

## Connections

- Shell user → Interactive loop: enters commands
- Interactive loop → Terminal and history service: reads prompt
- Interactive loop → Command history: records input
- Command history → Terminal and history service: updates history
- Interactive loop → Signal handling: initializes handlers
- Interactive loop → Lexer: tokenizes input
- Interactive loop → Syntax validation: validates tokens
- Interactive loop → Command parser: parses tokens
- Interactive loop → Expansion: expands commands
- Expansion → Environment state: reads variables
- Interactive loop → Executor: executes commands
- Executor → Builtin dispatch: dispatches built-ins
- Builtin dispatch → Built-in commands: invokes command
- Built-in commands → Environment state: updates environment
- Built-in commands → Environment tools: uses environment tools
- Built-in commands → Export tools: uses export tools
- Executor → Here-documents: handles heredocs
- Executor → Redirections: applies redirections
- Executor → Processes and pipes: launches pipeline
- Processes and pipes → Operating system: forks and executes
- Executor → Command lookup: resolves command
- Command lookup → Environment state: reads PATH
- Command lookup → Filesystem: searches executable
- Redirections → Filesystem: opens files
- Processes and pipes → Filesystem: redirects descriptors
