# the-to/holbertonschool-simple_shell architecture

> Architecture diagram of the GitHub repository the-to/holbertonschool-simple_shell, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/the-to/holbertonschool-simple_shell
- Repository: https://github.com/the-to/holbertonschool-simple_shell

## Overview

This is a small C UNIX shell. Its principal workflow reads interactive or piped input, tokenizes a command, handles the `exit` and `env` builtins, otherwise resolves an executable through PATH, then forks, executes it, waits, and reports its status. Environment lookup supports PATH resolution, while shared cleanup handles allocated memory. The graph follows relationships explicit in the README or sampled source; it does not infer unshown calls, such as a direct use of the cleanup helper on every runtime path.

Main entry points: [`main.c`](https://github.com/the-to/holbertonschool-simple_shell/blob/main/main.c) (Shell loop), [`builtins.c`](https://github.com/the-to/holbertonschool-simple_shell/blob/main/builtins.c) (Exit and env builtins), [`execute.c`](https://github.com/the-to/holbertonschool-simple_shell/blob/main/execute.c) (Process executor), [`wich.c`](https://github.com/the-to/holbertonschool-simple_shell/blob/main/wich.c) (Executable resolver)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["Input and parsing"]
  node_loop["Shell loop<br/>[main.c]"]
  node_tokenizer["Command tokenizer<br/>[split_string.c]"]
end

subgraph group_commands["Command handling"]
  node_dispatch["Builtin dispatch<br/>[main.c]"]
  node_builtins["Exit and env builtins<br/>[builtins.c]"]
  node_resolver["Executable resolver<br/>[wich.c]"]
  node_executor["Process executor<br/>[execute.c]"]
end

subgraph group_support["Runtime support"]
  node_environment["Environment lookup<br/>[_getenv.c]"]
  node_cleanup["Memory cleanup<br/>[freeall.c]"]
  node_interface["Shell declarations<br/>[main.h]"]
end

node_user(("Shell user"))
node_program["External command"]

node_user -->|"provides input"| node_loop
node_loop -->|"prints prompt"| node_user
node_loop -->|"tokenizes input"| node_tokenizer
node_loop -->|"checks builtins"| node_builtins
node_loop -->|"executes command"| node_executor
node_loop -->|"dispatches builtins"| node_dispatch
node_dispatch -->|"calls handlers"| node_builtins
node_executor -->|"resolves command"| node_resolver
node_resolver -->|"reads PATH"| node_environment
node_executor -->|"forks and execs"| node_program
node_builtins -->|"prints environment"| node_user
node_builtins -->|"exits shell"| node_loop
node_builtins -->|"frees memory"| node_cleanup
node_executor -->|"frees on failure"| node_cleanup

click node_loop "https://github.com/the-to/holbertonschool-simple_shell/blob/main/main.c"
click node_tokenizer "https://github.com/the-to/holbertonschool-simple_shell/blob/main/split_string.c"
click node_dispatch "https://github.com/the-to/holbertonschool-simple_shell/blob/main/main.c"
click node_builtins "https://github.com/the-to/holbertonschool-simple_shell/blob/main/builtins.c"
click node_resolver "https://github.com/the-to/holbertonschool-simple_shell/blob/main/wich.c"
click node_environment "https://github.com/the-to/holbertonschool-simple_shell/blob/main/_getenv.c"
click node_executor "https://github.com/the-to/holbertonschool-simple_shell/blob/main/execute.c"
click node_cleanup "https://github.com/the-to/holbertonschool-simple_shell/blob/main/freeall.c"
click node_interface "https://github.com/the-to/holbertonschool-simple_shell/blob/main/main.h"

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_tokenizer,node_user toneBlue
class node_dispatch,node_builtins,node_resolver,node_executor toneAmber
class node_environment,node_cleanup,node_interface toneMint
class node_program toneIndigo
```

## Components

### Input and parsing

- [Shell loop](https://github.com/the-to/holbertonschool-simple_shell/blob/main/main.c): `main.c`
- [Command tokenizer](https://github.com/the-to/holbertonschool-simple_shell/blob/main/split_string.c): `split_string.c`

### Command handling

- [Builtin dispatch](https://github.com/the-to/holbertonschool-simple_shell/blob/main/main.c): `main.c`
- [Exit and env builtins](https://github.com/the-to/holbertonschool-simple_shell/blob/main/builtins.c): `builtins.c`
- [Executable resolver](https://github.com/the-to/holbertonschool-simple_shell/blob/main/wich.c): `wich.c`
- [Process executor](https://github.com/the-to/holbertonschool-simple_shell/blob/main/execute.c): `execute.c`

### Runtime support

- [Environment lookup](https://github.com/the-to/holbertonschool-simple_shell/blob/main/_getenv.c): `_getenv.c`
- [Memory cleanup](https://github.com/the-to/holbertonschool-simple_shell/blob/main/freeall.c): `freeall.c`
- [Shell declarations](https://github.com/the-to/holbertonschool-simple_shell/blob/main/main.h): `main.h`

### Other components

- **Shell user**
- **External command**

## Connections

- Shell user → Shell loop: provides input (evidence: `README.md`)
- Shell loop → Shell user: prints prompt (evidence: `main.c`)
- Shell loop → Command tokenizer: tokenizes input (evidence: `main.c`)
- Shell loop → Exit and env builtins: checks builtins (evidence: `main.c`)
- Shell loop → Process executor: executes command (evidence: `main.c`)
- Shell loop → Builtin dispatch: dispatches builtins (evidence: `main.c`)
- Builtin dispatch → Exit and env builtins: calls handlers (evidence: `main.c`)
- Process executor → Executable resolver: resolves command (evidence: `execute.c`)
- Executable resolver → Environment lookup: reads PATH (evidence: `wich.c`)
- Process executor → External command: forks and execs (evidence: `execute.c`)
- Exit and env builtins → Shell user: prints environment (evidence: `builtins.c`)
- Exit and env builtins → Shell loop: exits shell (evidence: `builtins.c`)
- Exit and env builtins → Memory cleanup: frees memory (evidence: `builtins.c`)
- Process executor → Memory cleanup: frees on failure (evidence: `execute.c`)
