# jsenk347/homebrew-shell architecture

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

- Interactive diagram: https://gitdiagram.com/jsenk347/homebrew-shell
- Repository: https://github.com/jsenk347/homebrew-shell

## Overview

homebrew-shell is a small Linux command shell. Its main workflow reads a line, parses it into a job containing pipeline stages and optional redirections/background mode, launches the stages, then waits for foreground children or reaps background ones. The main product branches are parsing, process execution, and signal handling, with a small custom allocation/string layer supporting them. The README documents the shell’s purpose and launch command; the sampled source confirms these runtime features. No additional capabilities are documented.

Main entry points: [`run_job.c`](https://github.com/jsenk347/homebrew-shell/blob/main/run_job.c) (Job runner), [`mysh.c`](https://github.com/jsenk347/homebrew-shell/blob/main/mysh.c) (Shell loop), [`commands.c`](https://github.com/jsenk347/homebrew-shell/blob/main/commands.c) (Job parser), [`myheap.c`](https://github.com/jsenk347/homebrew-shell/blob/main/myheap.c) (Heap allocator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interaction["Shell interaction"]
  node_shell["Shell loop<br/>[mysh.c]"]
  node_line_input["Line input<br/>[commands.c]"]
  node_signal_control["Signal control<br/>[mysh.c]"]
end

subgraph group_parsing["Command parsing"]
  node_job_model["Job model<br/>[jobs.h]"]
  node_parser["Job parser<br/>[commands.c]"]
end

subgraph group_execution["Job execution"]
  node_runner["Job runner<br/>[run_job.c]"]
  node_redirections["Redirection I/O<br/>[run_job.c]"]
  node_pipe_setup["Pipe setup<br/>[run_job.c]"]
  node_child_io["Stage I/O<br/>[run_job.c]"]
  node_child_start["Child launcher<br/>[commands.c]"]
  node_path_resolver["Command path<br/>[commands.c]"]
  node_foreground_wait["Foreground wait<br/>[run_job.c]"]
end

subgraph group_support["Runtime support"]
  node_allocator["Heap allocator<br/>[myheap.c]"]
  node_strings["String helpers<br/>[mystring.c]"]
end

node_user(("Shell user"))
node_programs{{"External programs"}}
node_os{{"Linux process services"}}
node_file_system[("Redirection files")]

node_user -->|"enters commands"| node_line_input
node_shell -->|"reads line"| node_line_input
node_shell -->|"parses job"| node_parser
node_parser -->|"fills job"| node_job_model
node_parser -->|"allocates tokens"| node_allocator
node_parser -->|"measures strings"| node_strings
node_shell -->|"runs job"| node_runner
node_runner -->|"opens files"| node_redirections
node_redirections -->|"reads or writes"| node_file_system
node_runner -->|"creates pipes"| node_pipe_setup
node_pipe_setup -->|"creates processes"| node_os
node_runner -->|"assigns descriptors"| node_child_io
node_runner -->|"launches stages"| node_child_start
node_child_start -->|"resolves command"| node_path_resolver
node_child_start -->|"forks and executes"| node_os
node_child_start -->|"executes program"| node_programs
node_path_resolver -->|"allocates path"| node_allocator
node_runner -->|"waits if foreground"| node_foreground_wait
node_foreground_wait -->|"waits for children"| node_os
node_shell -->|"sets handlers"| node_signal_control
node_signal_control -->|"handles signals"| node_os
node_os -->|"dispatches SIGCHLD"| node_signal_control

click node_shell "https://github.com/jsenk347/homebrew-shell/blob/main/mysh.c"
click node_line_input "https://github.com/jsenk347/homebrew-shell/blob/main/commands.c"
click node_job_model "https://github.com/jsenk347/homebrew-shell/blob/main/jobs.h"
click node_parser "https://github.com/jsenk347/homebrew-shell/blob/main/commands.c"
click node_allocator "https://github.com/jsenk347/homebrew-shell/blob/main/myheap.c"
click node_strings "https://github.com/jsenk347/homebrew-shell/blob/main/mystring.c"
click node_runner "https://github.com/jsenk347/homebrew-shell/blob/main/run_job.c"
click node_redirections "https://github.com/jsenk347/homebrew-shell/blob/main/run_job.c"
click node_pipe_setup "https://github.com/jsenk347/homebrew-shell/blob/main/run_job.c"
click node_child_io "https://github.com/jsenk347/homebrew-shell/blob/main/run_job.c"
click node_child_start "https://github.com/jsenk347/homebrew-shell/blob/main/commands.c"
click node_path_resolver "https://github.com/jsenk347/homebrew-shell/blob/main/commands.c"
click node_foreground_wait "https://github.com/jsenk347/homebrew-shell/blob/main/run_job.c"
click node_signal_control "https://github.com/jsenk347/homebrew-shell/blob/main/mysh.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_shell,node_line_input,node_signal_control,node_user toneBlue
class node_job_model,node_parser,node_file_system toneAmber
class node_runner,node_redirections,node_pipe_setup,node_child_io,node_child_start,node_path_resolver,node_foreground_wait toneMint
class node_allocator,node_strings toneRose
class node_programs,node_os toneIndigo
```

## Components

### Shell interaction

- [Shell loop](https://github.com/jsenk347/homebrew-shell/blob/main/mysh.c): `mysh.c`
- [Line input](https://github.com/jsenk347/homebrew-shell/blob/main/commands.c): `commands.c`
- [Signal control](https://github.com/jsenk347/homebrew-shell/blob/main/mysh.c): `mysh.c`

### Command parsing

- [Job model](https://github.com/jsenk347/homebrew-shell/blob/main/jobs.h): `jobs.h`
- [Job parser](https://github.com/jsenk347/homebrew-shell/blob/main/commands.c): `commands.c`

### Job execution

- [Job runner](https://github.com/jsenk347/homebrew-shell/blob/main/run_job.c): `run_job.c`
- [Redirection I/O](https://github.com/jsenk347/homebrew-shell/blob/main/run_job.c): `run_job.c`
- [Pipe setup](https://github.com/jsenk347/homebrew-shell/blob/main/run_job.c): `run_job.c`
- [Stage I/O](https://github.com/jsenk347/homebrew-shell/blob/main/run_job.c): `run_job.c`
- [Child launcher](https://github.com/jsenk347/homebrew-shell/blob/main/commands.c): `commands.c`
- [Command path](https://github.com/jsenk347/homebrew-shell/blob/main/commands.c): `commands.c`
- [Foreground wait](https://github.com/jsenk347/homebrew-shell/blob/main/run_job.c): `run_job.c`

### Runtime support

- [Heap allocator](https://github.com/jsenk347/homebrew-shell/blob/main/myheap.c): `myheap.c`
- [String helpers](https://github.com/jsenk347/homebrew-shell/blob/main/mystring.c): `mystring.c`

### Other components

- **Shell user**
- **External programs**
- **Linux process services**
- **Redirection files**

## Connections

- Shell user → Line input: enters commands
- Shell loop → Line input: reads line
- Shell loop → Job parser: parses job
- Job parser → Job model: fills job
- Job parser → Heap allocator: allocates tokens
- Job parser → String helpers: measures strings
- Shell loop → Job runner: runs job
- Job runner → Redirection I/O: opens files
- Redirection I/O → Redirection files: reads or writes
- Job runner → Pipe setup: creates pipes
- Pipe setup → Linux process services: creates processes
- Job runner → Stage I/O: assigns descriptors
- Job runner → Child launcher: launches stages
- Child launcher → Command path: resolves command
- Child launcher → Linux process services: forks and executes
- Child launcher → External programs: executes program
- Command path → Heap allocator: allocates path
- Job runner → Foreground wait: waits if foreground
- Foreground wait → Linux process services: waits for children
- Shell loop → Signal control: sets handlers
- Signal control → Linux process services: handles signals
- Linux process services → Signal control: dispatches SIGCHLD
