# lukenar11/moleculeos architecture

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

- Interactive diagram: https://gitdiagram.com/lukenar11/moleculeos
- Repository: https://github.com/lukenar11/moleculeos

## Overview

MoleculeOS is a minimalist, text-based i386 monolithic operating system. Its principal runtime path initializes kernel memory and ATA storage, loads the RAM-resident filesystem, then repeatedly steps a terminal under a simple interrupt-driven loop. The graph also preserves the documented shell, hardware, interrupt, and system-control capabilities. Some subsystem links are dashed where the excerpts or README do not establish the exact call path; unsampled implementations are represented only at supported tree paths.

Main entry points: [`kernel/src/main.cpp`](https://github.com/lukenar11/moleculeos/blob/main/kernel/src/main.cpp) (Kernel scheduler), [`arch/i386/kernel/src/idt/isr_handler.cpp`](https://github.com/lukenar11/moleculeos/blob/main/arch/i386/kernel/src/idt/isr_handler.cpp) (Exception handler), [`kernel/src/storemgr/storage_manager.cpp`](https://github.com/lukenar11/moleculeos/blob/main/kernel/src/storemgr/storage_manager.cpp) (Storage manager), [`terminal/src/terminal.cpp`](https://github.com/lukenar11/moleculeos/blob/main/terminal/src/terminal.cpp) (Terminal)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_boot["Kernel runtime"]
  node_kernelmain["Kernel scheduler<br/>[main.cpp]"]
  node_heap["Block allocator<br/>[block.cpp]"]
end

subgraph group_arch["i386 architecture"]
  node_interrupts["Interrupt handling"]
  node_isr["Exception handler<br/>[isr_handler.cpp]"]
  node_irq["IRQ handler<br/>[irq_handler.cpp]"]
  node_regdump["CPU register state<br/>[regs.hpp]"]
  node_syscontrol["System control"]
end

subgraph group_devices["Hardware devices"]
  node_ata["ATA-PIO driver<br/>[pio.cpp]"]
  node_keyboard["PS/2 keyboard<br/>[keyboard_input.cpp]"]
  node_vga["VGA text mode<br/>[text_mode.cpp]"]
end

subgraph group_storage["RAM storage"]
  node_storage["Storage manager"]
  node_filesystem[("MOFS2 filesystem<br/>[mofs2.cpp]")]
end

subgraph group_interface["User interface"]
  node_terminal["Terminal<br/>[terminal.cpp]"]
  node_shell["Shell interpreter<br/>[shell.cpp]"]
  node_commands["Shell commands"]
  node_textoutput["Text output<br/>[text_output.cpp]"]
end

node_user(("OS user"))

node_kernelmain -->|"initializes"| node_heap
node_kernelmain -->|"initializes"| node_ata
node_kernelmain -->|"initializes"| node_storage
node_kernelmain -->|"loads filesystem"| node_storage
node_kernelmain -->|"steps repeatedly"| node_terminal
node_kernelmain -.->|"uses scheduling"| node_interrupts
node_storage -.->|"reads and writes"| node_ata
node_storage -.->|"loads and saves"| node_filesystem
node_filesystem -.->|"allocates file data"| node_heap
node_irq -->|"dispatches keyboard IRQ"| node_keyboard
node_irq -->|"uses register state"| node_regdump
node_isr -->|"reads register state"| node_regdump
node_isr -->|"prints diagnostics"| node_textoutput
node_isr -->|"halts execution"| node_syscontrol
node_interrupts -.->|"routes exceptions"| node_isr
node_interrupts -.->|"routes hardware IRQs"| node_irq
node_terminal -.->|"runs shell"| node_shell
node_shell -.->|"dispatches commands"| node_commands
node_user -.->|"interacts"| node_terminal
node_commands -.->|"manages files"| node_filesystem
node_terminal -.->|"displays text"| node_vga

click node_kernelmain "https://github.com/lukenar11/moleculeos/blob/main/kernel/src/main.cpp"
click node_heap "https://github.com/lukenar11/moleculeos/blob/main/kernel/src/heap/block.cpp"
click node_interrupts "https://github.com/lukenar11/moleculeos/tree/main/arch/i386/kernel/src/idt"
click node_isr "https://github.com/lukenar11/moleculeos/blob/main/arch/i386/kernel/src/idt/isr_handler.cpp"
click node_irq "https://github.com/lukenar11/moleculeos/blob/main/arch/i386/kernel/src/idt/irq_handler.cpp"
click node_regdump "https://github.com/lukenar11/moleculeos/blob/main/arch/i386/kernel/include/utils/regs.hpp"
click node_syscontrol "https://github.com/lukenar11/moleculeos/tree/main/arch/i386/kernel/src/sys"
click node_ata "https://github.com/lukenar11/moleculeos/blob/main/drivers/src/ata/pio.cpp"
click node_keyboard "https://github.com/lukenar11/moleculeos/blob/main/drivers/src/ps2/keyboard_input.cpp"
click node_vga "https://github.com/lukenar11/moleculeos/blob/main/drivers/src/vga/text_mode.cpp"
click node_storage "https://github.com/lukenar11/moleculeos/blob/main/kernel/src/storemgr/storage_manager.cpp"
click node_filesystem "https://github.com/lukenar11/moleculeos/blob/main/kernel/src/filesys/mofs2.cpp"
click node_terminal "https://github.com/lukenar11/moleculeos/blob/main/terminal/src/terminal.cpp"
click node_shell "https://github.com/lukenar11/moleculeos/blob/main/shell/src/shell.cpp"
click node_commands "https://github.com/lukenar11/moleculeos/tree/main/shell/src/cmds"
click node_textoutput "https://github.com/lukenar11/moleculeos/blob/main/runtime/stdlib/src/text_output.cpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_kernelmain,node_heap,node_user toneBlue
class node_interrupts,node_isr,node_irq,node_regdump,node_syscontrol toneAmber
class node_ata,node_keyboard,node_vga toneMint
class node_storage,node_filesystem toneRose
class node_terminal,node_shell,node_commands,node_textoutput toneIndigo
```

## Components

### Kernel runtime

- [Kernel scheduler](https://github.com/lukenar11/moleculeos/blob/main/kernel/src/main.cpp): `kernel/src/main.cpp`
- [Block allocator](https://github.com/lukenar11/moleculeos/blob/main/kernel/src/heap/block.cpp): `kernel/src/heap/block.cpp`

### i386 architecture

- [Interrupt handling](https://github.com/lukenar11/moleculeos/tree/main/arch/i386/kernel/src/idt): `arch/i386/kernel/src/idt`
- [Exception handler](https://github.com/lukenar11/moleculeos/blob/main/arch/i386/kernel/src/idt/isr_handler.cpp): `arch/i386/kernel/src/idt/isr_handler.cpp`
- [IRQ handler](https://github.com/lukenar11/moleculeos/blob/main/arch/i386/kernel/src/idt/irq_handler.cpp): `arch/i386/kernel/src/idt/irq_handler.cpp`
- [CPU register state](https://github.com/lukenar11/moleculeos/blob/main/arch/i386/kernel/include/utils/regs.hpp): `arch/i386/kernel/include/utils/regs.hpp`
- [System control](https://github.com/lukenar11/moleculeos/tree/main/arch/i386/kernel/src/sys): `arch/i386/kernel/src/sys`

### Hardware devices

- [ATA-PIO driver](https://github.com/lukenar11/moleculeos/blob/main/drivers/src/ata/pio.cpp): `drivers/src/ata/pio.cpp`
- [PS/2 keyboard](https://github.com/lukenar11/moleculeos/blob/main/drivers/src/ps2/keyboard_input.cpp): `drivers/src/ps2/keyboard_input.cpp`
- [VGA text mode](https://github.com/lukenar11/moleculeos/blob/main/drivers/src/vga/text_mode.cpp): `drivers/src/vga/text_mode.cpp`

### RAM storage

- [Storage manager](https://github.com/lukenar11/moleculeos/blob/main/kernel/src/storemgr/storage_manager.cpp): `kernel/src/storemgr/storage_manager.cpp`
- [MOFS2 filesystem](https://github.com/lukenar11/moleculeos/blob/main/kernel/src/filesys/mofs2.cpp): `kernel/src/filesys/mofs2.cpp`

### User interface

- [Terminal](https://github.com/lukenar11/moleculeos/blob/main/terminal/src/terminal.cpp): `terminal/src/terminal.cpp`
- [Shell interpreter](https://github.com/lukenar11/moleculeos/blob/main/shell/src/shell.cpp): `shell/src/shell.cpp`
- [Shell commands](https://github.com/lukenar11/moleculeos/tree/main/shell/src/cmds): `shell/src/cmds`
- [Text output](https://github.com/lukenar11/moleculeos/blob/main/runtime/stdlib/src/text_output.cpp): `runtime/stdlib/src/text_output.cpp`

### Other components

- **OS user**

## Connections

- Kernel scheduler → Block allocator: initializes (evidence: `kernel/src/main.cpp`)
- Kernel scheduler → ATA-PIO driver: initializes (evidence: `kernel/src/main.cpp`)
- Kernel scheduler → Storage manager: initializes (evidence: `kernel/src/main.cpp`)
- Kernel scheduler → Storage manager: loads filesystem (evidence: `kernel/src/main.cpp`)
- Kernel scheduler → Terminal: steps repeatedly (evidence: `kernel/src/main.cpp`)
- Kernel scheduler → Interrupt handling: uses scheduling
- Storage manager → ATA-PIO driver: reads and writes
- Storage manager → MOFS2 filesystem: loads and saves
- MOFS2 filesystem → Block allocator: allocates file data
- IRQ handler → PS/2 keyboard: dispatches keyboard IRQ
- IRQ handler → CPU register state: uses register state
- Exception handler → CPU register state: reads register state (evidence: `arch/i386/kernel/src/idt/isr_handler.cpp`)
- Exception handler → Text output: prints diagnostics (evidence: `arch/i386/kernel/src/idt/isr_handler.cpp`)
- Exception handler → System control: halts execution (evidence: `arch/i386/kernel/src/idt/isr_handler.cpp`)
- Interrupt handling → Exception handler: routes exceptions
- Interrupt handling → IRQ handler: routes hardware IRQs
- Terminal → Shell interpreter: runs shell
- Shell interpreter → Shell commands: dispatches commands
- OS user → Terminal: interacts
- Shell commands → MOFS2 filesystem: manages files
- Terminal → VGA text mode: displays text
