# tablerase/42_minishell architecture

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

- Interactive diagram: https://gitdiagram.com/tablerase/42_minishell
- Repository: https://github.com/tablerase/42_minishell

## Overview

##### Main Components
- Input Handling: Represented by the integration with Readline (as seen in several parts of the README) – handling dynamic user input and line reading.
- Lexing Module: The “lexer” directories/files (Sources/mandatory/lexer) and related headers handle tokenizing the input. This module checks for lexing errors (e.g., unmatched quotes).
- Parsing Module: Found under Sources/mandatory/parser. This module takes the list of tokens from the lexer and constructs commands (including handling of arguments, redirections, and here_docs).
- Builtin Commands: Located in Sources/mandatory/builtin, handling built-in functions like exit, cd, pwd, export, etc.
- Execution & Pipes: The Sources/mandatory/execution and Sources/mandatory/pipes directories elaborate how commands are executed, how redirections are applied, pipes are set up, and how external processes are launched.
- Utility Functions: Common routines (in Sources/mandatory/utils) and helper modules that support array handling, memory freeing, and more.
- Libft Integration: An external library (libft) that provides additional utility functions (like string, memory, list handling) which the shell uses.

##### Specify Relationships and Interactions
- Data flows from Readline input into the Lexing component.
- Lexical tokens are passed to the Parser, which builds a command listing.
- The Execution module handles initiating command processes, applying redirections (with special handling for things like here_doc) and managing resources.
- A separate subsystem deals with signal handling where events (SIGINT, SIGQUIT, SIGEOF) are caught and influence the current state of input, heredoc processing, or command execution.
- Libft is used as a support library ensuring fundamental operations (like formatted output via ft_printf) are consistent across modules.
- Dependencies between modules are clearly visible: the Parser depends on the output of the Lexer, while the Executor depends on both the Parser and the Pipes module.

##### Architectural Patterns and Design Principles
- Modular Design: The project is clearly split into modules (lexer, parser, executor, builtins, utilities) ensuring separation of concerns.
- Pipeline or Data Flow Architecture: Input flows sequentially through lexing -> parsing -> command execution.
- Error Handling & Signal Interception: Specialized design for handling errors (lexical errors, here_doc interrupts) and signals (leveraging Readline settings and modifications to keep input/signal handling coherent).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Input and Parsing Flow"
        A["Readline Input"]:::core
        B["Lexing Module"]:::core
        C["Parsing Module"]:::core
    end

    subgraph "Execution Pipeline"
        E["Builtin Commands"]:::core
        F["Execution & Redirections"]:::execution
        G["Pipes Module"]:::execution
    end

    subgraph "Supporting Modules"
        H["Utility Functions"]:::utility
        I["Libft Integration"]:::utility
        J["Signal Handling"]:::signal
    end

    %% Data Flow Connections
    A -->|"provides_input"| B
    B -->|"tokenizes_input"| C
    C -->|"if_builtin"| E
    C -->|"external_command"| F
    F -->|"setup_pipes"| G

    %% Signal Handling Interactions
    J -->|"monitors"| A
    J -->|"manages_signals"| F

    %% Utility and Libft Support
    H -.->|"supports"| B
    H -.->|"supports"| C
    H -.->|"supports"| F
    I -.->|"provides_lib_utils"| H

    %% Click Events
    click A "https://github.com/tablerase/42_minishell/blob/main/Sources/mandatory/main.c"
    click B "https://github.com/tablerase/42_minishell/tree/main/Sources/mandatory/lexer/"
    click C "https://github.com/tablerase/42_minishell/tree/main/Sources/mandatory/parser/"
    click E "https://github.com/tablerase/42_minishell/tree/main/Sources/mandatory/builtin/"
    click F "https://github.com/tablerase/42_minishell/tree/main/Sources/mandatory/execution/"
    click G "https://github.com/tablerase/42_minishell/tree/main/Sources/mandatory/pipes/"
    click H "https://github.com/tablerase/42_minishell/tree/main/Sources/mandatory/utils/"
    click I "https://github.com/tablerase/42_minishell/tree/main/libft/"
    click J "https://github.com/tablerase/42_minishell/blob/main/Sources/mandatory/execution/execution_signals.c"

    %% Style Definitions
    classDef core fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef execution fill:#d4edda,stroke:#333,stroke-width:2px;
    classDef signal fill:#f8d7da,stroke:#333,stroke-width:2px;
    classDef utility fill:#fff3cd,stroke:#333,stroke-width:2px;
```
