# seeeedn/shell-task architecture

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

- Interactive diagram: https://gitdiagram.com/seeeedn/shell-task
- Repository: https://github.com/seeeedn/shell-task

## Overview

This repository implements an interactive Unix-style shell. A user enters a command; the shell reads and records the line, lexes and parses it into pipeline state, expands a leading alias, then runs a builtin or launches external commands with redirection, pipes, and optional background execution. Builtins include directory navigation, process signaling, and alias management. The generated parser’s semantic-action details and scanner rules were not shown, so their internal links to pipeline construction are omitted rather than inferred.

Main entry points: [`main.c`](https://github.com/seeeedn/shell-task/blob/master/main.c) (Shell loop), [`helper.c`](https://github.com/seeeedn/shell-task/blob/master/helper.c) (Builtins), [`alias.c`](https://github.com/seeeedn/shell-task/blob/master/alias.c) (Alias table), [`lex.yy.c`](https://github.com/seeeedn/shell-task/blob/master/lex.yy.c) (Command lexer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interaction["Interactive shell"]
  node_shell["Shell loop<br/>[main.c]"]
  node_history["Command history"]
end

subgraph group_language["Command language"]
  node_lexer["Command lexer<br/>[lex.yy.c]"]
  node_parser["Command parser<br/>[parse.tab.c]"]
  node_parser_tokens["Parser tokens<br/>[parse.tab.h]"]
end

subgraph group_execution["Command execution"]
  node_pipeline_state["Pipeline state<br/>[shell.c]"]
  node_builtins["Builtins<br/>[helper.c]"]
  node_external["External commands<br/>[main.c]"]
end

subgraph group_aliases["Alias management"]
  node_alias_builtin["Alias builtins<br/>[helper.c]"]
  node_alias_store["Alias table<br/>[alias.c]"]
end

node_user(("User"))
node_os["Operating system"]

node_user -->|"enters commands"| node_shell
node_shell -->|"reads and writes"| node_history
node_shell -->|"scans input"| node_lexer
node_shell -->|"parses input"| node_parser
node_lexer -.->|"uses tokens"| node_parser_tokens
node_parser -.->|"uses interface"| node_parser_tokens
node_shell -->|"initializes and clears"| node_pipeline_state
node_shell -->|"dispatches builtins"| node_builtins
node_shell -->|"launches commands"| node_external
node_external -->|"forks and executes"| node_os
node_builtins -->|"uses system calls"| node_os
node_builtins -->|"manages aliases"| node_alias_store
node_shell -->|"looks up aliases"| node_alias_store
node_alias_builtin -->|"updates alias table"| node_alias_store

click node_shell "https://github.com/seeeedn/shell-task/blob/master/main.c"
click node_history "https://github.com/seeeedn/shell-task/blob/master/history"
click node_lexer "https://github.com/seeeedn/shell-task/blob/master/lex.yy.c"
click node_parser "https://github.com/seeeedn/shell-task/blob/master/parse.tab.c"
click node_parser_tokens "https://github.com/seeeedn/shell-task/blob/master/parse.tab.h"
click node_pipeline_state "https://github.com/seeeedn/shell-task/blob/master/shell.c"
click node_builtins "https://github.com/seeeedn/shell-task/blob/master/helper.c"
click node_external "https://github.com/seeeedn/shell-task/blob/master/main.c"
click node_alias_builtin "https://github.com/seeeedn/shell-task/blob/master/helper.c"
click node_alias_store "https://github.com/seeeedn/shell-task/blob/master/alias.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_history,node_user toneBlue
class node_lexer,node_parser,node_parser_tokens toneAmber
class node_pipeline_state,node_builtins,node_external toneMint
class node_alias_builtin,node_alias_store toneRose
class node_os toneIndigo
```

## Components

### Interactive shell

- [Shell loop](https://github.com/seeeedn/shell-task/blob/master/main.c): `main.c`
- [Command history](https://github.com/seeeedn/shell-task/blob/master/history): `history`

### Command language

- [Command lexer](https://github.com/seeeedn/shell-task/blob/master/lex.yy.c): `lex.yy.c`
- [Command parser](https://github.com/seeeedn/shell-task/blob/master/parse.tab.c): `parse.tab.c`
- [Parser tokens](https://github.com/seeeedn/shell-task/blob/master/parse.tab.h): `parse.tab.h`

### Command execution

- [Pipeline state](https://github.com/seeeedn/shell-task/blob/master/shell.c): `shell.c`
- [Builtins](https://github.com/seeeedn/shell-task/blob/master/helper.c): `helper.c`
- [External commands](https://github.com/seeeedn/shell-task/blob/master/main.c): `main.c`

### Alias management

- [Alias builtins](https://github.com/seeeedn/shell-task/blob/master/helper.c): `helper.c`
- [Alias table](https://github.com/seeeedn/shell-task/blob/master/alias.c): `alias.c`

### Other components

- **User**
- **Operating system**

## Connections

- User → Shell loop: enters commands (evidence: `main.c`)
- Shell loop → Command history: reads and writes (evidence: `main.c`)
- Shell loop → Command lexer: scans input (evidence: `main.c`)
- Shell loop → Command parser: parses input (evidence: `main.c`)
- Command lexer → Parser tokens: uses tokens (evidence: `lex.yy.c`)
- Command parser → Parser tokens: uses interface (evidence: `parse.tab.c`)
- Shell loop → Pipeline state: initializes and clears (evidence: `main.c`)
- Shell loop → Builtins: dispatches builtins (evidence: `main.c`)
- Shell loop → External commands: launches commands (evidence: `main.c`)
- External commands → Operating system: forks and executes (evidence: `main.c`)
- Builtins → Operating system: uses system calls (evidence: `helper.c`)
- Builtins → Alias table: manages aliases (evidence: `helper.c`)
- Shell loop → Alias table: looks up aliases (evidence: `main.c`)
- Alias builtins → Alias table: updates alias table (evidence: `helper.c`)
