# cobbal/swsh architecture

> Architecture diagram of the GitHub repository cobbal/swsh, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cobbal/swsh
- Repository: https://github.com/cobbal/swsh

## Overview

##### Component Relationships

- How Command flows to ProcessSpawner
- Pipeline connections between Commands
- Demonstrate File Descriptor operations flow
- Platform-specific implementations

##### Specific Elements

a) Command Execution Flow:
- Command Interface -> ProcessSpawner -> Platform-Specific Spawner -> System Process

b) Pipeline Operations:
- Command A -> Pipeline -> Command B -> Command Result

c) File Descriptor Management:
- FDOperation -> FDMap -> FileDescriptor -> System FD

##### Important Details

- Async/sync execution paths separately
- Error handling paths
- Where platform-specific code diverges
- Integration points with system commands

Create distinct sections for:
- Command Creation and Management
- Process Execution
- File Descriptor Handling
- Platform-Specific Implementation
- Error Handling

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef api fill:#a8d1f0,stroke:#2980b9
    classDef core fill:#a8e6cf,stroke:#1b4d3e
    classDef platform fill:#ffd3b6,stroke:#d35400
    classDef utility fill:#dfe4ea,stroke:#747d8c

    %% Legend
    subgraph Legend
        API[API Layer]:::api
        Core[Core Layer]:::core
        Platform[Platform Layer]:::platform
        Util[Utility Layer]:::utility
    end

    %% Public API Layer
    subgraph Public_API
        Command["Command Interface"]:::api
        Pipeline["Pipeline Operations"]:::api
        CmdResult["Command Results"]:::api
    end

    %% Core Processing Layer
    subgraph Core_Processing
        ProcSpawn["Process Management"]:::core
        FD["File Descriptor"]:::core
        FDMap["FD Mapping"]:::core
        FDOp["FD Operations"]:::core
        FDWrapper["FD Wrapper Command"]:::core
        ExtCmd["External Command"]:::core
        ErrorHandler["Error Handling"]:::utility
    end

    %% Platform Layer
    subgraph Platform_Specific
        LinuxSpawn["Linux Spawn"]:::platform
        PosixSpawn["POSIX Spawn"]:::platform
        LinuxC["Linux C Implementation"]:::platform
    end

    %% Relationships
    Command --> Pipeline
    Pipeline --> CmdResult
    Command --> ProcSpawn
    ProcSpawn --> LinuxSpawn
    ProcSpawn --> PosixSpawn
    LinuxSpawn --> LinuxC
    
    FD --> FDMap
    FDMap --> FDOp
    FDOp --> FDWrapper
    FDWrapper --> ExtCmd
    ExtCmd --> ProcSpawn
    
    ProcSpawn --> ErrorHandler
    Command --> ErrorHandler
    Pipeline --> ErrorHandler

    %% Click Events
    click Command "https://github.com/cobbal/swsh/blob/master/Sources/swsh/Command.swift"
    click Pipeline "https://github.com/cobbal/swsh/blob/master/Sources/swsh/Pipeline.swift"
    click CmdResult "https://github.com/cobbal/swsh/blob/master/Sources/swsh/CommandResult.swift"
    click ProcSpawn "https://github.com/cobbal/swsh/blob/master/Sources/swsh/ProcessSpawner.swift"
    click FD "https://github.com/cobbal/swsh/blob/master/Sources/swsh/FileDescriptor.swift"
    click FDMap "https://github.com/cobbal/swsh/blob/master/Sources/swsh/FDMap.swift"
    click FDOp "https://github.com/cobbal/swsh/blob/master/Sources/swsh/FDOperation.swift"
    click FDWrapper "https://github.com/cobbal/swsh/blob/master/Sources/swsh/FDWrapperCommand.swift"
    click ExtCmd "https://github.com/cobbal/swsh/blob/master/Sources/swsh/ExternalCommand.swift"
    click LinuxSpawn "https://github.com/cobbal/swsh/blob/master/Sources/swsh/LinuxSpawn.swift"
    click LinuxC "https://github.com/cobbal/swsh/blob/master/Sources/linuxSpawn/linux-spawn.c"
    click PosixSpawn "https://github.com/cobbal/swsh/blob/master/Sources/swsh/PosixSpawn.swift"
    click ErrorHandler "https://github.com/cobbal/swsh/blob/master/Sources/swsh/Errors.swift"
```
