# rkoeninger/shensharp architecture

> Architecture diagram of the GitHub repository rkoeninger/shensharp, 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/rkoeninger/shensharp
- Repository: https://github.com/rkoeninger/shensharp

## Overview

##### Main Components

a) Core Components:
- Kλ (Core Language) Layer
- Shen Language Layer
- CLR Integration Layer
- Build/Make System
- Testing Infrastructure

b) Key Processing Flows:
- Compilation Pipeline
- Runtime Evaluation
- REPL Interface

**┌─ User Interface Layer ─────┐**
- REPL                    │
- API Integration Points  │
- ┘

**┌─ Shen Implementation ─────┐**
- Runtime                 │
- Extension Methods       │
- ┘

**┌─ Kλ Implementation ───────┐**
- Types                   │
- Evaluator              │
- Builtins               │
- ┘

**Reader → Syntax → Compiler → F# AST → CLR Assembly**

##### Key Relationships to Highlight

a) Compilation Process:
- How Kl.Make handles the build process
- Transformation from Kλ to F# to CLR

b) Runtime Flow:
- How evaluation happens through the Evaluator
- Demonstrate interaction between Builtins and Types

c) Testing Integration:
- How test suites connect to both Kλ and Shen layers

##### Component Details

Core Components:
- Types.fs (Value representation)
- Evaluator.fs (Expression interpretation)
- Builtins.fs (Primitive functions)
- Compiler.fs (Translation logic)

Support Components:
- Reader.fs (Parsing)
- Writer.fs (Output)
- Runtime.fs (Embedding support)
- ExtensionMethods.fs (C# integration)

##### Additional Elements

- Notes about optimization points
- Entry points for different use cases (REPL, embedded use)
- Configuration and build pipeline integration

Remember to include bidirectional relationships where appropriate, especially between the evaluation engine and the runtime system, and mark clear boundaries between compile-time and runtime components.

This architecture should emphasize the project's nature as both a language implementation and a CLR integration, showing how it bridges the gap between Shen's functional/logic paradigms and the CLR's object-oriented environment.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph UI["User Interface Layer"]
        REPL["REPL Interface"]:::ui
        API["API Integration Points"]:::ui
    end

    subgraph SHEN["Shen Implementation Layer"]
        Runtime["Runtime"]:::shen
        ExtMethods["Extension Methods"]:::shen
    end

    subgraph KL["Kλ Implementation Layer"]
        Types["Types System"]:::core
        Evaluator["Evaluator"]:::core
        Builtins["Builtins"]:::core
        Values["Values Handler"]:::core
        Interop["Foreign Function Interface"]:::core
        Startup["Startup Configuration"]:::core
    end

    subgraph COMPILE["Compilation Pipeline"]
        direction TB
        Reader["Reader"]:::compile
        Syntax["Syntax Processing"]:::compile
        Compiler["Compiler"]:::compile
        Writer["Writer"]:::compile
        BuildRuntime["Build Runtime"]:::compile
    end

    subgraph TEST["Testing Infrastructure"]
        KlTests["Kλ Tests"]:::test
        ShenTests["Shen Tests"]:::test
        TestRunner["Test Suite Runner"]:::test
    end

    subgraph BUILD["Build System"]
        BuildConfig["Build Configuration"]:::build
        BuildPipeline["Build Pipeline"]:::build
    end

    %% Relationships
    REPL --> Runtime
    API --> Runtime
    Runtime --> ExtMethods
    Runtime --> Evaluator
    ExtMethods --> Interop
    Evaluator --> Types
    Evaluator --> Builtins
    Evaluator --> Values
    Builtins --> Types
    Startup --> Evaluator

    %% Compilation Flow
    Reader --> Syntax
    Syntax --> Compiler
    Compiler --> Writer
    Writer --> BuildRuntime
    BuildRuntime --> Runtime

    %% Testing Relationships
    KlTests --> Evaluator
    ShenTests --> Runtime
    TestRunner --> KlTests
    TestRunner --> ShenTests

    %% Build System
    BuildConfig --> BuildPipeline
    BuildPipeline --> Compiler

    %% Click Events
    click Types "https://github.com/rkoeninger/ShenSharp/blob/master/src/Kl/Types.fs"
    click Evaluator "https://github.com/rkoeninger/ShenSharp/blob/master/src/Kl/Evaluator.fs"
    click Builtins "https://github.com/rkoeninger/ShenSharp/blob/master/src/Kl/Builtins.fs"
    click Values "https://github.com/rkoeninger/ShenSharp/blob/master/src/Kl/Values.fs"
    click Reader "https://github.com/rkoeninger/ShenSharp/blob/master/src/Kl.Make/Reader.fs"
    click Syntax "https://github.com/rkoeninger/ShenSharp/blob/master/src/Kl.Make/Syntax.fs"
    click Compiler "https://github.com/rkoeninger/ShenSharp/blob/master/src/Kl.Make/Compiler.fs"
    click Writer "https://github.com/rkoeninger/ShenSharp/blob/master/src/Kl.Make/Writer.fs"
    click BuildRuntime "https://github.com/rkoeninger/ShenSharp/blob/master/src/Kl.Make/BuildRuntime.fs"
    click Runtime "https://github.com/rkoeninger/ShenSharp/blob/master/src/Shen/Runtime.fs"
    click ExtMethods "https://github.com/rkoeninger/ShenSharp/blob/master/src/Shen/ExtensionMethods.fs"
    click REPL "https://github.com/rkoeninger/ShenSharp/blob/master/src/Shen.Repl/RunRepl.fs"
    click KlTests "https://github.com/rkoeninger/ShenSharp/blob/master/src/Kl.Tests"
    click ShenTests "https://github.com/rkoeninger/ShenSharp/blob/master/src/Shen.Tests"
    click TestRunner "https://github.com/rkoeninger/ShenSharp/blob/master/src/Shen.TestSuite/RunTestSuite.fs"
    click Interop "https://github.com/rkoeninger/ShenSharp/blob/master/src/Kl/Interop.fs"
    click Startup "https://github.com/rkoeninger/ShenSharp/blob/master/src/Kl/Startup.fs"
    click BuildConfig "https://github.com/rkoeninger/ShenSharp/blob/master/src/Directory.Build.props"
    click BuildPipeline "https://github.com/rkoeninger/ShenSharp/blob/master/.github/workflows/build.yml"

    %% Styling
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef shen fill:#4CAF50,stroke:#2E7D32,color:white
    classDef compile fill:#FF9800,stroke:#EF6C00,color:white
    classDef test fill:#9C27B0,stroke:#6A1B9A,color:white
    classDef ui fill:#03A9F4,stroke:#0277BD,color:white
    classDef build fill:#795548,stroke:#4E342E,color:white
```
