# awkward-squad/ki architecture

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

## Overview

##### Main Components Identification

a) Core Library Components (ki)
- Thread Management System
- Scope Management
- IO Operations Layer
- STM (Software Transactional Memory) Layer

b) Extension Components (ki-unlifted)
- Unlifted Interface Layer

##### Component Relationships

a) Core Layer (Bottom)
- ByteCount
- NonblockingSTM
- ThreadAffinity
- ThreadOptions
- IO Operations

b) Middle Layer
- Thread Management System
- Connection to Scope Management
- Propagation mechanisms
- To the IO and STM layers

c) Top Layer
- Public API Interface
- Unlifted Interface Extension

##### Key Relationships to Highlight

- How the Thread Management system interacts with Scope Management
- Relationship between NonblockingSTM and Thread operations
- Demonstrate how propagation works through the system
- Connection between the core 'ki' library and 'ki-unlifted' extension

##### Implementation Details

- Thread lifecycle management
- Scope creation and management
- Error propagation paths
- STM interaction points

## Diagram (Mermaid)

```mermaid
graph TB
    %% Main Components
    subgraph Public
        API["Public API"]:::public
        Unlifted["Unlifted Interface"]:::public
    end

    subgraph Core
        ThreadMgmt["Thread Management"]:::core
        ScopeMgmt["Scope Management"]:::core
        PropSystem["Propagation System"]:::core
    end

    subgraph Operations
        IOOps["IO Operations"]:::ops
        STMOps["STM Operations"]:::ops
    end

    subgraph Utilities
        ByteCount["ByteCount"]:::util
        ThreadAff["Thread Affinity"]:::util
        ThreadOpt["Thread Options"]:::util
    end

    %% Relationships
    API --> ThreadMgmt
    API --> ScopeMgmt
    Unlifted --> API
    
    ThreadMgmt --> ScopeMgmt
    ThreadMgmt --> IOOps
    ThreadMgmt --> STMOps
    ThreadMgmt --> ThreadAff
    ThreadMgmt --> ThreadOpt
    
    ScopeMgmt --> PropSystem
    ScopeMgmt --> IOOps
    ScopeMgmt --> STMOps
    
    IOOps --> ByteCount
    STMOps --> ByteCount

    %% Click Events
    click API "https://github.com/awkward-squad/ki/blob/main/ki/src/Ki.hs"
    click Unlifted "https://github.com/awkward-squad/ki/blob/main/ki-unlifted/src/Ki/Unlifted.hs"
    click ThreadMgmt "https://github.com/awkward-squad/ki/blob/main/ki/src/Ki/Internal/Thread.hs"
    click ScopeMgmt "https://github.com/awkward-squad/ki/blob/main/ki/src/Ki/Internal/Scope.hs"
    click IOOps "https://github.com/awkward-squad/ki/blob/main/ki/src/Ki/Internal/IO.hs"
    click STMOps "https://github.com/awkward-squad/ki/blob/main/ki/src/Ki/Internal/NonblockingSTM.hs"
    click ThreadAff "https://github.com/awkward-squad/ki/blob/main/ki/src/Ki/Internal/ThreadAffinity.hs"
    click ThreadOpt "https://github.com/awkward-squad/ki/blob/main/ki/src/Ki/Internal/ThreadOptions.hs"
    click ByteCount "https://github.com/awkward-squad/ki/blob/main/ki/src/Ki/Internal/ByteCount.hs"
    click PropSystem "https://github.com/awkward-squad/ki/blob/main/ki/src/Ki/Internal/Propagating.hs"

    %% Styles
    classDef public fill:#FFD700,stroke:#000
    classDef core fill:#4169E1,stroke:#000,color:#fff
    classDef ops fill:#32CD32,stroke:#000
    classDef util fill:#A9A9A9,stroke:#000

    %% Legend
    subgraph Legend
        L1["Public Interfaces"]:::public
        L2["Core Components"]:::core
        L3["Operations"]:::ops
        L4["Utilities"]:::util
    end
```
