# mliligenes/42-minishell architecture

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

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

## Overview

This repository implements minishell: an interactive command-line shell that parses a command, prepares and executes its command tree, and maintains shell state. The main workflow is visible in the shell loop and parser excerpts; filenames and declarations indicate additional runtime capabilities including builtins, pipes, redirections, heredocs, and wildcard/variable expansion. The mandatory and bonus trees are parallel implementations, so the graph uses mandatory paths. Execution internals were not sampled; links to them reflect only the dispatches visible in the sampled entry points.

Main entry points: [`mandatory/shell_loop.c`](https://github.com/mliligenes/42-minishell/blob/main/mandatory/shell_loop.c) (Interactive loop), [`mandatory/parsing/parser.c`](https://github.com/mliligenes/42-minishell/blob/main/mandatory/parsing/parser.c) (Input parser), [`mandatory/execution/execute_cmd_handle.c`](https://github.com/mliligenes/42-minishell/blob/main/mandatory/execution/execute_cmd_handle.c) (Command execution), [`mandatory/main.c`](https://github.com/mliligenes/42-minishell/blob/main/mandatory/main.c) (AST dispatch)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Shell interface"]
  node_main["Program entry<br/>[main.c]"]
  node_loop["Interactive loop<br/>[shell_loop.c]"]
end

subgraph group_parsing["Command parsing"]
  node_parser["Input parser<br/>[parser.c]"]
  node_tokenizer["Lexer and tokenizer<br/>[tokenizer.c]"]
  node_validation["Token validation<br/>[token_validation.c]"]
  node_processing["Token processing<br/>[processing.c]"]
  node_ast["AST construction<br/>[ast_construction.c]"]
end

subgraph group_preparation["Expansion and preparation"]
  node_expansion["Expansion and wildcards<br/>[expension.c]"]
  node_wildcard["Wildcard matching<br/>[wildcard.c]"]
end

subgraph group_execution["Command execution"]
  node_dispatch["AST dispatch<br/>[main.c]"]
  node_commands["Command execution"]
  node_operators["Pipes and logic<br/>[pipe.c]"]
  node_redirections["Redirections<br/>[redirections.c]"]
  node_heredocs["Here-documents<br/>[open_here_docs.c]"]
  node_builtins["Shell builtins<br/>[ft_export.c]"]
end

subgraph group_state["Shell state and I/O"]
  node_environment[("Environment<br/>[env_utils.c]")]
  node_signals["Signal handling<br/>[signals.c]"]
end

node_user(("Shell user"))
node_filesystem(("Process and filesystem"))

node_user -->|"enters commands"| node_loop
node_main -->|"starts loop"| node_loop
node_loop -->|"parses input"| node_parser
node_parser -->|"creates tokens"| node_tokenizer
node_parser -->|"validates tokens"| node_validation
node_parser -->|"extracts tokens"| node_processing
node_parser -->|"builds tree"| node_ast
node_loop -->|"opens documents"| node_heredocs
node_loop -->|"executes tree"| node_dispatch
node_dispatch -->|"executes command"| node_commands
node_dispatch -->|"handles operators"| node_operators
node_commands -->|"runs builtins"| node_builtins
node_commands -->|"applies redirects"| node_redirections
node_commands -->|"runs processes"| node_filesystem
node_commands -->|"reads environment"| node_environment
node_builtins -->|"updates environment"| node_environment
node_loop -->|"sets handlers"| node_signals
node_operators -->|"connects processes"| node_filesystem

click node_main "https://github.com/mliligenes/42-minishell/blob/main/mandatory/main.c"
click node_loop "https://github.com/mliligenes/42-minishell/blob/main/mandatory/shell_loop.c"
click node_parser "https://github.com/mliligenes/42-minishell/blob/main/mandatory/parsing/parser.c"
click node_tokenizer "https://github.com/mliligenes/42-minishell/blob/main/mandatory/tokenizer/tokenizer.c"
click node_validation "https://github.com/mliligenes/42-minishell/blob/main/mandatory/tokenizer/token_validation.c"
click node_processing "https://github.com/mliligenes/42-minishell/blob/main/mandatory/processing/processing.c"
click node_ast "https://github.com/mliligenes/42-minishell/blob/main/mandatory/parsing/ast_construction.c"
click node_expansion "https://github.com/mliligenes/42-minishell/blob/main/mandatory/post_processing/expension.c"
click node_wildcard "https://github.com/mliligenes/42-minishell/blob/main/mandatory/post_processing/wildcard.c"
click node_dispatch "https://github.com/mliligenes/42-minishell/blob/main/mandatory/main.c"
click node_commands "https://github.com/mliligenes/42-minishell/blob/main/mandatory/execution/execute_cmd_handle.c"
click node_operators "https://github.com/mliligenes/42-minishell/blob/main/mandatory/execution/pipe.c"
click node_redirections "https://github.com/mliligenes/42-minishell/blob/main/mandatory/execution/redirections.c"
click node_heredocs "https://github.com/mliligenes/42-minishell/blob/main/mandatory/heredoc/open_here_docs.c"
click node_builtins "https://github.com/mliligenes/42-minishell/blob/main/mandatory/builtins/ft_export.c"
click node_environment "https://github.com/mliligenes/42-minishell/blob/main/mandatory/builtins/env_utils.c"
click node_signals "https://github.com/mliligenes/42-minishell/blob/main/mandatory/signals.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_loop,node_user toneBlue
class node_parser,node_tokenizer,node_validation,node_processing,node_ast toneAmber
class node_expansion,node_wildcard toneMint
class node_dispatch,node_commands,node_operators,node_redirections,node_heredocs,node_builtins toneRose
class node_environment,node_signals,node_filesystem toneIndigo
```

## Components

### Shell interface

- [Program entry](https://github.com/mliligenes/42-minishell/blob/main/mandatory/main.c): `mandatory/main.c`
- [Interactive loop](https://github.com/mliligenes/42-minishell/blob/main/mandatory/shell_loop.c): `mandatory/shell_loop.c`

### Command parsing

- [Input parser](https://github.com/mliligenes/42-minishell/blob/main/mandatory/parsing/parser.c): `mandatory/parsing/parser.c`
- [Lexer and tokenizer](https://github.com/mliligenes/42-minishell/blob/main/mandatory/tokenizer/tokenizer.c): `mandatory/tokenizer/tokenizer.c`
- [Token validation](https://github.com/mliligenes/42-minishell/blob/main/mandatory/tokenizer/token_validation.c): `mandatory/tokenizer/token_validation.c`
- [Token processing](https://github.com/mliligenes/42-minishell/blob/main/mandatory/processing/processing.c): `mandatory/processing/processing.c`
- [AST construction](https://github.com/mliligenes/42-minishell/blob/main/mandatory/parsing/ast_construction.c): `mandatory/parsing/ast_construction.c`

### Expansion and preparation

- [Expansion and wildcards](https://github.com/mliligenes/42-minishell/blob/main/mandatory/post_processing/expension.c): `mandatory/post_processing/expension.c`
- [Wildcard matching](https://github.com/mliligenes/42-minishell/blob/main/mandatory/post_processing/wildcard.c): `mandatory/post_processing/wildcard.c`

### Command execution

- [AST dispatch](https://github.com/mliligenes/42-minishell/blob/main/mandatory/main.c): `mandatory/main.c`
- [Command execution](https://github.com/mliligenes/42-minishell/blob/main/mandatory/execution/execute_cmd_handle.c): `mandatory/execution/execute_cmd_handle.c`
- [Pipes and logic](https://github.com/mliligenes/42-minishell/blob/main/mandatory/execution/pipe.c): `mandatory/execution/pipe.c`
- [Redirections](https://github.com/mliligenes/42-minishell/blob/main/mandatory/execution/redirections.c): `mandatory/execution/redirections.c`
- [Here-documents](https://github.com/mliligenes/42-minishell/blob/main/mandatory/heredoc/open_here_docs.c): `mandatory/heredoc/open_here_docs.c`
- [Shell builtins](https://github.com/mliligenes/42-minishell/blob/main/mandatory/builtins/ft_export.c): `mandatory/builtins/ft_export.c`

### Shell state and I/O

- [Environment](https://github.com/mliligenes/42-minishell/blob/main/mandatory/builtins/env_utils.c): `mandatory/builtins/env_utils.c`
- [Signal handling](https://github.com/mliligenes/42-minishell/blob/main/mandatory/signals.c): `mandatory/signals.c`

### Other components

- **Shell user**
- **Process and filesystem**

## Connections

- Shell user → Interactive loop: enters commands
- Program entry → Interactive loop: starts loop
- Interactive loop → Input parser: parses input
- Input parser → Lexer and tokenizer: creates tokens
- Input parser → Token validation: validates tokens
- Input parser → Token processing: extracts tokens
- Input parser → AST construction: builds tree
- Interactive loop → Here-documents: opens documents
- Interactive loop → AST dispatch: executes tree
- AST dispatch → Command execution: executes command
- AST dispatch → Pipes and logic: handles operators
- Command execution → Shell builtins: runs builtins
- Command execution → Redirections: applies redirects
- Command execution → Process and filesystem: runs processes
- Command execution → Environment: reads environment
- Shell builtins → Environment: updates environment
- Interactive loop → Signal handling: sets handlers
- Pipes and logic → Process and filesystem: connects processes
