# dotcorr/oscortex architecture

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

- Interactive diagram: https://gitdiagram.com/dotcorr/oscortex
- Repository: https://github.com/dotcorr/oscortex

## Overview

1. **High-level shape**
   OSCortex is a custom operating system repo split into four major layers: a Rust kernel, a small Rust PID 1 init process, a Flutter-based system shell and apps, and build/release tooling that assembles bootable images. The key architectural boundary is that Flutter owns UI, while the kernel owns hardware and policy.

2. **Boot and startup flow**
   The boot path is Limine → kernel → `userspace/init` (PID 1) → `oscortex-host` Flutter embedder → shell rendering. The kernel does not host the UI directly; it launches a userspace supervisor first, then the embedder that connects Flutter to kernel services.

3. **Kernel core**
   `kernel/` is a `no_std` Rust OS kernel. It includes memory management, process and scheduler logic, syscall dispatch, IPC, security, filesystem support, networking, and a compositor/window manager. This is the central subsystem that owns all privileged operations and mediates access to hardware.

4. **Architecture-specific hardware layer**
   The kernel has explicit per-architecture code under `kernel/src/arch/`, with x86_64 the primary bring-up target and aarch64/riscv64 scaffolding present. x86_64 contains ACPI, APIC, GDT/IDT, interrupts, SMP, paging, PCI, port I/O, and syscall setup, which indicates the OS is designed around a traditional bare-metal hardware abstraction boundary.

5. **Display and input pipeline**
   The visible UI path is kernel compositor/window manager → framebuffer/scanout driver → Flutter surface in the embedder → shell UI in Dart. Driver modules like `fb`, `ps2`, `usb`, `usb_hid`, and `xhci_runtime` provide input and output plumbing into the compositor and higher-level UI.

6. **Process and app model**
   The repository is built around one process per app. Kernel-side code under `process/`, `sched/`, `syscall/`, `ipc/`, `isolate/`, and `app_registry/` suggests a managed application lifecycle with isolation, launch, waiting/reaping, file descriptors, and IPC as the primary interfaces between shell, init, and apps.

7. **Cortex subsystem**
   `kernel/src/cortex/` is a distinct AI-oriented kernel subsystem. It includes context, inference, driver generation, healing, observer, and PID-0 logic, implying a privileged service layer that can inspect runtime state and influence recovery or driver behavior. This is a kernel-internal capability, not a userspace AI service.

8. **Storage, filesystems, and app distribution**
   Filesystem support is split between `ext2`, `initramfs`, and `ramdisk`, with disk/storage drivers such as `nvme` and `virtio_blk`. The README indicates `.osx` bundles are the intended installable app format, so app deployment is meant to happen at runtime rather than by reflashing the ISO.

9. **Userspace init and shell**
   `userspace/init/` is the PID 1 supervisor responsible for spawning the shell and reaping children. `apps/oscortex_app/` is the Flutter-based system shell, currently slimmed for fast startup in QEMU. This keeps the desktop/application layer fully separated from the kernel.

10. **Flutter embedding boundary**
    `tools/flutter-embedder/` is the host binary that binds the Flutter engine to kernel syscalls for surfaces, vsync, and input. This is the main bridge between the Dart/Flutter world and the OS kernel, and the repo treats it as a dedicated runtime component rather than a general-purpose Linux-style window system.

11. **Engine patching and build artifacts**
    `tools/flutter-engine/` contains patching logic for `libflutter_engine.so`, indicating the Flutter runtime is customized for OSCortex’s boot and rendering path. The repo also contains `scripts/build-iso.sh`, `scripts/run-qemu.sh`, and `scripts/embed-flutter-engine.sh`, which are the assembly points for producing and booting a full OS image.

12. **Testing and validation**
    `tests/kernel/` contains bare-metal unit tests for low-level subsystems such as PCI BARs, NVMe registers, USB HID, vring, and xHCI caps, while `tests/integration/` covers kernel build and QEMU driver behavior. There is also a `harness/verify_engine_patches.py` check, showing that engine patch correctness is part of the system’s validation boundary.

13. **Release and CI/CD**
    `.github/workflows/ci.yml` and `release.yml`, plus the `tools/xtask/` command surface, handle build/test/release automation. The repo is structured to produce bootable ISOs and versioned releases from the main branch, with the development branch carrying integration work before promotion.

14. **Useful diagram boundaries**
    If you draw the architecture, the most important boundaries are: hardware vs kernel, kernel vs userspace init, init vs Flutter host, Flutter host vs shell/apps, and kernel-internal service layers such as compositor, syscalls, drivers, and Cortex. The key data flows are input events into the kernel, framebuffer/surface output back to the display, and process/syscall/IPC traffic between kernel-managed user processes.

Main entry points: [`kernel/src/main.rs`](https://github.com/dotcorr/oscortex/blob/develop/kernel/src/main.rs) (Kernel core), [`tools/flutter-embedder/src/main.rs`](https://github.com/dotcorr/oscortex/blob/develop/tools/flutter-embedder/src/main.rs) (Flutter host), [`scripts/build-iso.sh`](https://github.com/dotcorr/oscortex/blob/develop/scripts/build-iso.sh) (Build tools), [`kernel/src/drivers/mod.rs`](https://github.com/dotcorr/oscortex/blob/develop/kernel/src/drivers/mod.rs) (Drivers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_kernel["Kernel"]
  node_kernel_main["Kernel core<br/>no_std kernel<br/>[main.rs]"]
  node_kernel_arch["Arch layer<br/>hardware bring-up<br/>[mod.rs]"]
  node_kernel_mm["Memory<br/>mm subsystem<br/>[mod.rs]"]
  node_kernel_proc["Processes<br/>process lifecycle<br/>[mod.rs]"]
  node_kernel_sched["Scheduler<br/>task scheduling<br/>[mod.rs]"]
  node_kernel_syscall["Syscalls<br/>syscall layer<br/>[mod.rs]"]
  node_kernel_ipc(("IPC<br/>message passing<br/>[mod.rs]"))
  node_kernel_drivers["Drivers<br/>device layer<br/>[mod.rs]"]
  node_kernel_fs["Filesystems<br/>storage fs<br/>[mod.rs]"]
  node_kernel_net["Networking<br/>network stack<br/>[mod.rs]"]
  node_kernel_wm["Compositor<br/>window manager<br/>[mod.rs]"]
  node_kernel_cortex{{"Cortex<br/>ai subsystem<br/>[mod.rs]"}}
  node_kernel_embedder["Embedder ABI<br/>surface bridge<br/>[mod.rs]"]
end

subgraph group_group_userspace["Userspace"]
  node_init_pid1["PID 1<br/>userspace init<br/>[main.rs]"]
end

subgraph group_group_tools["Tooling"]
  node_flutter_embedder["Flutter host<br/>runtime embedder<br/>[main.rs]"]
  node_build_tools["Build tools<br/>release tooling<br/>[build-iso.sh]"]
end

subgraph group_group_apps["Apps"]
  node_oscortex_app["Shell app<br/>Flutter UI<br/>[main.dart]"]
end

subgraph group_group_tests["Tests"]
  node_kernel_tests["Kernel tests<br/>bare-metal tests<br/>[main.rs]"]
end

node_limine_boot["Limine<br/>bootloader<br/>[limine.conf]"]

node_limine_boot -->|"boots"| node_kernel_main
node_kernel_main -->|"bring-up"| node_kernel_arch
node_kernel_main -->|"manages"| node_kernel_mm
node_kernel_main -->|"spawns"| node_kernel_proc
node_kernel_main -->|"schedules"| node_kernel_sched
node_kernel_main -->|"exposes"| node_kernel_syscall
node_kernel_main -->|"routes"| node_kernel_ipc
node_kernel_main -->|"drives"| node_kernel_drivers
node_kernel_main -->|"mounts"| node_kernel_fs
node_kernel_main -->|"networking"| node_kernel_net
node_kernel_main -->|"renders"| node_kernel_wm
node_kernel_main -->|"hosts"| node_kernel_cortex
node_kernel_main -->|"bridges"| node_kernel_embedder
node_kernel_proc -->|"launches"| node_init_pid1
node_init_pid1 -->|"spawns"| node_flutter_embedder
node_flutter_embedder -->|"runs"| node_oscortex_app
node_kernel_wm -->|"surface path"| node_kernel_embedder
node_kernel_drivers -->|"feeds input"| node_kernel_wm
node_kernel_embedder -->|"abi"| node_flutter_embedder
node_build_tools -->|"builds"| node_kernel_main
node_build_tools -->|"patches"| node_flutter_embedder
node_build_tools -->|"packages"| node_init_pid1
node_kernel_tests -->|"validates"| node_kernel_drivers
node_kernel_tests -->|"checks"| node_kernel_main

click node_limine_boot "https://github.com/dotcorr/oscortex/blob/develop/iso_root/limine.conf"
click node_kernel_main "https://github.com/dotcorr/oscortex/blob/develop/kernel/src/main.rs"
click node_kernel_arch "https://github.com/dotcorr/oscortex/blob/develop/kernel/src/arch/mod.rs"
click node_kernel_mm "https://github.com/dotcorr/oscortex/blob/develop/kernel/src/mm/mod.rs"
click node_kernel_proc "https://github.com/dotcorr/oscortex/blob/develop/kernel/src/process/mod.rs"
click node_kernel_sched "https://github.com/dotcorr/oscortex/blob/develop/kernel/src/sched/mod.rs"
click node_kernel_syscall "https://github.com/dotcorr/oscortex/blob/develop/kernel/src/syscall/mod.rs"
click node_kernel_ipc "https://github.com/dotcorr/oscortex/blob/develop/kernel/src/ipc/mod.rs"
click node_kernel_drivers "https://github.com/dotcorr/oscortex/blob/develop/kernel/src/drivers/mod.rs"
click node_kernel_fs "https://github.com/dotcorr/oscortex/blob/develop/kernel/src/fs/mod.rs"
click node_kernel_net "https://github.com/dotcorr/oscortex/blob/develop/kernel/src/net/mod.rs"
click node_kernel_wm "https://github.com/dotcorr/oscortex/blob/develop/kernel/src/wm/mod.rs"
click node_kernel_cortex "https://github.com/dotcorr/oscortex/blob/develop/kernel/src/cortex/mod.rs"
click node_kernel_embedder "https://github.com/dotcorr/oscortex/blob/develop/kernel/src/embedder/mod.rs"
click node_init_pid1 "https://github.com/dotcorr/oscortex/blob/develop/userspace/init/src/main.rs"
click node_flutter_embedder "https://github.com/dotcorr/oscortex/blob/develop/tools/flutter-embedder/src/main.rs"
click node_oscortex_app "https://github.com/dotcorr/oscortex/blob/develop/apps/oscortex_app/lib/main.dart"
click node_build_tools "https://github.com/dotcorr/oscortex/blob/develop/scripts/build-iso.sh"
click node_kernel_tests "https://github.com/dotcorr/oscortex/blob/develop/tests/kernel/unit/main.rs"

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_kernel_main,node_kernel_arch,node_kernel_mm,node_kernel_proc,node_kernel_sched,node_kernel_syscall,node_kernel_ipc,node_kernel_drivers,node_kernel_fs,node_kernel_net,node_kernel_wm,node_kernel_cortex,node_kernel_embedder toneBlue
class node_init_pid1 toneAmber
class node_flutter_embedder,node_build_tools toneMint
class node_oscortex_app toneRose
class node_kernel_tests toneIndigo
class node_limine_boot toneNeutral
```

## Components

### Kernel

Privileged Rust OS kernel and hardware-facing subsystems

- [Kernel core](https://github.com/dotcorr/oscortex/blob/develop/kernel/src/main.rs): no_std kernel · Top-level kernel runtime and privileged control plane · `kernel/src/main.rs`
- [Arch layer](https://github.com/dotcorr/oscortex/blob/develop/kernel/src/arch/mod.rs): hardware bring-up · Architecture-specific boot, interrupt, memory, and syscall setup · `kernel/src/arch/mod.rs`
- [Memory](https://github.com/dotcorr/oscortex/blob/develop/kernel/src/mm/mod.rs): mm subsystem · Frame allocation, heap, and paging management · `kernel/src/mm/mod.rs`
- [Processes](https://github.com/dotcorr/oscortex/blob/develop/kernel/src/process/mod.rs): process lifecycle · Process loading, ELF handling, and user process support · `kernel/src/process/mod.rs`
- [Scheduler](https://github.com/dotcorr/oscortex/blob/develop/kernel/src/sched/mod.rs): task scheduling · Execution scheduling and run-queue control · `kernel/src/sched/mod.rs`
- [Syscalls](https://github.com/dotcorr/oscortex/blob/develop/kernel/src/syscall/mod.rs): syscall layer · Syscall dispatch, tables, wait/poll, and POSIX-facing handlers · `kernel/src/syscall/mod.rs`
- [IPC](https://github.com/dotcorr/oscortex/blob/develop/kernel/src/ipc/mod.rs): message passing · Kernel message-passing and isolation boundaries · `kernel/src/ipc/mod.rs`
- [Drivers](https://github.com/dotcorr/oscortex/blob/develop/kernel/src/drivers/mod.rs): device layer · Platform, storage, input, networking, and runtime device drivers · `kernel/src/drivers/mod.rs`
- [Filesystems](https://github.com/dotcorr/oscortex/blob/develop/kernel/src/fs/mod.rs): storage fs · Initramfs, ramdisk, and ext2 support · `kernel/src/fs/mod.rs`
- [Networking](https://github.com/dotcorr/oscortex/blob/develop/kernel/src/net/mod.rs): network stack · Kernel networking and TCP support · `kernel/src/net/mod.rs`
- [Compositor](https://github.com/dotcorr/oscortex/blob/develop/kernel/src/wm/mod.rs): window manager · Kernel-side compositor and window management · `kernel/src/wm/mod.rs`
- [Cortex](https://github.com/dotcorr/oscortex/blob/develop/kernel/src/cortex/mod.rs): ai subsystem · Privileged runtime inspection, inference, and healing subsystem · `kernel/src/cortex/mod.rs`
- [Embedder ABI](https://github.com/dotcorr/oscortex/blob/develop/kernel/src/embedder/mod.rs): surface bridge · Kernel ABI exposed to the Flutter host for surfaces, input, and timing · `kernel/src/embedder/mod.rs`

### Userspace

PID 1 and shell runtime

- [PID 1](https://github.com/dotcorr/oscortex/blob/develop/userspace/init/src/main.rs): userspace init · Supervisor that starts and reaps user processes · `userspace/init/src/main.rs`

### Tooling

Build, embedder, and release automation

- [Flutter host](https://github.com/dotcorr/oscortex/blob/develop/tools/flutter-embedder/src/main.rs): runtime embedder · Native host that connects Flutter to kernel services · `tools/flutter-embedder/src/main.rs`
- [Build tools](https://github.com/dotcorr/oscortex/blob/develop/scripts/build-iso.sh): release tooling · Image assembly, engine patching, and workflow automation · `scripts/build-iso.sh`

### Apps

Flutter application layer

- [Shell app](https://github.com/dotcorr/oscortex/blob/develop/apps/oscortex_app/lib/main.dart): Flutter UI · System shell and application UI written in Dart · `apps/oscortex_app/lib/main.dart`

### Tests

Kernel and integration validation

- [Kernel tests](https://github.com/dotcorr/oscortex/blob/develop/tests/kernel/unit/main.rs): bare-metal tests · Low-level kernel unit tests for drivers and core hardware abstractions · `tests/kernel/unit/main.rs`

### Other components

- [Limine](https://github.com/dotcorr/oscortex/blob/develop/iso_root/limine.conf): bootloader · Bootloader entry that hands off to the OS kernel · `iso_root/limine.conf`

## Connections

- Limine → Kernel core: boots · Bootloader transfers control to the kernel
- Kernel core → Arch layer: bring-up · Kernel initializes architecture-specific hardware support
- Kernel core → Memory: manages · Kernel owns memory management
- Kernel core → Processes: spawns · Kernel loads and manages user processes
- Kernel core → Scheduler: schedules · Kernel schedules runnable tasks
- Kernel core → Syscalls: exposes · Kernel dispatches syscalls into privileged handlers
- Kernel core → IPC: routes · Kernel mediates inter-process communication
- Kernel core → Drivers: drives · Kernel initializes and uses hardware drivers
- Kernel core → Filesystems: mounts · Kernel provides filesystem access
- Kernel core → Networking: networking · Kernel owns network protocol support
- Kernel core → Compositor: renders · Kernel compositor manages display composition
- Kernel core → Cortex: hosts · Kernel contains the Cortex privileged subsystem
- Kernel core → Embedder ABI: bridges · Kernel exposes embedder ABI for Flutter host integration
- Processes → PID 1: launches · Kernel starts PID 1 as the first userspace process
- PID 1 → Flutter host: spawns · Init supervises the Flutter host process
- Flutter host → Shell app: runs · Native host embeds the Flutter shell UI
- Compositor → Embedder ABI: surface path · Compositor output is presented through the embedder boundary
- Drivers → Compositor: feeds input · Input and framebuffer drivers feed compositor state
- Embedder ABI → Flutter host: abi · Host talks to kernel through embedder ABI
- Build tools → Kernel core: builds · Tooling assembles kernel and bootable images
- Build tools → Flutter host: patches · Tooling customizes the Flutter engine/host integration
- Build tools → PID 1: packages · Tooling includes init and runtime artifacts in the image
- Kernel tests → Drivers: validates · Tests cover low-level driver and hardware abstractions
- Kernel tests → Kernel core: checks · Tests exercise bare-metal kernel behavior
