# oliverkingz/minishell architecture

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

- Interactive diagram: https://gitdiagram.com/oliverkingz/minishell
- Repository: https://github.com/oliverkingz/minishell

## Overview

##### Project Type and Purpose
- Minishell is a command-line shell implementation that mimics basic functionalities of Unix shells (like Bash). Its purpose is to handle process management, file descriptors, redirections, pipes, signal handling, and built-in commands.
- Key functional modules include command execution, input/output redirections, parser/tokenizer, environment handling, and signal management.

##### File Structure to Extract Architectural Components
- The top-level structure reveals directories such as “src”, “inc”, “lib/libft”, “doc” and “scripts”.
- The “src” folder contains files implementing shell built-ins (bi_cd, bi_echo, etc.), lexer, parser, command execution, and signal handling, which indicates a layered processing pipeline.
- The “lib/libft” directory hosts an external library that provides common utility and helper functions.
- The README confirms the core features (like redirection, pipes, environment variables, etc.), reinforcing the separation of concerns into input handling, processing pipeline, and auxiliary services.

##### And Explain the Main Components
a. User Interface Layer:
- Component: Input Handler (main.c, input.c)
- Role: Captures user commands from the terminal.

b. Processing Pipeline Layer:
- Components:
- Lexer (lexer.c): Scans raw input to produce tokens.
- Parser/Tokenizer (parser_tokenize.c, parser_utils.c, token_list.c, token_utils.c): Organizes tokens and clarifies command structure.
- Redirection & Pipe Manager (redirections.c, heredoc.c, heredoc2.c): Manages input/output redirections and pipes.
- Command Executor (execution.c, builtin.c, bi_* files): Executes commands, including built-in commands.
- Relationships: Input flows from the CLI to the lexer, then to the parser, followed by redirection handling, and finally is passed to the command executor.

c. Auxiliary Services Layer:
- Components:
- Environment Manager (env.c, env_list.c, env_var.c): Manages environment variables.
- Signal Handler (signal.c): Catches signals like ctrl-C, ctrl-D, etc.
- Utility & Helper Functions (utils.c, utils2.c, expansion_security.c, expansion_utils.c, expansion_var.c): Provides common helper functions used across modules.
- External Dependency: The External Library (libft) provides essential functions for string handling, memory management, and other utilities.

## Diagram (Mermaid)

```mermaid
graph TD
    %% User Interface Layer
    subgraph "User Interface"
        A["Input Handler: CLI (main.c, input.c)"]:::input
    end

    %% Processing Pipeline Layer
    subgraph "Processing Pipeline"
        B["Lexer (lexer.c)"]:::lexer
        C["Parser/Tokenizer (parser_tokenize.c, parser_utils.c, token_list.c, token_utils.c)"]:::parser
        D["Redirection & Pipe Manager (redirections.c, heredoc.c, heredoc2.c)"]:::redirection
        E["Command Executor (execution.c, builtin.c, bi_cd.c, bi_echo.c, bi_env.c, bi_exit.c, bi_export.c, bi_pwd.c, bi_unset.c)"]:::executor
    end

    %% Auxiliary Services Layer
    subgraph "Auxiliary Services"
        F["Environment Manager (env.c, env_list.c, env_var.c)"]:::environment
        G["Signal Handler (signal.c)"]:::signal
        H["Utility & Helper Functions (utils.c, utils2.c, expansion_security.c, expansion_utils.c, expansion_var.c)"]:::utility
        I["External Library: libft"]:::libft
    end

    %% Data Flow Connections
    A -->|"input"| B
    B -->|"tokens"| C
    C -->|"parsed"| D
    D -->|"commands"| E

    %% Auxiliary Services interactions with Processing Pipeline
    F -->|"env data"| E
    G -->|"signal catch"| E
    H -->|"helpers"| E

    %% External Library Dependencies
    E -->|"uses"| I
    H -->|"uses"| I

    %% Click Events for Component Mapping
    click A "https://github.com/oliverkingz/minishell/blob/main/src/main.c"
    click A "https://github.com/oliverkingz/minishell/blob/main/src/input.c"
    click B "https://github.com/oliverkingz/minishell/blob/main/src/lexer.c"
    click C "https://github.com/oliverkingz/minishell/blob/main/src/parser_tokenize.c"
    click C "https://github.com/oliverkingz/minishell/blob/main/src/parser_utils.c"
    click C "https://github.com/oliverkingz/minishell/blob/main/src/token_list.c"
    click C "https://github.com/oliverkingz/minishell/blob/main/src/token_utils.c"
    click D "https://github.com/oliverkingz/minishell/blob/main/src/redirections.c"
    click D "https://github.com/oliverkingz/minishell/blob/main/src/heredoc.c"
    click D "https://github.com/oliverkingz/minishell/blob/main/src/heredoc2.c"
    click E "https://github.com/oliverkingz/minishell/blob/main/src/execution.c"
    click E "https://github.com/oliverkingz/minishell/blob/main/src/builtin.c"
    click E "https://github.com/oliverkingz/minishell/blob/main/src/bi_cd.c"
    click E "https://github.com/oliverkingz/minishell/blob/main/src/bi_echo.c"
    click E "https://github.com/oliverkingz/minishell/blob/main/src/bi_env.c"
    click E "https://github.com/oliverkingz/minishell/blob/main/src/bi_exit.c"
    click E "https://github.com/oliverkingz/minishell/blob/main/src/bi_export.c"
    click E "https://github.com/oliverkingz/minishell/blob/main/src/bi_pwd.c"
    click E "https://github.com/oliverkingz/minishell/blob/main/src/bi_unset.c"
    click F "https://github.com/oliverkingz/minishell/blob/main/src/env.c"
    click F "https://github.com/oliverkingz/minishell/blob/main/src/env_list.c"
    click F "https://github.com/oliverkingz/minishell/blob/main/src/env_var.c"
    click G "https://github.com/oliverkingz/minishell/blob/main/src/signal.c"
    click H "https://github.com/oliverkingz/minishell/blob/main/src/utils.c"
    click H "https://github.com/oliverkingz/minishell/blob/main/src/utils2.c"
    click H "https://github.com/oliverkingz/minishell/blob/main/src/expansion_security.c"
    click H "https://github.com/oliverkingz/minishell/blob/main/src/expansion_utils.c"
    click H "https://github.com/oliverkingz/minishell/blob/main/src/expansion_var.c"
    click I "https://github.com/oliverkingz/minishell/tree/main/lib/libft"

    %% Styles
    classDef input fill:#1f77b4,stroke:#ffffff,stroke-width:2px;
    classDef lexer fill:#ff7f0e,stroke:#ffffff,stroke-width:2px;
    classDef parser fill:#2ca02c,stroke:#ffffff,stroke-width:2px;
    classDef redirection fill:#d62728,stroke:#ffffff,stroke-width:2px;
    classDef executor fill:#9467bd,stroke:#ffffff,stroke-width:2px;
    classDef environment fill:#8c564b,stroke:#ffffff,stroke-width:2px;
    classDef signal fill:#e377c2,stroke:#ffffff,stroke-width:2px;
    classDef utility fill:#7f7f7f,stroke:#ffffff,stroke-width:2px;
    classDef libft fill:#bcbd22,stroke:#ffffff,stroke-width:2px;
```
