# szymonsuchanek/42_minishell architecture

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

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

## Overview

##### Project type and purpose
- This is a “minishell” command-line shell, implemented in C.
- It provides interactive command parsing, built-in commands (cd, echo, export, etc.), external command execution with fork/exec, pipes, redirection, environment-variable expansion, and its own simple garbage collector and utility library (lib_ft).

##### File structure
- Top-level:
- inc/            → headers for the shell (cmd.h, minishell.h)
- lib_ft/         → custom utility library (string, memory, list ops, error handling)
- src/            → all the shell’s modules, subdivided into:
– builtin/      → implementations of built-in shell commands
– env/          → environment‐variable list, expansion routines
– parsing/      → tokenization, here-doc, quote handling, validation
– execution/    → forks, pipes, file redirection, finding binaries
– garbage_colector/ → alloc/free tracking for safe memory management
– main.c, signals.c, validate_input.c
- Makefile, .vscode/, config files, and README.txt for build and project hooks.

##### README insights
- Minimal content: instructions for git hooks setup, mention of “signals in forks.”

##### Elements
- User → CLI
- CLI → Parser
- Parser ↔ Env Manager (variable lookup & expansion)
- Parser → Executor
- Executor → Built-in Handler OR Executor → fork/exec external
- Executor → Garbage Collector (register/release memory)
- Core modules (Parser, Executor) in another
- Support services (Env, GC, lib_ft) in a third

##### Final advice
- Be highly detailed: break execution flow into “fork process”, “set up pipe”, “dup2 redirection”, “execve call”.
- Every module boundary and external dependency (OS calls, lib_ft).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entities
    User["User"]:::external

    %% Core Modules
    subgraph "Core Layers"
        direction TB
        CLI["CLI / Input Reader"]:::io
        Parser["Parser Module"]:::core
        Executor["Execution Engine"]:::core
        Builtin["Built-in Command Handler"]:::core
        ExtExec["External Command Executor"]:::core
    end

    %% Support Services
    subgraph "Support Services"
        direction TB
        EnvMgr["Environment Manager"]:::support
        GC["Garbage Collector"]:::support
        LibFT["Utility Library (lib_ft)"]:::support
    end

    %% OS
    OS["Operating System"]:::os

    %% Flows
    User -->|"types command"| CLI
    CLI -->|"raw input"| Parser
    Parser -->|"token stream"| EnvMgr
    EnvMgr -->|"expanded tokens"| Parser
    Parser -->|"AST/command list"| Executor
    Executor -->|"route built-in"| Builtin
    Executor -->|"fork & exec"| ExtExec
    Executor -->|"alloc/free tracking"| GC
    Parser -->|"alloc/free tracking"| GC
    EnvMgr -->|"alloc/free tracking"| GC
    Parser -->|"utils calls"| LibFT
    EnvMgr -->|"utils calls"| LibFT
    Executor -->|"utils calls"| LibFT
    Builtin -->|"utils calls"| LibFT
    ExtExec -->|"utils calls"| LibFT
    ExtExec -->|"syscalls"| OS
    EnvMgr -->|"env list access"| OS
    Executor -->|"signal handling"| OS

    %% Click Events
    click CLI "https://github.com/szymonsuchanek/42_minishell/tree/main/src/"
    click Parser "https://github.com/szymonsuchanek/42_minishell/tree/main/src/parsing/"
    click EnvMgr "https://github.com/szymonsuchanek/42_minishell/tree/main/src/env/"
    click Builtin "https://github.com/szymonsuchanek/42_minishell/tree/main/src/builtin/"
    click ExtExec "https://github.com/szymonsuchanek/42_minishell/tree/main/src/execution/"
    click GC "https://github.com/szymonsuchanek/42_minishell/tree/main/src/garbage_colector/"
    click LibFT "https://github.com/szymonsuchanek/42_minishell/tree/main/lib_ft/"
    click OS "https://github.com/szymonsuchanek/42_minishell/tree/main/inc/"

    %% Styles
    classDef io fill:#ccffcc,stroke:#333,stroke-width:1px
    classDef core fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef support fill:#fff2cc,stroke:#333,stroke-width:1px
    classDef external fill:#f0f0f0,stroke:#333,stroke-width:1px
    classDef os fill:#e6e6e6,stroke:#333,stroke-width:1px
```
