# hacke-rc/optimistos architecture

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

- Interactive diagram: https://gitdiagram.com/hacke-rc/optimistos
- Repository: https://github.com/hacke-rc/optimistos

## Overview

##### Main Components
- Bootloader: Represent the bootloader module (Limine) and its configuration. Indicate that the OS uses UEFI and the provided limine.cfg file.
- CPU Initialization: Create a block for CPU-related components that includes:
- GDT (from kernel/gdt)
- IDT (from kernel/idt)
- ACPI (from kernel/acpi) for managing hardware configurations
- Memory Management: Separate into two distinct areas:
- Heap allocation (in kernel/memory using mallocx)
- Paging and virtual memory management (in kernel/paging including free list handling, page frame allocator, etc.)
- Process and Scheduling: Represent process management (kernel/process) and scheduling (kernel/scheduler) modules, indicating that the scheduling mechanism and context switching are key in managing processes.
- I/O and Renderer: Group the input/output functions (kernel/io) and the basic rendering functionalities (kernel/renderer, printutils) which are used for basic debugging and display output.
- Libraries and Utilities: Mention supporting libraries in kernel/lib (e.g., lock management, memory abstractions, string utilities) and include directories for various STL-like functionalities under kernel/include, which bolster the rest of the system.
- External Resources & Media: Note the presence of external files (kernel/external) and media (images in media/) that the OS uses during boot or for assets.

##### Relationships and Interactions
- The UEFI boot process launches the Limine bootloader, which triggers the kernel entry point (kernel/kernelEntry.cpp/hpp).
- That early CPU initialization (setting up GDT/IDT and ACPI routines) happens during boot.
- After boot, the memory management modules initialize paging and allocate heap space.
- The scheduler and process modules depend on the CPU initialization to manage context switching, and they interact with memory management for process address space setup.
- I/O and renderer modules are used by several components for diagnostics and possibly user interaction.

##### Architectural and Design Patterns
- Modular structure: The project is organized into clear directories for specific hardware and system subsystems (representing a layered architecture).
- Initialization sequence: The bootloader hands off control to low-level initialization routines for CPU and memory.
- Separation of concerns: Each subsystem (CPU, Memory, Process, I/O) is clearly isolated, enabling focused improvements and debugging.

##### Relevant Technologies and Frameworks
- UEFI and Limine bootloader
- Assembly and C++ for low-level operations
- External dependency for heap allocation (mallocx)
- Emphasis on low-level hardware interfacing components such as ACPI for hardware configuration

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Boot Sequence
    subgraph "Boot Sequence"
        Bootloader["Bootloader (Limine)"]:::boot
        KernelEntry["Kernel Entry Point"]:::boot
    end
    Bootloader -->|"handoff"| KernelEntry

    %% CPU Initialization
    subgraph "CPU Initialization"
        GDT["GDT"]:::cpu
        IDT["IDT"]:::cpu
        ACPI["ACPI"]:::cpu
        SMP["SMP"]:::cpu
    end
    KernelEntry -->|"initCPU"| GDT
    KernelEntry -->|"initCPU"| IDT
    KernelEntry -->|"initCPU"| ACPI
    KernelEntry -->|"initCPU"| SMP

    %% Memory Management
    subgraph "Memory Management"
        Heap["Heap Allocation"]:::memory
        Paging["Paging (VirtualMemory)"]:::memory
    end
    KernelEntry -->|"initMemory"| Heap
    KernelEntry -->|"initMemory"| Paging

    %% Process & Scheduling
    subgraph "Process & Scheduling"
        Process["Process Management"]:::process
        Scheduler["Scheduler"]:::process
    end
    Heap -->|"setupProc"| Process
    Paging -->|"setupProc"| Process
    GDT -->|"contextSwitch"| Scheduler
    SMP -->|"contextSwitch"| Scheduler
    Process -->|"schedule"| Scheduler

    %% I/O & Renderer
    subgraph "I/O & Renderer"
        IO["I/O"]:::io
        Renderer["Renderer"]:::io
    end
    Process -->|"ioCall"| IO
    Scheduler -->|"debugOut"| Renderer

    %% Supporting Libraries
    subgraph "Supporting Libraries"
        Libraries["Libraries"]:::lib
        PrintUtils["PrintUtilities"]:::lib
    end
    Libraries ---|"support"| KernelEntry
    PrintUtils ---|"support"| IO

    %% External Resources & Media
    subgraph "External Resources"
        External["External Resources"]:::external
        Media["Media Assets"]:::external
    end
    Bootloader -->|"resources"| External
    Bootloader -->|"resources"| Media

    %% Click Events
    click Bootloader "https://github.com/hacke-rc/optimistos/blob/main/limine/limine.cfg"
    click KernelEntry "https://github.com/hacke-rc/optimistos/blob/main/kernel/kernelEntry.cpp"
    click GDT "https://github.com/hacke-rc/optimistos/blob/main/kernel/gdt/gdt.asm"
    click IDT "https://github.com/hacke-rc/optimistos/blob/main/kernel/idt/idt.cpp"
    click ACPI "https://github.com/hacke-rc/optimistos/blob/main/kernel/acpi/acpi.cpp"
    click SMP "https://github.com/hacke-rc/optimistos/blob/main/kernel/smp/smp.cpp"
    click Heap "https://github.com/hacke-rc/optimistos/blob/main/kernel/memory/malloc.cpp"
    click Paging "https://github.com/hacke-rc/optimistos/blob/main/kernel/paging/paging.asm"
    click Process "https://github.com/hacke-rc/optimistos/blob/main/kernel/process/process.cpp"
    click Scheduler "https://github.com/hacke-rc/optimistos/blob/main/kernel/scheduler/scheduler.cpp"
    click IO "https://github.com/hacke-rc/optimistos/blob/main/kernel/io/io.cpp"
    click Renderer "https://github.com/hacke-rc/optimistos/blob/main/kernel/renderer/BasicRenderer.cpp"
    click Libraries "https://github.com/hacke-rc/optimistos/blob/main/kernel/lib/lock.cpp"
    click PrintUtils "https://github.com/hacke-rc/optimistos/blob/main/kernel/printutils/e9print.cpp"
    click External "https://github.com/hacke-rc/optimistos/tree/main/kernel/external"
    click Media "https://github.com/hacke-rc/optimistos/blob/main/media/blue.bmp"

    %% Styles
    classDef boot fill:#ADD8E6,stroke:#000,stroke-width:1px,font-size:12px;
    classDef cpu fill:#90EE90,stroke:#000,stroke-width:1px,font-size:12px;
    classDef memory fill:#FFFFE0,stroke:#000,stroke-width:1px,font-size:12px;
    classDef process fill:#F08080,stroke:#000,stroke-width:1px,font-size:12px;
    classDef io fill:#D3D3D3,stroke:#000,stroke-width:1px,font-size:12px;
    classDef lib fill:#FFB6C1,stroke:#000,stroke-width:1px,font-size:12px;
    classDef external fill:#E0FFFF,stroke:#000,stroke-width:1px,font-size:12px;
```
