# guille-ux/munix architecture

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

- Interactive diagram: https://gitdiagram.com/guille-ux/munix
- Repository: https://github.com/guille-ux/munix

## Overview

##### Project type and purpose
- From the file tree, this is a small operating-system project (“MunixOs”) that uses GRUB as a multiboot bootloader and contains a custom kernel written in C and assembly.
- It includes:
- a /boot/grub folder with grub.cfg
- /kernel sources, headers, linker scripts
- utilities like PASM interpreter sources under include/PASM
- VRAM helper library under include/VRAM
- compile.sh produces an ISO image (munix.iso)

##### File structure
- Top level:
- MunixOs/boot → GRUB config and multiboot setup
- MunixOs/kernel → kernel.c, multiboot.asm, ELF and object files, linker.ld
- MunixOs/kernel/include → hardware abstractions (memory, I/O, disk, display, keyboard, timer, multitask), plus embedded tools (PASM, VRAM)
- compile.sh, linker.ld (root), munix.iso
- Architectural hints:
- Multiboot standard (multiboot.asm → kernel entry)
- Hardware abstraction layer (HAL) in include/*.h
- Monolithic kernel with built-in utilities (PASM interpreter, shell, VRAM libs)
- No separate userland binaries—everything is linked into kernel.

##### Readme insights
- (Empty) so rely on code structure:
- The kernel implements drivers for screen, keyboard, disk, speaker.
- It exposes a shell (shell.h) and an interpreter for a tiny assembly (PASM).

##### Main components and interactions
a. Bootloader (GRUB)
- Reads grub.cfg
- Loads multiboot header from multiboot.asm
- Jumps to kernel
b. Kernel entry & initialization
- multiboot.asm → sets up protected mode → calls kernel.c:init()
c. Hardware Abstraction Layer
- memory management (memory.h)
- low-level I/O (ports.h, io.h)
- disk access (disk.h, fs.h)
- timer & interrupts (timer.h)
- keyboard input (keyboard.h)
- speaker/beeper (speaker.h)
d. Drivers & subsystems
- Filesystem (fs.h)
- Multitasking (multitask.h)
e. Shell & tools
- Built-in shell (shell.h)
- PASM interpreter (ansi-interpreter.h, pasm.h)
f. Output
- Kernel handles console I/O, user commands, and runs PASM code, renders via VRAM.

[GRUB Bootloader] → [Multiboot Stub (multiboot.asm)] → [Kernel Core]
- HAL modules
- Device Drivers
- Subsystems (FS, Multitask)
- User-level shell & PASM
[ISO Image / compile.sh] sits outside as build artifact.
- Patterns: monolithic kernel, layered HAL.
- Technologies: C, x86 Assembly, GRUB2 (Multiboot), custom linker scripts (linker.ld).

**@startuml**
**skinparam rectangle {**
- BackgroundColor<<Boot>> LightBlue
- BackgroundColor<<Kernel>> LightGreen
- BackgroundColor<<Tool>> LightYellow
**}**
**rectangle "GRUB2 Bootloader" <<Boot>>**
**rectangle "Multiboot Stub\n(multiboot.asm)" <<Boot>>**
**rectangle "Kernel Core" <<Kernel>> {**
- rectangle "HAL\n(memory, IO, timer)"
- rectangle "Drivers\n(disk, keyboard, speaker)"
- rectangle "Subsystems\n(filesystem, multitask)"
- rectangle "VRAM Library\n(include/VRAM)"
- rectangle "PASM Interpreter\n(include/PASM)"
- rectangle "Shell\n(shell.h)"
**}**
**rectangle "munix.iso / compile.sh" <<Tool>>**

**GRUB2 Bootloader --> Multiboot Stub : loads**
**Multiboot Stub --> Kernel Core : jumps to**
**Kernel Core --> Drivers : init**
**Kernel Core --> Subsystems : setup**
**Subsystems --> Shell : ready**
**Shell --> PASM Interpreter : exec**
**Kernel Core --> VRAM Library : render**
**compile.sh --> munix.iso : builds**
**@enduml**

##### Further analysis
- Review the linker script (kernel/linker.ld) to see memory layout blocks; include them as sub-blocks inside “HAL”.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Boot Layer
    subgraph "Boot Layer"
        GRUB["GRUB2 Bootloader"]:::boot
        Multiboot["Multiboot Stub\n(multiboot.asm)"]:::boot
        X86["x86 Mode Switch"]:::boot
    end

    %% Kernel Core
    subgraph "Kernel Core"
        %% Linker Scripts
        LinkerTop["Top-level Linker Script\n(linker.ld)"]:::kernel
        LinkerKernel["Kernel Linker Script\n(linker.ld)"]:::kernel

        %% HAL
        subgraph "HAL" 
            Memory["Memory Management\n(memory.h)"]:::kernel
            IO["I/O Ports & Instructions\n(io.h, ports.h)"]:::kernel
            Timer["Timer & Interrupts\n(timer.h)"]:::kernel
            Disk["Disk & Filesystem\n(disk.h, fs.h)"]:::kernel
            Keyboard["Keyboard Input\n(keyboard.h)"]:::kernel
            Speaker["Speaker/Beeper\n(speaker.h)"]:::kernel
        end

        %% Drivers & Subsystems
        subgraph "Drivers & Subsystems"
            Display["Display & Graphics\n(display.h, draw.h, pixels.h)"]:::kernel
            Multitask["Multitasking\n(multitask.h)"]:::kernel
            Errors["Error Handling & Types\n(errors.h, types.h)"]:::kernel
        end

        %% User Tools
        subgraph "User Tools"
            Shell["Shell Interface\n(shell.h)"]:::tool
            Stdio["Standard I/O\n(stnio.h)"]:::tool
            PASM["PASM Interpreter\n(include/PASM)"]:::tool
            VRAM["VRAM Library\n(include/VRAM)"]:::tool
        end
    end

    %% Build Artifact
    Compile["Build Script\n(compile.sh)"]:::tool
    ISO["ISO Image\n(munix.iso)"]:::tool

    %% Connections
    GRUB -->|"reads grub.cfg"| Multiboot
    Multiboot -->|"sets up protected mode"| X86
    X86 -->|"jumps to init()"| KernelEntry["Kernel Entry\n(kernel.c)"]:::kernel
    KernelEntry -->|initializes| LinkerKernel
    LinkerKernel --> Memory & IO & Timer & Disk & Keyboard & Speaker
    Memory & IO & Timer & Disk & Keyboard & Speaker -->|provide HAL| Display & Multitask & Errors
    Display & Multitask & Errors -->|init subsystems| Shell & Stdio
    Shell -->|exec commands| PASM
    PASM -->|renders via| VRAM
    Compile -->|builds| ISO

    %% Click Events
    click GRUB "https://github.com/guille-ux/munix/tree/main/MunixOs/Munix/boot/grub"
    click Multiboot "https://github.com/guille-ux/munix/blob/main/MunixOs/Munix/kernel/multiboot.asm"
    click KernelEntry "https://github.com/guille-ux/munix/blob/main/MunixOs/Munix/kernel/kernel.c"
    click LinkerKernel "https://github.com/guille-ux/munix/blob/main/MunixOs/Munix/kernel/linker.ld"
    click LinkerTop "https://github.com/guille-ux/munix/blob/main/MunixOs/linker.ld"
    click Memory "https://github.com/guille-ux/munix/blob/main/MunixOs/Munix/kernel/include/memory.h"
    click IO "https://github.com/guille-ux/munix/blob/main/MunixOs/Munix/kernel/include/io.h"
    click IO "https://github.com/guille-ux/munix/blob/main/MunixOs/Munix/kernel/include/ports.h"
    click Timer "https://github.com/guille-ux/munix/blob/main/MunixOs/Munix/kernel/include/timer.h"
    click Disk "https://github.com/guille-ux/munix/blob/main/MunixOs/Munix/kernel/include/disk.h"
    click Disk "https://github.com/guille-ux/munix/blob/main/MunixOs/Munix/kernel/include/fs.h"
    click Keyboard "https://github.com/guille-ux/munix/blob/main/MunixOs/Munix/kernel/include/keyboard.h"
    click Speaker "https://github.com/guille-ux/munix/blob/main/MunixOs/Munix/kernel/include/speaker.h"
    click Display "https://github.com/guille-ux/munix/blob/main/MunixOs/Munix/kernel/include/display.h"
    click Display "https://github.com/guille-ux/munix/blob/main/MunixOs/Munix/kernel/include/draw.h"
    click Display "https://github.com/guille-ux/munix/blob/main/MunixOs/Munix/kernel/include/pixels.h"
    click Multitask "https://github.com/guille-ux/munix/blob/main/MunixOs/Munix/kernel/include/multitask.h"
    click Errors "https://github.com/guille-ux/munix/blob/main/MunixOs/Munix/kernel/include/errors.h"
    click Errors "https://github.com/guille-ux/munix/blob/main/MunixOs/Munix/kernel/include/types.h"
    click Shell "https://github.com/guille-ux/munix/blob/main/MunixOs/Munix/kernel/include/shell.h"
    click Stdio "https://github.com/guille-ux/munix/blob/main/MunixOs/Munix/kernel/include/stnio.h"
    click PASM "https://github.com/guille-ux/munix/blob/main/MunixOs/Munix/kernel/include/PASM/ansi-interpreter.h"
    click PASM "https://github.com/guille-ux/munix/blob/main/MunixOs/Munix/kernel/include/PASM/pasm.h"
    click PASM "https://github.com/guille-ux/munix/blob/main/MunixOs/Munix/kernel/include/PASM/src/compiler.h"
    click PASM "https://github.com/guille-ux/munix/blob/main/MunixOs/Munix/kernel/include/PASM/src/exec.h"
    click PASM "https://github.com/guille-ux/munix/blob/main/MunixOs/Munix/kernel/include/PASM/src/out-drivs.h"
    click PASM "https://github.com/guille-ux/munix/blob/main/MunixOs/Munix/kernel/include/PASM/src/shell.h"
    click VRAM "https://github.com/guille-ux/munix/tree/main/MunixOs/Munix/kernel/include/VRAM"
    click Compile "https://github.com/guille-ux/munix/blob/main/MunixOs/compile.sh"
    click ISO "https://github.com/guille-ux/munix/blob/main/MunixOs/munix.iso"

    %% Styles
    classDef boot fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef kernel fill:#90EE90,stroke:#333,stroke-width:1px
    classDef tool fill:#FFFACD,stroke:#333,stroke-width:1px
```
