# ikigu/simple_shell architecture

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

- Interactive diagram: https://gitdiagram.com/ikigu/simple_shell
- Repository: https://github.com/ikigu/simple_shell

## Overview

##### Flow Representation
- User Input → Read Command → Tokenize → Parse → Execute → Output

##### Component Details

- Blue: Core shell components (shell.c, execute_command.c)
- Green: Input processing (read_command.c, tokenize.c)
- Yellow: Command processing (parse_command.c, find_exe.c)
- Gray: Utility functions (strings.c, path.c, extend_buffer.c, free_mem.c)

##### Specific Elements

a. Main Process Flow:
- [Shell Interface] → [Command Reader] → [Tokenizer] → [Parser] → [Executor]

- [Path Handler] ----→ [Executor]
- [String Utils] ----→ [Multiple Components]
- [Memory Manager] ----→ [Multiple Components]

c. Built-in Commands (in a separate section):
- [Command Parser] → [Built-ins]
- env
- exit

##### Additional Details
- Notes about memory management flow
- Where environment variables are accessed

##### Key Interactions to Highlight
- Command input processing flow
- PATH resolution process
- Memory allocation/deallocation points
- Built-in command handling vs external command execution

##### Technical Notes
- Where the program interfaces with the system (system calls)
- Where environment variables are accessed
- Points where memory management occurs

Remember to:
- Use consistent symbols throughout
- Both successful and error paths
- Decision points in the command processing flow

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Legend
        L1[Core Components]:::core
        L2[Input Processing]:::input
        L3[Command Processing]:::command
        L4[Support Systems]:::support
        L5[Error Path]:::error
    end

    subgraph "Input Processing Layer"
        Shell[Shell Interface]:::core
        Reader[Command Reader]:::input
        Tokenizer[Command Tokenizer]:::input
    end

    subgraph "Command Processing Layer"
        Parser[Command Parser]:::command
        Executor[Command Executor]:::core
        Finder[Executable Finder]:::command
        
        subgraph "Built-in Commands"
            Builtins[Built-ins]:::command
            Env[env]:::command
            Exit[exit]:::command
        end
    end

    subgraph "Support Systems Layer"
        PathHandler[PATH Handler]:::support
        StringUtils[String Operations]:::support
        MemManager[Memory Manager]:::support
        MemCleanup[Memory Cleanup]:::support
    end

    %% Main Flow
    Shell --> Reader
    Reader --> Tokenizer
    Tokenizer --> Parser
    Parser --> Executor
    Parser --> Builtins
    Builtins --> Env
    Builtins --> Exit
    Executor --> Finder
    
    %% Support System Connections
    PathHandler -.-> Finder
    StringUtils -.-> Parser
    StringUtils -.-> Tokenizer
    MemManager -.-> Reader
    MemManager -.-> Tokenizer
    MemCleanup -.-> Executor

    %% Error Paths
    Reader -.-x Shell:::error
    Parser -.-x Shell:::error
    Executor -.-x Shell:::error

    %% Click Events
    click Shell "https://github.com/ikigu/simple_shell/blob/main/shell.c"
    click Reader "https://github.com/ikigu/simple_shell/blob/main/read_command.c"
    click Tokenizer "https://github.com/ikigu/simple_shell/blob/main/tokenize.c"
    click Parser "https://github.com/ikigu/simple_shell/blob/main/parse_command.c"
    click Executor "https://github.com/ikigu/simple_shell/blob/main/execute_command.c"
    click Finder "https://github.com/ikigu/simple_shell/blob/main/find_exe.c"
    click PathHandler "https://github.com/ikigu/simple_shell/blob/main/path.c"
    click StringUtils "https://github.com/ikigu/simple_shell/blob/main/strings.c"
    click MemManager "https://github.com/ikigu/simple_shell/blob/main/extend_buffer.c"
    click MemCleanup "https://github.com/ikigu/simple_shell/blob/main/free_mem.c"

    %% Styles
    classDef core fill:#a2d2ff
    classDef input fill:#bde0fe
    classDef command fill:#ffafcc
    classDef support fill:#cdb4db
    classDef error stroke:#ff0000,stroke-width:2px
    classDef default fill:#fff
```
