# jonaskruckenberg/k23 architecture

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

- Interactive diagram: https://gitdiagram.com/jonaskruckenberg/k23
- Repository: https://github.com/jonaskruckenberg/k23

## Overview

##### Main Components
- WASM Engine and Runtime: The kernel includes a dedicated WASM subsystem, with components for compiling (using both a “compile” folder and Cranelift backend under kernel/src/wasm/cranelift), running WASM modules (runtime), and handling traps. This is central to its experimental approach and should be highlighted as an isolated “WASM Engine” within the kernel.
- Bootloader/Loader: The “loader” directory represents the bootloader component that initializes the hardware, sets up the initial address mappings, and loads the kernel. It contains its own architecture-specific routines and a main entry point.
- Libraries (“libs”): A large set of libraries supports various low-level functions:
- CPU-local storage, frame allocation, fault handling, and address translation/lookup (e.g., libs/cpu-local, libs/addr2line, libs/leb128, libs/riscv).
- Several libraries provide building blocks for WASM encoding, parsing, and execution support (e.g., libs/wasm-encoder, libs/wast).
- Other components, like “libs/spin” for synchronization primitives and “libs/ksharded-slab” for concurrent data structures, are crucial to the kernel’s performance and reliability.
- Testing/CI: Note the “tests”, “.github/workflows”, and other configuration files. While these are not direct runtime components, they indicate continuous integration and testing flows which can be represented as a supporting infrastructure (perhaps as external tools or feedback loops).

##### Relationships and Data Flow
- Boot Sequence: Represent the flow where the loader (bootloader) initializes the system and hands control over to the kernel.
- Architecture-specific modules (each architecture module feeds into the common kernel functionality).
- Memory management units, including paging, address spaces, and frame allocators.
- The scheduler and task management that drive concurrency and process execution.

##### Architectural Patterns and Design Principles
- Modularity: Notice how the project is cleanly separated into components (kernel, loader, various libraries), which reflects a modular design ideal for research in microkernel architecture.
- Extensibility: Given the roadmap (e.g., future proposals for concurrency features, extended WASM proposals, drivers, etc.), include notes or placeholders that indicate future expansion points.
- Low-Level Hardware Abstraction: The architecture-specific directories and modules (e.g., interrupt handling in kernel/src/arch, device tree parsing in kernel/src/device_tree.rs) showcase abstracted hardware interfaces.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Main Boot Sequence
    Loader("Bootloader/Loader"):::boot
    KernelCore("Kernel Core"):::kernel
    Loader -->|"boot_sequence"| KernelCore

    %% Kernel Subsystems
    subgraph "Kernel Subsystems"
        Arch("Arch Modules"):::kernel
        Memory("Memory Management"):::kernel
        Scheduler("Scheduler & Task Manager"):::kernel
        WasmEngine("WASM Engine & Runtime"):::wasm
        Arch --> KernelCore
        Memory --> KernelCore
        Scheduler --> KernelCore
        WasmEngine --> KernelCore
    end

    %% WASM Engine Components
    subgraph "WASM Engine Components"
        WasmCompile("WASM Compile"):::wasm
        WasmCranelift("WASM Cranelift Backend"):::wasm
        WasmRuntime("WASM Runtime"):::wasm
        WasmCompile -->|"backend_compile"| WasmCranelift
        WasmCranelift -->|"execution_flow"| WasmRuntime
    end

    %% Library Support Modules
    LibSupport("Library Support Modules"):::library
    LibSupport ---|"integrates with"| KernelCore

    %% Documentation and CI support
    Documentation("Documentation/Manual"):::doc
    Testing("Testing/CI Infrastructure"):::ci

    %% Indicate interactions with WASM Engine and Scheduler/Memory Management
    WasmEngine <-->|"traps_and_calls"| Scheduler
    Memory <-->|"address_translation"| WasmRuntime

    %% External support connections
    KernelCore ---|"modular_design"| Documentation
    KernelCore ---|"feedback_loop"| Testing

    %% Annotations for design principles
    KernelCore ---|"hardware_Abstraction"| Arch

    %% Click Events
    click Loader "https://github.com/jonaskruckenberg/k23/tree/main/loader/"
    click KernelCore "https://github.com/jonaskruckenberg/k23/tree/main/kernel/"
    click Arch "https://github.com/jonaskruckenberg/k23/tree/main/kernel/src/arch"
    click Memory "https://github.com/jonaskruckenberg/k23/tree/main/kernel/src/vm"
    click Scheduler "https://github.com/jonaskruckenberg/k23/tree/main/kernel/src/scheduler"
    click WasmEngine "https://github.com/jonaskruckenberg/k23/tree/main/kernel/src/wasm/"
    click WasmCompile "https://github.com/jonaskruckenberg/k23/tree/main/kernel/src/wasm/compile"
    click WasmCranelift "https://github.com/jonaskruckenberg/k23/tree/main/kernel/src/wasm/cranelift"
    click WasmRuntime "https://github.com/jonaskruckenberg/k23/tree/main/kernel/src/wasm/runtime"
    click LibSupport "https://github.com/jonaskruckenberg/k23/tree/main/libs/"
    click Documentation "https://github.com/jonaskruckenberg/k23/tree/main/manual/"
    click Testing "https://github.com/jonaskruckenberg/k23/tree/main/tests/"
    
    %% Styles
    classDef boot fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
    classDef kernel fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef wasm fill:#A2D9CE,stroke:#1ABC9C,stroke-width:2px;
    classDef library fill:#D6EAF8,stroke:#3498DB,stroke-width:2px;
    classDef doc fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
    classDef ci fill:#FADBD8,stroke:#E74C3C,stroke-width:2px;
```
