# kibet-rotich/shell-using-c- architecture

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

- Interactive diagram: https://gitdiagram.com/kibet-rotich/shell-using-c-
- Repository: https://github.com/kibet-rotich/shell-using-c-

## Overview

This repository is a small C++ shell starter. Its runtime workflow reads a command line, tokenizes it, applies stdout redirection when requested, dispatches builtins or an external command, then restores stdout. Builtins cover exit, type lookup, echo, working-directory display, and directory changes; external commands are resolved through PATH and run in a child process. The only substantial runtime source is src/main.cpp, so the graph keeps these responsibilities together. Relationships are supported by that excerpt; external command execution is shown as process interaction.

Main entry points: [`src/main.cpp`](https://github.com/kibet-rotich/shell-using-c-/blob/master/src/main.cpp) (Command dispatch)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_shell["Shell runtime"]
  node_runtime["Shell loop<br/>[main.cpp]"]
  node_tokenizer["Command tokenizer<br/>[main.cpp]"]
  node_dispatcher["Command dispatch<br/>[main.cpp]"]
  node_builtins["Builtin commands<br/>[main.cpp]"]
  node_redirect["Stdout redirection<br/>[main.cpp]"]
  node_resolver["PATH resolver<br/>[main.cpp]"]
end

subgraph group_host["Host environment"]
  node_child["External process<br/>[main.cpp]"]
  node_environment["Environment and filesystem"]
end

node_user(("Shell user"))

node_user -->|"enters command"| node_runtime
node_runtime -->|"tokenizes input"| node_tokenizer
node_runtime -->|"extracts redirect"| node_redirect
node_runtime -->|"dispatches command"| node_dispatcher
node_dispatcher -->|"calls builtin"| node_builtins
node_dispatcher -->|"calls for external"| node_resolver
node_dispatcher -->|"type lookup"| node_resolver
node_resolver -->|"reads PATH"| node_environment
node_builtins -->|"changes or reads cwd"| node_environment
node_dispatcher -->|"forks and executes"| node_child
node_child -->|"runs resolved program"| node_environment
node_redirect -->|"opens output file"| node_environment

click node_runtime "https://github.com/kibet-rotich/shell-using-c-/blob/master/src/main.cpp"
click node_tokenizer "https://github.com/kibet-rotich/shell-using-c-/blob/master/src/main.cpp"
click node_dispatcher "https://github.com/kibet-rotich/shell-using-c-/blob/master/src/main.cpp"
click node_builtins "https://github.com/kibet-rotich/shell-using-c-/blob/master/src/main.cpp"
click node_redirect "https://github.com/kibet-rotich/shell-using-c-/blob/master/src/main.cpp"
click node_resolver "https://github.com/kibet-rotich/shell-using-c-/blob/master/src/main.cpp"
click node_child "https://github.com/kibet-rotich/shell-using-c-/blob/master/src/main.cpp"

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_runtime,node_tokenizer,node_dispatcher,node_builtins,node_redirect,node_resolver,node_user toneBlue
class node_child,node_environment toneAmber
```

## Components

### Shell runtime

- [Shell loop](https://github.com/kibet-rotich/shell-using-c-/blob/master/src/main.cpp): `src/main.cpp`
- [Command tokenizer](https://github.com/kibet-rotich/shell-using-c-/blob/master/src/main.cpp): `src/main.cpp`
- [Command dispatch](https://github.com/kibet-rotich/shell-using-c-/blob/master/src/main.cpp): `src/main.cpp`
- [Builtin commands](https://github.com/kibet-rotich/shell-using-c-/blob/master/src/main.cpp): `src/main.cpp`
- [Stdout redirection](https://github.com/kibet-rotich/shell-using-c-/blob/master/src/main.cpp): `src/main.cpp`
- [PATH resolver](https://github.com/kibet-rotich/shell-using-c-/blob/master/src/main.cpp): `src/main.cpp`

### Host environment

- [External process](https://github.com/kibet-rotich/shell-using-c-/blob/master/src/main.cpp): `src/main.cpp`
- **Environment and filesystem**

### Other components

- **Shell user**

## Connections

- Shell user → Shell loop: enters command (evidence: `README.md`)
- Shell loop → Command tokenizer: tokenizes input (evidence: `src/main.cpp`)
- Shell loop → Stdout redirection: extracts redirect (evidence: `src/main.cpp`)
- Shell loop → Command dispatch: dispatches command (evidence: `src/main.cpp`)
- Command dispatch → Builtin commands: calls builtin (evidence: `src/main.cpp`)
- Command dispatch → PATH resolver: calls for external (evidence: `src/main.cpp`)
- Command dispatch → PATH resolver: type lookup (evidence: `src/main.cpp`)
- PATH resolver → Environment and filesystem: reads PATH (evidence: `src/main.cpp`)
- Builtin commands → Environment and filesystem: changes or reads cwd (evidence: `src/main.cpp`)
- Command dispatch → External process: forks and executes (evidence: `src/main.cpp`)
- External process → Environment and filesystem: runs resolved program (evidence: `src/main.cpp`)
- Stdout redirection → Environment and filesystem: opens output file (evidence: `src/main.cpp`)
