# r4yl-dev/minishell architecture

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

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

## Overview

MiniShell is an interactive Bash-like shell. Its main loop initializes shell state, reads a prompt, then lexes, parses, expands, and executes each nonempty command; EOF exits. Execution handles external programs, builtins, pipes, and redirections, while signal handling and shell variables support the session. The README documents the user-visible stages and capabilities; sampled source confirms the main-loop dispatch, parser tree construction, and execution behavior. Other subsystem links below reflect documented workflow, not inspection of unsampled implementations.

Main entry points: [`main.c`](https://github.com/r4yl-dev/minishell/blob/main/main.c) (Shell loop), [`exec/exec_env.c`](https://github.com/r4yl-dev/minishell/blob/main/exec/exec_env.c) (Command dispatch), [`exec/exec.c`](https://github.com/r4yl-dev/minishell/blob/main/exec/exec.c) (Executor), [`prompt/prompt.c`](https://github.com/r4yl-dev/minishell/blob/main/prompt/prompt.c) (Prompt input)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_session["Interactive session"]
  node_prompt["Prompt input<br/>[prompt.c]"]
  node_mainloop["Shell loop<br/>[main.c]"]
  node_signals["Signal handling<br/>[handle_sigint.c]"]
end

subgraph group_language["Command processing"]
  node_lexer["Lexer<br/>[lexer.c]"]
  node_tokens["Token list<br/>[dyntklist.c]"]
  node_parser["Parser<br/>[parser.c]"]
  node_syntax["Command tree<br/>[dyntree.c]"]
  node_expand["Expansion<br/>[expand.c]"]
end

subgraph group_runtime["Execution runtime"]
  node_exec["Executor<br/>[exec.c]"]
  node_command_exec["Command dispatch<br/>[exec_env.c]"]
  node_paths["Executable lookup<br/>[get_cmd_path.c]"]
  node_io["Pipes and redirects<br/>[get_infd.c]"]
  node_heredoc["Here-doc input<br/>[make_heredoc.c]"]
  node_builtins["Builtin commands<br/>[lstbuiltins_exec.c]"]
end

subgraph group_state["Shell state"]
  node_vars[("Shell variables<br/>[grpvar.c]")]
  node_context["Shell context<br/>[ctx.c]"]
  node_environment["Process environment<br/>[make_env.c]"]
end

node_user(("Shell user"))
node_terminal["Terminal and files"]

node_user -->|"enters commands"| node_prompt
node_mainloop -->|"reads input"| node_prompt
node_prompt -.->|"returns line"| node_mainloop
node_mainloop -->|"sets signal mode"| node_signals
node_mainloop -->|"lexes input"| node_lexer
node_lexer -.->|"builds tokens"| node_tokens
node_mainloop -->|"parses tokens"| node_parser
node_parser -->|"builds tree"| node_syntax
node_mainloop -->|"expands command"| node_expand
node_mainloop -->|"executes tree"| node_exec
node_exec -.->|"dispatches work"| node_command_exec
node_command_exec -.->|"resolves programs"| node_paths
node_command_exec -->|"runs builtins"| node_builtins
node_exec -.->|"configures I/O"| node_io
node_exec -.->|"collects here-docs"| node_heredoc
node_builtins -.->|"updates variables"| node_vars
node_mainloop -->|"initializes context"| node_context
node_context -.->|"holds shell state"| node_vars
node_command_exec -->|"builds process env"| node_environment
node_prompt -.->|"reads terminal"| node_terminal
node_command_exec -.->|"runs programs and I/O"| node_terminal

click node_prompt "https://github.com/r4yl-dev/minishell/blob/main/prompt/prompt.c"
click node_mainloop "https://github.com/r4yl-dev/minishell/blob/main/main.c"
click node_signals "https://github.com/r4yl-dev/minishell/blob/main/signals/handle_sigint.c"
click node_lexer "https://github.com/r4yl-dev/minishell/blob/main/lexer/lexer.c"
click node_tokens "https://github.com/r4yl-dev/minishell/blob/main/lexer/dyntklist.c"
click node_parser "https://github.com/r4yl-dev/minishell/blob/main/parser/parser.c"
click node_syntax "https://github.com/r4yl-dev/minishell/blob/main/parser/dyntree.c"
click node_expand "https://github.com/r4yl-dev/minishell/blob/main/expand/expand.c"
click node_exec "https://github.com/r4yl-dev/minishell/blob/main/exec/exec.c"
click node_command_exec "https://github.com/r4yl-dev/minishell/blob/main/exec/exec_env.c"
click node_paths "https://github.com/r4yl-dev/minishell/blob/main/exec/get_cmd_path.c"
click node_io "https://github.com/r4yl-dev/minishell/blob/main/exec/get_infd.c"
click node_heredoc "https://github.com/r4yl-dev/minishell/blob/main/exec/make_heredoc.c"
click node_builtins "https://github.com/r4yl-dev/minishell/blob/main/builtins/lstbuiltins_exec.c"
click node_vars "https://github.com/r4yl-dev/minishell/blob/main/vars/grpvar.c"
click node_context "https://github.com/r4yl-dev/minishell/blob/main/ctx/ctx.c"
click node_environment "https://github.com/r4yl-dev/minishell/blob/main/exec/make_env.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_prompt,node_mainloop,node_signals,node_user toneBlue
class node_lexer,node_tokens,node_parser,node_syntax,node_expand toneAmber
class node_exec,node_command_exec,node_paths,node_io,node_heredoc,node_builtins toneMint
class node_vars,node_context,node_environment toneRose
class node_terminal toneIndigo
```

## Components

### Interactive session

- [Prompt input](https://github.com/r4yl-dev/minishell/blob/main/prompt/prompt.c): `prompt/prompt.c`
- [Shell loop](https://github.com/r4yl-dev/minishell/blob/main/main.c): `main.c`
- [Signal handling](https://github.com/r4yl-dev/minishell/blob/main/signals/handle_sigint.c): `signals/handle_sigint.c`

### Command processing

- [Lexer](https://github.com/r4yl-dev/minishell/blob/main/lexer/lexer.c): `lexer/lexer.c`
- [Token list](https://github.com/r4yl-dev/minishell/blob/main/lexer/dyntklist.c): `lexer/dyntklist.c`
- [Parser](https://github.com/r4yl-dev/minishell/blob/main/parser/parser.c): `parser/parser.c`
- [Command tree](https://github.com/r4yl-dev/minishell/blob/main/parser/dyntree.c): `parser/dyntree.c`
- [Expansion](https://github.com/r4yl-dev/minishell/blob/main/expand/expand.c): `expand/expand.c`

### Execution runtime

- [Executor](https://github.com/r4yl-dev/minishell/blob/main/exec/exec.c): `exec/exec.c`
- [Command dispatch](https://github.com/r4yl-dev/minishell/blob/main/exec/exec_env.c): `exec/exec_env.c`
- [Executable lookup](https://github.com/r4yl-dev/minishell/blob/main/exec/get_cmd_path.c): `exec/get_cmd_path.c`
- [Pipes and redirects](https://github.com/r4yl-dev/minishell/blob/main/exec/get_infd.c): `exec/get_infd.c`
- [Here-doc input](https://github.com/r4yl-dev/minishell/blob/main/exec/make_heredoc.c): `exec/make_heredoc.c`
- [Builtin commands](https://github.com/r4yl-dev/minishell/blob/main/builtins/lstbuiltins_exec.c): `builtins/lstbuiltins_exec.c`

### Shell state

- [Shell variables](https://github.com/r4yl-dev/minishell/blob/main/vars/grpvar.c): `vars/grpvar.c`
- [Shell context](https://github.com/r4yl-dev/minishell/blob/main/ctx/ctx.c): `ctx/ctx.c`
- [Process environment](https://github.com/r4yl-dev/minishell/blob/main/exec/make_env.c): `exec/make_env.c`

### Other components

- **Shell user**
- **Terminal and files**

## Connections

- Shell user → Prompt input: enters commands
- Shell loop → Prompt input: reads input (evidence: `main.c`)
- Prompt input → Shell loop: returns line
- Shell loop → Signal handling: sets signal mode (evidence: `main.c`)
- Shell loop → Lexer: lexes input (evidence: `main.c`)
- Lexer → Token list: builds tokens
- Shell loop → Parser: parses tokens (evidence: `main.c`)
- Parser → Command tree: builds tree (evidence: `parser/parser.c`)
- Shell loop → Expansion: expands command (evidence: `main.c`)
- Shell loop → Executor: executes tree (evidence: `main.c`)
- Executor → Command dispatch: dispatches work
- Command dispatch → Executable lookup: resolves programs
- Command dispatch → Builtin commands: runs builtins (evidence: `exec/exec_env.c`)
- Executor → Pipes and redirects: configures I/O
- Executor → Here-doc input: collects here-docs
- Builtin commands → Shell variables: updates variables
- Shell loop → Shell context: initializes context (evidence: `main.c`)
- Shell context → Shell variables: holds shell state
- Command dispatch → Process environment: builds process env (evidence: `exec/exec_env.c`)
- Prompt input → Terminal and files: reads terminal
- Command dispatch → Terminal and files: runs programs and I/O
