# tresor850/minshell2--42sh architecture

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

- Interactive diagram: https://gitdiagram.com/tresor850/minshell2--42sh
- Repository: https://github.com/tresor850/minshell2--42sh

## Overview

This repository implements a small interactive Unix shell: it reads command lines, dispatches commands, supports built-ins and environment changes, and executes external programs with redirection and pipeline support. The main loop and command dispatcher are visible in excerpts; some domain-stage implementations are indexed but not sampled, so uncertain dispatch links are omitted or marked unverified.

Main entry points: [`src/process_command.c`](https://github.com/tresor850/minshell2--42sh/blob/main/src/process_command.c) (Single command), [`src/execution.c`](https://github.com/tresor850/minshell2--42sh/blob/main/src/execution.c) (External execution), [`src/handle_command.c`](https://github.com/tresor850/minshell2--42sh/blob/main/src/handle_command.c) (Command dispatcher), [`src/main.c`](https://github.com/tresor850/minshell2--42sh/blob/main/src/main.c) (Input loop)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["Shell input"]
  node_loop["Input loop<br/>[main.c]"]
end

subgraph group_commands["Command handling"]
  node_dispatch["Command dispatcher<br/>[handle_command.c]"]
  node_split["Semicolon splitting<br/>[semicolon.c]"]
  node_single["Single command<br/>[process_command.c]"]
  node_builtins["Built-ins<br/>[handle_command.c]"]
  node_tokenize["Command tokenization"]
  node_pipesplit["Pipe splitting"]
end

subgraph group_runtime["Execution and state"]
  node_cd["Directory changes<br/>[change_directory.c]"]
  node_env[("Environment list<br/>[set_env.c]")]
  node_envtab["Environment conversion<br/>[list_to_tab.c]"]
  node_lookup["Command lookup<br/>[find_command.c]"]
  node_parser["Executable path check<br/>[parser.c]"]
  node_execute["External execution<br/>[execution.c]"]
  node_redirect["I/O redirection<br/>[redirections.c]"]
  node_pipeline["Pipeline execution<br/>[pipe.c]"]
end

node_user(("Shell user"))

node_user -->|"enters commands"| node_loop
node_loop -->|"submits line"| node_dispatch
node_dispatch -->|"splits commands"| node_split
node_dispatch -->|"processes each"| node_single
node_builtins -->|"changes directory"| node_cd
node_builtins -->|"updates variables"| node_env
node_dispatch -->|"serializes environment"| node_envtab
node_execute -->|"finds executable"| node_lookup
node_execute -->|"applies redirection"| node_redirect
node_execute -->|"tokenizes input"| node_tokenize
node_lookup -.->|"checks candidate paths"| node_parser
node_single -.->|"dispatches built-ins"| node_builtins
node_single -.->|"runs external command"| node_execute
node_single -.->|"splits pipeline"| node_pipesplit
node_single -.->|"runs pipeline"| node_pipeline
node_pipeline -->|"executes stages"| node_execute

click node_loop "https://github.com/tresor850/minshell2--42sh/blob/main/src/main.c"
click node_dispatch "https://github.com/tresor850/minshell2--42sh/blob/main/src/handle_command.c"
click node_split "https://github.com/tresor850/minshell2--42sh/blob/main/src/semicolon.c"
click node_single "https://github.com/tresor850/minshell2--42sh/blob/main/src/process_command.c"
click node_builtins "https://github.com/tresor850/minshell2--42sh/blob/main/src/handle_command.c"
click node_cd "https://github.com/tresor850/minshell2--42sh/blob/main/src/change_directory.c"
click node_env "https://github.com/tresor850/minshell2--42sh/blob/main/src/set_env.c"
click node_envtab "https://github.com/tresor850/minshell2--42sh/blob/main/src/list_to_tab.c"
click node_tokenize "https://github.com/tresor850/minshell2--42sh/blob/main/src/my_str_to_word_array.c"
click node_lookup "https://github.com/tresor850/minshell2--42sh/blob/main/src/find_command.c"
click node_parser "https://github.com/tresor850/minshell2--42sh/blob/main/src/parser.c"
click node_execute "https://github.com/tresor850/minshell2--42sh/blob/main/src/execution.c"
click node_redirect "https://github.com/tresor850/minshell2--42sh/blob/main/src/redirections.c"
click node_pipesplit "https://github.com/tresor850/minshell2--42sh/blob/main/src/mys_str_to_word_array.c"
click node_pipeline "https://github.com/tresor850/minshell2--42sh/blob/main/src/pipe.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_loop,node_user toneBlue
class node_dispatch,node_split,node_single,node_builtins,node_tokenize,node_pipesplit toneAmber
class node_cd,node_env,node_envtab,node_lookup,node_parser,node_execute,node_redirect,node_pipeline toneMint
```

## Components

### Shell input

- [Input loop](https://github.com/tresor850/minshell2--42sh/blob/main/src/main.c): `src/main.c`

### Command handling

- [Command dispatcher](https://github.com/tresor850/minshell2--42sh/blob/main/src/handle_command.c): `src/handle_command.c`
- [Semicolon splitting](https://github.com/tresor850/minshell2--42sh/blob/main/src/semicolon.c): `src/semicolon.c`
- [Single command](https://github.com/tresor850/minshell2--42sh/blob/main/src/process_command.c): `src/process_command.c`
- [Built-ins](https://github.com/tresor850/minshell2--42sh/blob/main/src/handle_command.c): `src/handle_command.c`
- [Command tokenization](https://github.com/tresor850/minshell2--42sh/blob/main/src/my_str_to_word_array.c): `src/my_str_to_word_array.c`
- [Pipe splitting](https://github.com/tresor850/minshell2--42sh/blob/main/src/mys_str_to_word_array.c): `src/mys_str_to_word_array.c`

### Execution and state

- [Directory changes](https://github.com/tresor850/minshell2--42sh/blob/main/src/change_directory.c): `src/change_directory.c`
- [Environment list](https://github.com/tresor850/minshell2--42sh/blob/main/src/set_env.c): `src/set_env.c`
- [Environment conversion](https://github.com/tresor850/minshell2--42sh/blob/main/src/list_to_tab.c): `src/list_to_tab.c`
- [Command lookup](https://github.com/tresor850/minshell2--42sh/blob/main/src/find_command.c): `src/find_command.c`
- [Executable path check](https://github.com/tresor850/minshell2--42sh/blob/main/src/parser.c): `src/parser.c`
- [External execution](https://github.com/tresor850/minshell2--42sh/blob/main/src/execution.c): `src/execution.c`
- [I/O redirection](https://github.com/tresor850/minshell2--42sh/blob/main/src/redirections.c): `src/redirections.c`
- [Pipeline execution](https://github.com/tresor850/minshell2--42sh/blob/main/src/pipe.c): `src/pipe.c`

### Other components

- **Shell user**

## Connections

- Shell user → Input loop: enters commands (evidence: `src/main.c`)
- Input loop → Command dispatcher: submits line (evidence: `src/main.c`)
- Command dispatcher → Semicolon splitting: splits commands (evidence: `src/handle_command.c`)
- Command dispatcher → Single command: processes each (evidence: `src/handle_command.c`)
- Built-ins → Directory changes: changes directory (evidence: `src/handle_command.c`)
- Built-ins → Environment list: updates variables (evidence: `src/handle_command.c`)
- Command dispatcher → Environment conversion: serializes environment (evidence: `src/handle_command.c`)
- External execution → Command lookup: finds executable (evidence: `src/execution.c`)
- External execution → I/O redirection: applies redirection (evidence: `src/execution.c`)
- External execution → Command tokenization: tokenizes input (evidence: `src/execution.c`)
- Command lookup → Executable path check: checks candidate paths
- Single command → Built-ins: dispatches built-ins
- Single command → External execution: runs external command
- Single command → Pipe splitting: splits pipeline
- Single command → Pipeline execution: runs pipeline
- Pipeline execution → External execution: executes stages (evidence: `src/pipe.c`)
