# gandalf-/coreutils architecture

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

- Interactive diagram: https://gitdiagram.com/gandalf-/coreutils
- Repository: https://github.com/gandalf-/coreutils

## Overview

##### Project Type Analysis
This is a command-line utility project that reimplements Unix core utilities in Haskell, focusing on platform independence, idiomatic implementation, and performance.

##### Main Architectural Components

a. Core Components:
- Command Router/Dispatcher
- Individual Utility Implementations
- Common Utilities/Shared Code
- Testing Framework

**[User Command Input] → [Command Router/Dispatcher]**
- ↓
- ┌────────────────────────┼────────────────────────┐
- ↓                        ↓                        ↓
**[File Operations]    [Text Processing]        [System Operations]**

- → [Common Utilities] ←───────────────┘
- ↑
- [Testing Framework]

##### Component Details

A. Command Router/Dispatcher
- How the system determines which utility to execute based on binary name
- Platform-specific handling (symlinks vs. copies)

B. Utility Categories (group the 40+ utilities into logical categories):
- File Operations (ls, cat, mkdir, etc.)
- Text Processing (awk, cut, tr, etc.)
- System Operations (sleep, env, whoami, etc.)

C. Common Utilities Layer
- Shared Util.hs component
- IO handling patterns
- Demonstrate lazy evaluation support

D. Testing Framework
- Unit Tests
- Integration Tests
- Property-Based Tests

##### Important Characteristics to Highlight

- Lazy I/O streams
- Direct function calls
- System interactions

##### Additional Elements

- The build/installation process
- The platform-specific deployment strategies
- The testing architecture

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Input
        CMD[User Command Input]
    end

    subgraph Router
        DISP[Command Router/Dispatcher]
    end

    subgraph "File Operations"
        LS[ls]
        CAT[cat]
        MKDIR[mkdir]
        PWD[pwd]
    end

    subgraph "Text Processing"
        AWK[awk]
        CUT[cut]
        TR[tr]
        UNIQ[uniq]
        WC[wc]
    end

    subgraph "System Operations"
        SLEEP[sleep]
        ENV[env]
        WHOAMI[whoami]
        EXIT[exit]
    end

    subgraph "Common Layer"
        UTIL[Common Utilities]
    end

    subgraph "Testing Framework"
        UNIT[Unit Tests]
        INT[Integration Tests]
        RUNNER[Test Runner]
    end

    subgraph "Build System"
        CABAL[Cabal Config]
        STACK[Stack Config]
        MAKE[Makefile]
    end

    %% Connections
    CMD --> DISP
    DISP --> LS & CAT & MKDIR & PWD
    DISP --> AWK & CUT & TR & UNIQ & WC
    DISP --> SLEEP & ENV & WHOAMI & EXIT

    LS & CAT & MKDIR & PWD --> UTIL
    AWK & CUT & TR & UNIQ & WC --> UTIL
    SLEEP & ENV & WHOAMI & EXIT --> UTIL

    UNIT & INT --> RUNNER
    RUNNER --> UTIL

    %% Click events
    click DISP "https://github.com/Gandalf-/coreutils/blob/master/src/main.hs"
    click UTIL "https://github.com/Gandalf-/coreutils/blob/master/Coreutils/Util.hs"
    click LS "https://github.com/Gandalf-/coreutils/blob/master/Coreutils/Ls.hs"
    click CAT "https://github.com/Gandalf-/coreutils/blob/master/Coreutils/Cat.hs"
    click MKDIR "https://github.com/Gandalf-/coreutils/blob/master/Coreutils/Mkdir.hs"
    click PWD "https://github.com/Gandalf-/coreutils/blob/master/Coreutils/Pwd.hs"
    click AWK "https://github.com/Gandalf-/coreutils/blob/master/Coreutils/Awk.hs"
    click CUT "https://github.com/Gandalf-/coreutils/blob/master/Coreutils/Cut.hs"
    click TR "https://github.com/Gandalf-/coreutils/blob/master/Coreutils/Tr.hs"
    click UNIQ "https://github.com/Gandalf-/coreutils/blob/master/Coreutils/Uniq.hs"
    click WC "https://github.com/Gandalf-/coreutils/blob/master/Coreutils/Wc.hs"
    click SLEEP "https://github.com/Gandalf-/coreutils/blob/master/Coreutils/Sleep.hs"
    click ENV "https://github.com/Gandalf-/coreutils/blob/master/Coreutils/Env.hs"
    click WHOAMI "https://github.com/Gandalf-/coreutils/blob/master/Coreutils/Whoami.hs"
    click EXIT "https://github.com/Gandalf-/coreutils/blob/master/Coreutils/Exit.hs"
    click UNIT "https://github.com/Gandalf-/coreutils/tree/master/test"
    click INT "https://github.com/Gandalf-/coreutils/tree/master/test/integration"
    click RUNNER "https://github.com/Gandalf-/coreutils/blob/master/test/Spec.hs"
    click CABAL "https://github.com/Gandalf-/coreutils/blob/master/coreutils.cabal"
    click STACK "https://github.com/Gandalf-/coreutils/blob/master/stack.yaml"
    click MAKE "https://github.com/Gandalf-/coreutils/tree/master/Makefile"

    %% Styling
    classDef default fill:#f9f9f9,stroke:#333,stroke-width:2px;
    classDef completed fill:#d4edda,stroke:#28a745;
    classDef partial fill:#fff3cd,stroke:#ffc107;
    classDef system fill:#e2e3e5,stroke:#6c757d;
    classDef testing fill:#cce5ff,stroke:#0d6efd;
    classDef build fill:#f8d7da,stroke:#dc3545;

    class LS,CAT,MKDIR,PWD,AWK,CUT,TR,UNIQ,WC,SLEEP,ENV,WHOAMI,EXIT completed;
    class UTIL system;
    class UNIT,INT,RUNNER testing;
    class CABAL,STACK,MAKE build;
```
