# ayasy-el/codecrafters-shell-go architecture

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

- Interactive diagram: https://gitdiagram.com/ayasy-el/codecrafters-shell-go
- Repository: https://github.com/ayasy-el/codecrafters-shell-go

## Overview

##### Main Components

a. Input Layer:
- REPL (Read-Eval-Print Loop) Component
- Input Parser (handling quotes and escape characters)
- Command Tokenizer

b. Command Processing Layer:
- Command Resolver (determines if builtin or external)
- Builtin Commands Manager
- External Command Executor
- Path Resolution System

c. System Integration Layer:
- Process Management
- File System Interface
- Environment Variables Handler

- [User Input] → [Parser] → [Command Resolver] → [Execution] → [Output]

##### Detailed Component Breakdown

a. Input Processing:
**┌─────────────────────────┐**
- Input Handler      │
- ┤
- Quote Handler         │
- Escape Processor      │
- Argument Tokenizer    │
- ┘

b. Command Resolution:
**┌─────────────────────────┐**
- Command Resolver     │
- ┤
- Builtin Commands      │
- cd                  │
- pwd                 │
- echo                │
- exit                │
- type                │
- External Commands     │
- ┘

c. Execution Engine:
**┌─────────────────────────┐**
- Execution Engine     │
- ┤
- Process Creator       │
- PATH Resolver        │
- Working Dir Manager   │
- ┘

##### Integration Points

Connections to external systems:
- File System
- Process Management
- Environment Variables
- System PATH

##### Key Flows to Highlight

a. Command Processing Flow:
1. User Input → Input Handler
2. Input Handler → Command Resolver
3. Command Resolver → Appropriate Executor
4. Executor → Output

b. System Integration Flow:
1. External Command → PATH Resolution
2. Process Creation → System Process Manager
3. Directory Operations → File System

##### Technical Details

- Go runtime interaction points
- System call boundaries
- Error propagation paths
- State management (current working directory, environment)

Remember to include version information and any relevant constraints or limitations mentioned in the README, such as the lack of support for piping and redirection.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Legend
        style Legend fill:#f5f5f5,stroke:#333
        L1[Input/Output]:::io
        L2[Command Processing]:::cmd
        L3[System Integration]:::sys
        L4[External Systems]:::ext
    end

    subgraph "Input Layer"
        UserInput[User Input]:::io
        REPL[REPL]:::io
        click REPL "https://github.com/ayasy-el/codecrafters-shell-go/blob/master/cmd/myshell/main.go"
        InputParser[Input Parser]:::io
        CmdTokenizer[Command Tokenizer]:::io
    end

    subgraph "Command Processing Layer"
        CmdResolver[Command Resolver]:::cmd
        BuiltinMgr[Builtin Commands Manager]:::cmd
        ExtCmdExec[External Command Executor]:::cmd
        PathResolver[Path Resolution System]:::cmd
    end

    subgraph "System Integration Layer"
        ProcMgmt[Process Management]:::sys
        FSInterface[File System Interface]:::sys
        EnvHandler[Environment Variables Handler]:::sys
    end

    subgraph "External Systems"
        FileSystem[File System]:::ext
        SysProc[System Processes]:::ext
        EnvVars[Environment Variables]:::ext
    end

    %% Connections
    UserInput --> REPL
    REPL --> InputParser
    InputParser --> CmdTokenizer
    CmdTokenizer --> CmdResolver

    CmdResolver --> BuiltinMgr
    CmdResolver --> ExtCmdExec
    ExtCmdExec --> PathResolver
    PathResolver --> ProcMgmt

    BuiltinMgr -.-> FSInterface
    BuiltinMgr -.-> EnvHandler
    ExtCmdExec -.-> ProcMgmt
    
    FSInterface -.-> FileSystem
    ProcMgmt -.-> SysProc
    EnvHandler -.-> EnvVars

    %% Styles
    classDef io fill:#b3e0ff,stroke:#333
    classDef cmd fill:#b3ffb3,stroke:#333
    classDef sys fill:#ffffb3,stroke:#333
    classDef ext fill:#e6e6e6,stroke:#333

    %% Click Events
    click REPL "https://github.com/ayasy-el/codecrafters-shell-go/blob/master/cmd/myshell/main.go"
```
