# sohe1l/unix-shell architecture

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

- Interactive diagram: https://gitdiagram.com/sohe1l/unix-shell
- Repository: https://github.com/sohe1l/unix-shell

## Overview

This repository is a compact interactive shell. Its main workflow reads a command line, tokenizes and interprets arguments, pipes, redirects, and background markers, then handles built-ins or launches external programs. The single source file also implements prompt/path display, directory changes, child-process execution, and pipe forwarding. The README documents nested pipes and tilde support; source excerpts show the main parsing and execution mechanisms, though some documented combinations are not independently verified here.

Main entry points: [`myshell.c`](https://github.com/sohe1l/unix-shell/blob/master/myshell.c) (Process launcher)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_shell["Shell runtime"]
  node_input["Input reader<br/>[myshell.c]"]
  node_parser["Command parser<br/>[myshell.c]"]
  node_builtins["Built-in commands<br/>[myshell.c]"]
  node_prompt["Prompt and cwd<br/>[myshell.c]"]
  node_directory["Directory change<br/>[myshell.c]"]
end

subgraph group_execution["Command execution"]
  node_launcher["Process launcher<br/>[myshell.c]"]
  node_redirection["File redirection<br/>[myshell.c]"]
  node_pipes["Pipe forwarding<br/>[myshell.c]"]
end

node_user(("Terminal user"))
node_program["External program"]
node_files[("Redirected files")]

node_user -->|"enters commands"| node_input
node_input -->|"tokenizes input"| node_parser
node_parser -->|"dispatches built-ins"| node_builtins
node_builtins -->|"changes directory"| node_directory
node_parser -->|"launches commands"| node_launcher
node_launcher -->|"executes via execvp"| node_program
node_launcher -->|"applies redirects"| node_redirection
node_redirection -->|"opens files"| node_files
node_launcher -->|"sets up pipes"| node_pipes
node_pipes -->|"forwards pipe input"| node_launcher
node_prompt -->|"prints prompt"| node_user
node_builtins -->|"reads cwd"| node_prompt

click node_input "https://github.com/sohe1l/unix-shell/blob/master/myshell.c"
click node_parser "https://github.com/sohe1l/unix-shell/blob/master/myshell.c"
click node_builtins "https://github.com/sohe1l/unix-shell/blob/master/myshell.c"
click node_prompt "https://github.com/sohe1l/unix-shell/blob/master/myshell.c"
click node_directory "https://github.com/sohe1l/unix-shell/blob/master/myshell.c"
click node_launcher "https://github.com/sohe1l/unix-shell/blob/master/myshell.c"
click node_redirection "https://github.com/sohe1l/unix-shell/blob/master/myshell.c"
click node_pipes "https://github.com/sohe1l/unix-shell/blob/master/myshell.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_input,node_parser,node_builtins,node_prompt,node_directory,node_user toneBlue
class node_launcher,node_redirection,node_pipes,node_files toneAmber
class node_program toneIndigo
```

## Components

### Shell runtime

- [Input reader](https://github.com/sohe1l/unix-shell/blob/master/myshell.c): `myshell.c`
- [Command parser](https://github.com/sohe1l/unix-shell/blob/master/myshell.c): `myshell.c`
- [Built-in commands](https://github.com/sohe1l/unix-shell/blob/master/myshell.c): `myshell.c`
- [Prompt and cwd](https://github.com/sohe1l/unix-shell/blob/master/myshell.c): `myshell.c`
- [Directory change](https://github.com/sohe1l/unix-shell/blob/master/myshell.c): `myshell.c`

### Command execution

- [Process launcher](https://github.com/sohe1l/unix-shell/blob/master/myshell.c): `myshell.c`
- [File redirection](https://github.com/sohe1l/unix-shell/blob/master/myshell.c): `myshell.c`
- [Pipe forwarding](https://github.com/sohe1l/unix-shell/blob/master/myshell.c): `myshell.c`

### Other components

- **Terminal user**
- **External program**
- **Redirected files**

## Connections

- Terminal user → Input reader: enters commands (evidence: `myshell.c`)
- Input reader → Command parser: tokenizes input (evidence: `myshell.c`)
- Command parser → Built-in commands: dispatches built-ins (evidence: `myshell.c`)
- Built-in commands → Directory change: changes directory (evidence: `myshell.c`)
- Command parser → Process launcher: launches commands (evidence: `myshell.c`)
- Process launcher → External program: executes via execvp (evidence: `myshell.c`)
- Process launcher → File redirection: applies redirects (evidence: `myshell.c`)
- File redirection → Redirected files: opens files (evidence: `myshell.c`)
- Process launcher → Pipe forwarding: sets up pipes (evidence: `myshell.c`)
- Pipe forwarding → Process launcher: forwards pipe input (evidence: `myshell.c`)
- Prompt and cwd → Terminal user: prints prompt (evidence: `myshell.c`)
- Built-in commands → Prompt and cwd: reads cwd (evidence: `myshell.c`)
