# sozahra/minishell architecture

> Architecture diagram of the GitHub repository sozahra/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/sozahra/minishell
- Repository: https://github.com/sozahra/minishell

## Overview

MiniBG is an interactive Unix-style shell. The main workflow initializes shell state, builds an environment, accepts command lines, tokenizes and expands them, converts tokens into commands/redirections, then executes built-ins or child processes with pipes and file redirections. The tree and sampled sources support this overall structure; unsampled execution and parsing details are represented at their enclosing directories, and uncertain call wiring is omitted.

Main entry points: [`src/loop/loop.c`](https://github.com/sozahra/minishell/blob/main/src/loop/loop.c) (Interactive loop), [`src/exec/generic_exec.c`](https://github.com/sozahra/minishell/blob/main/src/exec/generic_exec.c) (Child execution), [`src/main.c`](https://github.com/sozahra/minishell/blob/main/src/main.c) (Shell entry), [`src/builtins/cd.c`](https://github.com/sozahra/minishell/blob/main/src/builtins/cd.c) (Directory changes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_shell["Shell lifecycle"]
  node_main["Shell entry<br/>[main.c]"]
  node_loop["Interactive loop<br/>[loop.c]"]
  node_signals["Signal handling<br/>[handle_signal.c]"]
end

subgraph group_parse["Command parsing"]
  node_tokenize["Tokenization<br/>[proc.c]"]
  node_tokens["Token list<br/>[add_tokens.c]"]
  node_expand["Expansion<br/>[expand.c]"]
  node_wildcards["Wildcard expansion<br/>[skibidi_split.c]"]
  node_command_parse["Command construction<br/>[commands_lst.c]"]
end

subgraph group_exec["Execution"]
  node_builtins["Shell built-ins<br/>[gestion_builtins.c]"]
  node_cd["Directory changes<br/>[cd.c]"]
  node_executor["Execution dispatch<br/>[exec.c]"]
  node_child_exec["Child execution<br/>[generic_exec.c]"]
  node_redirections["Redirection setup<br/>[redirections.c]"]
  node_file_open["File opening<br/>[open_fct.c]"]
  node_heredoc["Here-documents<br/>[heredoc.c]"]
  node_fd["Pipe and descriptors<br/>[fd_utils.c]"]
end

subgraph group_state["Shell state"]
  node_environment[("Environment list<br/>[build_env_list.c]")]
end

node_user(("Shell user"))
node_filesystem[("Filesystem")]
node_processes{{"OS processes"}}

node_user -->|"starts"| node_main
node_main -->|"builds"| node_environment
node_main -->|"starts"| node_loop
node_main -->|"installs"| node_signals
node_loop -->|"prompts"| node_user
node_loop -->|"tokenizes"| node_tokenize
node_tokenize -->|"adds tokens"| node_tokens
node_loop -->|"expands"| node_expand
node_loop -->|"expands patterns"| node_wildcards
node_loop -->|"builds commands"| node_command_parse
node_loop -->|"dispatches"| node_executor
node_executor -->|"runs built-in"| node_builtins
node_builtins -->|"handles cd"| node_cd
node_cd -->|"changes directory"| node_filesystem
node_cd -->|"updates variables"| node_environment
node_executor -->|"runs external command"| node_child_exec
node_child_exec -->|"reads variables"| node_environment
node_child_exec -->|"spawns and waits"| node_processes
node_child_exec -->|"sets up redirections"| node_redirections
node_redirections -->|"opens targets"| node_file_open
node_file_open -->|"reads or writes"| node_filesystem
node_redirections -->|"handles here-doc"| node_heredoc
node_heredoc -->|"reads delimiter input"| node_user
node_child_exec -->|"configures descriptors"| node_fd
node_fd -->|"connects pipelines"| node_processes

click node_main "https://github.com/sozahra/minishell/blob/main/src/main.c"
click node_loop "https://github.com/sozahra/minishell/blob/main/src/loop/loop.c"
click node_signals "https://github.com/sozahra/minishell/blob/main/src/signaux/handle_signal.c"
click node_tokenize "https://github.com/sozahra/minishell/blob/main/src/loop/proc.c"
click node_tokens "https://github.com/sozahra/minishell/blob/main/src/tokens/add_tokens.c"
click node_expand "https://github.com/sozahra/minishell/blob/main/src/loop/expand.c"
click node_wildcards "https://github.com/sozahra/minishell/blob/main/src/jokers/skibidi_split.c"
click node_command_parse "https://github.com/sozahra/minishell/blob/main/src/loop/commands_lst.c"
click node_environment "https://github.com/sozahra/minishell/blob/main/src/env/build_env_list.c"
click node_builtins "https://github.com/sozahra/minishell/blob/main/src/builtins/gestion_builtins.c"
click node_cd "https://github.com/sozahra/minishell/blob/main/src/builtins/cd.c"
click node_executor "https://github.com/sozahra/minishell/blob/main/src/exec.c"
click node_child_exec "https://github.com/sozahra/minishell/blob/main/src/exec/generic_exec.c"
click node_redirections "https://github.com/sozahra/minishell/blob/main/src/exec/redirections.c"
click node_file_open "https://github.com/sozahra/minishell/blob/main/src/exec/open_fct.c"
click node_heredoc "https://github.com/sozahra/minishell/blob/main/src/exec/heredoc.c"
click node_fd "https://github.com/sozahra/minishell/blob/main/src/exec/fd_utils.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_signals,node_user toneBlue
class node_tokenize,node_tokens,node_expand,node_wildcards,node_command_parse,node_filesystem toneAmber
class node_builtins,node_cd,node_executor,node_child_exec,node_redirections,node_file_open,node_heredoc,node_fd toneMint
class node_environment toneRose
class node_processes toneIndigo
```

## Components

### Shell lifecycle

- [Shell entry](https://github.com/sozahra/minishell/blob/main/src/main.c): `src/main.c`
- [Interactive loop](https://github.com/sozahra/minishell/blob/main/src/loop/loop.c): `src/loop/loop.c`
- [Signal handling](https://github.com/sozahra/minishell/blob/main/src/signaux/handle_signal.c): `src/signaux/handle_signal.c`

### Command parsing

- [Tokenization](https://github.com/sozahra/minishell/blob/main/src/loop/proc.c): `src/loop/proc.c`
- [Token list](https://github.com/sozahra/minishell/blob/main/src/tokens/add_tokens.c): `src/tokens/add_tokens.c`
- [Expansion](https://github.com/sozahra/minishell/blob/main/src/loop/expand.c): `src/loop/expand.c`
- [Wildcard expansion](https://github.com/sozahra/minishell/blob/main/src/jokers/skibidi_split.c): `src/jokers/skibidi_split.c`
- [Command construction](https://github.com/sozahra/minishell/blob/main/src/loop/commands_lst.c): `src/loop/commands_lst.c`

### Execution

- [Shell built-ins](https://github.com/sozahra/minishell/blob/main/src/builtins/gestion_builtins.c): `src/builtins/gestion_builtins.c`
- [Directory changes](https://github.com/sozahra/minishell/blob/main/src/builtins/cd.c): `src/builtins/cd.c`
- [Execution dispatch](https://github.com/sozahra/minishell/blob/main/src/exec.c): `src/exec.c`
- [Child execution](https://github.com/sozahra/minishell/blob/main/src/exec/generic_exec.c): `src/exec/generic_exec.c`
- [Redirection setup](https://github.com/sozahra/minishell/blob/main/src/exec/redirections.c): `src/exec/redirections.c`
- [File opening](https://github.com/sozahra/minishell/blob/main/src/exec/open_fct.c): `src/exec/open_fct.c`
- [Here-documents](https://github.com/sozahra/minishell/blob/main/src/exec/heredoc.c): `src/exec/heredoc.c`
- [Pipe and descriptors](https://github.com/sozahra/minishell/blob/main/src/exec/fd_utils.c): `src/exec/fd_utils.c`

### Shell state

- [Environment list](https://github.com/sozahra/minishell/blob/main/src/env/build_env_list.c): `src/env/build_env_list.c`

### Other components

- **Shell user**
- **Filesystem**
- **OS processes**

## Connections

- Shell user → Shell entry: starts
- Shell entry → Environment list: builds
- Shell entry → Interactive loop: starts
- Shell entry → Signal handling: installs
- Interactive loop → Shell user: prompts
- Interactive loop → Tokenization: tokenizes
- Tokenization → Token list: adds tokens
- Interactive loop → Expansion: expands
- Interactive loop → Wildcard expansion: expands patterns
- Interactive loop → Command construction: builds commands
- Interactive loop → Execution dispatch: dispatches
- Execution dispatch → Shell built-ins: runs built-in
- Shell built-ins → Directory changes: handles cd
- Directory changes → Filesystem: changes directory
- Directory changes → Environment list: updates variables
- Execution dispatch → Child execution: runs external command
- Child execution → Environment list: reads variables
- Child execution → OS processes: spawns and waits
- Child execution → Redirection setup: sets up redirections
- Redirection setup → File opening: opens targets
- File opening → Filesystem: reads or writes
- Redirection setup → Here-documents: handles here-doc
- Here-documents → Shell user: reads delimiter input
- Child execution → Pipe and descriptors: configures descriptors
- Pipe and descriptors → OS processes: connects pipelines
