# ragingo/ragingos architecture

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

- Interactive diagram: https://gitdiagram.com/ragingo/ragingos
- Repository: https://github.com/ragingo/ragingos

## Overview

##### Main Components
- Boot Loader Component:
- Directory: src/RagingosLoaderPkg
- Role: Manages initial boot tasks and transfers control to the OS kernel.
- Kernel Component:
- Directory: src/kernel
- Role: Contains core OS functions such as task management, memory management, interrupt handling, device drivers (e.g., for USB, ACPI, PCI), file systems (FAT), graphical and console UI, and system calls.
- Applications Component:
- Directory: src/apps
- Role: Includes a variety of example/userland applications (such as cp, cube, mandel, paint, etc.) which use the services provided by the kernel.
- Libraries and Utilities:
- Directory: lib and tools
- Role: Auxiliary libraries (e.g., stb_image in apps/lib) and inspection/build tools (like elf_checker in tools, makefont.py) that support development or runtime features.
- Build and Scripts Component:
- Directory: scripts, setup
- Role: Contains shell scripts to build various parts (kernel, EDK2, libcxx, edk2_loader) and environment setup configuration for multiple platforms (Windows, WSL2, etc.).
- Resources:
- Directory: res
- Role: Holds fonts, images, and text files that might be used by the kernel or applications.

##### Out the Relationships and Interactions
- The Boot Loader initializes execution; it loads and transfers control to the Kernel.
- The Kernel comprises multiple submodules:
- Drivers: USB, ACPI, PCI, keyboard, mouse, etc.
- System Services: Memory manager, task scheduler, paging, logging, system call handler.
- UI Layer: Includes both text-based console and graphical components.
- User-space applications (within src/apps) interact with the Kernel via system calls. They serve various functionalities (file handling, arithmetic processing, graphics, and so on).
- Build scripts automate and coordinate the compilation and linking of the loader, kernel, and applications.
- Tools and libraries assist with utility tasks (e.g., ELF checking, image handling) that support both development and runtime operations.

##### Architectural Patterns and Design Principles
- Modularity: The clear separation into loader, kernel, and apps indicates modular layering.
- Layered Architecture: Boot loader at the very bottom, kernel core in the middle, and user applications on top.
- Driver Abstraction: The drivers for various peripherals (USB, ACPI, etc.) are organized into dedicated directories, reflecting a separation of concerns.
- Build & Deployment Automation: The scripts and setup directories reflect an emphasis on automated testing, build, and deployment.
- Use of Standard Tools: The integration of pre-commit, clang-format, and Makefiles indicates adherence to coding and quality standards.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Boot Layer
    subgraph "Boot Layer"
        BL["Boot Loader"]:::boot
    end

    %% Kernel Layer
    subgraph "Kernel Layer"
        KC["Kernel Core"]:::kernel
        %% Device Drivers Subgroup
        subgraph "Device Drivers"
            GD["General Drivers"]:::kernel
            UD["USB Drivers"]:::kernel
        end
        %% System Services Subgroup
        subgraph "System Services"
            MM["Memory Manager"]:::kernel
            PA["Paging"]:::kernel
            TM["Task Management"]:::kernel
            SC["System Calls"]:::kernel
            IH["Interrupt Handling"]:::kernel
            IRQ["IRQ Flags"]:::kernel
        end
        %% UI Subsystem Subgroup
        subgraph "UI Subsystem"
            UI["Console/Graphics UI"]:::kernel
        end
        %% Intra-Kernel Relationships
        KC -->|"initializes"| GD
        KC -->|"initializes"| MM
        KC -->|"initializes"| UI
        GD -->|"includes"| UD
        MM -->|"supports"| PA
        PA -->|"enables"| TM
        TM -->|"triggers"| SC
        SC -->|"leads to"| IH
        IH -->|"configures"| IRQ
    end

    %% User Applications
    subgraph "User Applications"
        APPS["User Applications"]:::app
    end

    %% Supporting & Build
    subgraph "Supporting & Build"
        AL["Auxiliary Libraries"]:::supp
        DT["Development Tools"]:::supp
        BS["Build Scripts"]:::build
        ES["Environment Setup"]:::build
        RES["Resources"]:::res
    end

    %% Relationships Between Layers
    BL -->|"transfers control"| KC
    SC ---|"syscall interface"| APPS
    
    BS ---|"builds"| BL
    BS ---|"builds"| KC
    BS ---|"builds"| APPS
    ES ---|"configures"| BS

    AL ---|"supports"| KC
    AL ---|"supports"| APPS

    DT ---|"assists"| KC
    DT ---|"assists"| APPS

    RES ---|"used by"| KC
    RES ---|"used by"| APPS

    %% Click Events
    click BL "https://github.com/ragingo/ragingos/tree/main/src/RagingosLoaderPkg"
    click KC "https://github.com/ragingo/ragingos/tree/main/src/kernel"
    click GD "https://github.com/ragingo/ragingos/tree/main/src/kernel/drivers"
    click UD "https://github.com/ragingo/ragingos/tree/main/src/kernel/drivers/usb"
    click MM "https://github.com/ragingo/ragingos/blob/main/src/kernel/memory_manager.cpp"
    click PA "https://github.com/ragingo/ragingos/blob/main/src/kernel/paging.cpp"
    click TM "https://github.com/ragingo/ragingos/blob/main/src/kernel/task.cpp"
    click SC "https://github.com/ragingo/ragingos/blob/main/src/kernel/syscall.cpp"
    click IH "https://github.com/ragingo/ragingos/blob/main/src/kernel/interrupt.cpp"
    click IRQ "https://github.com/ragingo/ragingos/blob/main/src/kernel/irqflags.hpp"
    click UI "https://github.com/ragingo/ragingos/tree/main/src/kernel/ui"
    click APPS "https://github.com/ragingo/ragingos/tree/main/src/apps"
    click AL "https://github.com/ragingo/ragingos/tree/main/lib"
    click DT "https://github.com/ragingo/ragingos/tree/main/tools"
    click BS "https://github.com/ragingo/ragingos/tree/main/scripts"
    click ES "https://github.com/ragingo/ragingos/tree/main/setup"
    click RES "https://github.com/ragingo/ragingos/tree/main/res"

    %% Styles
    classDef boot fill:#AEDFF7,stroke:#000,stroke-width:2px;
    classDef kernel fill:#C6F7C1,stroke:#000,stroke-width:2px;
    classDef app fill:#F7C6CD,stroke:#000,stroke-width:2px;
    classDef supp fill:#F9E79F,stroke:#000,stroke-width:2px;
    classDef build fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef res fill:#FFD700,stroke:#000,stroke-width:2px;
```
