# ahunter954/42sh architecture

> Architecture diagram of the GitHub repository ahunter954/42sh, 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/ahunter954/42sh
- Repository: https://github.com/ahunter954/42sh

## Overview

42sh is a small command-line shell. Its main workflow selects stdin, a script file, or `-c` input; parses commands into an AST; executes that tree; and frees it before reading the next command. The sampled code supports command lists, `if`/`then`/`else`, pipelines, output redirection, and the `true`/`false` builtins. The graph follows visible calls; the README provides no additional capability detail, and unsampled modules are not inferred.

Main entry points: [`src/main.c`](https://github.com/ahunter954/42sh/blob/main/src/main.c) (Shell loop), [`src/parser.c`](https://github.com/ahunter954/42sh/blob/main/src/parser.c) (Parsing), [`src/exec.c`](https://github.com/ahunter954/42sh/blob/main/src/exec.c) (AST execution), [`src/ast.h`](https://github.com/ahunter954/42sh/blob/main/src/ast.h) (AST model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Shell interface"]
  node_main["Shell loop<br/>[main.c]"]
  node_legacy_header["Legacy interface<br/>[42sh.h]"]
end

subgraph group_language["Language processing"]
  node_lexer["Tokenization<br/>[lexer.c]"]
  node_parser["Parsing<br/>[parser.c]"]
  node_ast_model["AST model<br/>[ast.h]"]
  node_ast_memory["AST construction and cleanup<br/>[ast.c]"]
end

subgraph group_runtime["Execution runtime"]
  node_executor["AST execution<br/>[exec.c]"]
end

node_user(("Shell user"))
node_processes["External commands"]
node_filesystem["Output files"]

node_user -->|"provides input"| node_main
node_main -->|"parses input"| node_parser
node_parser -->|"requests tokens"| node_lexer
node_parser -->|"builds nodes"| node_ast_memory
node_parser -->|"uses node types"| node_ast_model
node_main -->|"executes tree"| node_executor
node_main -->|"frees tree"| node_ast_memory
node_executor -->|"dispatches node types"| node_ast_model
node_executor -->|"runs commands"| node_processes
node_executor -->|"writes redirected output"| node_filesystem
node_main -->|"includes interface"| node_legacy_header

click node_main "https://github.com/ahunter954/42sh/blob/main/src/main.c"
click node_legacy_header "https://github.com/ahunter954/42sh/blob/main/src/42sh.h"
click node_lexer "https://github.com/ahunter954/42sh/blob/main/src/lexer.c"
click node_parser "https://github.com/ahunter954/42sh/blob/main/src/parser.c"
click node_ast_model "https://github.com/ahunter954/42sh/blob/main/src/ast.h"
click node_ast_memory "https://github.com/ahunter954/42sh/blob/main/src/ast.c"
click node_executor "https://github.com/ahunter954/42sh/blob/main/src/exec.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_main,node_legacy_header,node_user toneBlue
class node_lexer,node_parser,node_ast_model,node_ast_memory toneAmber
class node_executor toneMint
class node_processes,node_filesystem toneIndigo
```

## Components

### Shell interface

- [Shell loop](https://github.com/ahunter954/42sh/blob/main/src/main.c): `src/main.c`
- [Legacy interface](https://github.com/ahunter954/42sh/blob/main/src/42sh.h): `src/42sh.h`

### Language processing

- [Tokenization](https://github.com/ahunter954/42sh/blob/main/src/lexer.c): `src/lexer.c`
- [Parsing](https://github.com/ahunter954/42sh/blob/main/src/parser.c): `src/parser.c`
- [AST model](https://github.com/ahunter954/42sh/blob/main/src/ast.h): `src/ast.h`
- [AST construction and cleanup](https://github.com/ahunter954/42sh/blob/main/src/ast.c): `src/ast.c`

### Execution runtime

- [AST execution](https://github.com/ahunter954/42sh/blob/main/src/exec.c): `src/exec.c`

### Other components

- **Shell user**
- **External commands**
- **Output files**

## Connections

- Shell user → Shell loop: provides input (evidence: `src/main.c`)
- Shell loop → Parsing: parses input (evidence: `src/main.c`)
- Parsing → Tokenization: requests tokens (evidence: `src/parser.c`)
- Parsing → AST construction and cleanup: builds nodes (evidence: `src/parser.c`)
- Parsing → AST model: uses node types (evidence: `src/parser.c`)
- Shell loop → AST execution: executes tree (evidence: `src/main.c`)
- Shell loop → AST construction and cleanup: frees tree (evidence: `src/main.c`)
- AST execution → AST model: dispatches node types (evidence: `src/exec.c`)
- AST execution → External commands: runs commands (evidence: `src/exec.c`)
- AST execution → Output files: writes redirected output (evidence: `src/exec.c`)
- Shell loop → Legacy interface: includes interface (evidence: `src/main.c`)
