# theseus-os/theseus architecture

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

- Interactive diagram: https://gitdiagram.com/theseus-os/theseus
- Repository: https://github.com/theseus-os/theseus

## Overview

#### Purpose and entry points
Theseus is an experimental Rust OS focused on compiler-enforced resource management, fault recovery, and live runtime evolution. The primary developer entry point is `make run`, which builds a bootable image and launches QEMU; `make ARCH=aarch64 run` targets ARMv8. Build orchestration and target definitions reside in `Makefile`, `cfg/Config.mk`, and `rust-toolchain.toml`.

#### Boot and kernel composition
Boot begins in the architecture-specific nano-core, with BIOS and UEFI paths, assembly startup, linker scripts, and early runtime support in `kernel/nano_core/src/lib.rs`, `kernel/nano_core/src/bios.rs`, and `kernel/nano_core/src/uefi.rs`. Boot metadata is normalized through `kernel/boot_info/src/lib.rs`. Theseus is composed from many independently compiled Rust crates rather than a monolithic kernel binary; crate metadata and loading support are central to this model.

#### Initialization and dynamic module management
The root initialization path and first user-visible application are represented by `kernel/root/src/lib.rs`, `kernel/captain/src/lib.rs`, and `kernel/first_application/src/lib.rs`. Runtime crate discovery, metadata, loading, replacement, and serialization are handled across `kernel/mod_mgmt/src/lib.rs`, `kernel/crate_metadata/src/lib.rs`, and `kernel/crate_swap/src/lib.rs`. This is a key boundary: live evolution and fault recovery operate on crate/module units rather than conventional processes or shared libraries.

#### CPU, interrupts, tasks, and scheduling
Architecture abstraction separates x86_64 and AArch64 CPU, exception, interrupt-controller, and context-switch implementations: `kernel/cpu/src/lib.rs`, `kernel/interrupt_controller/src/lib.rs`, and `kernel/context_switch_regular/src/lib.rs`. Hardware interrupts feed task-oriented execution and deferred work. Core task lifecycle and scheduler integration live in `kernel/task/src/lib.rs`, with selectable scheduler implementations such as `kernel/scheduler_round_robin/src/lib.rs` and `kernel/scheduler_priority/src/lib.rs`. Synchronization, preemption, channels, and wait queues form the concurrency boundary.

#### Memory and allocation
Early initialization establishes architecture-specific virtual memory; general paging abstractions are in `kernel/memory/src/lib.rs` and `kernel/memory/src/paging/mapper.rs`, while platform implementations are split into `kernel/memory_x86_64/src/lib.rs` and `kernel/memory_aarch64/src/lib.rs`. Physical frames, pages, heaps, and slab allocation are distinct layers, represented by `kernel/frame_allocator/src/lib.rs`, `kernel/page_allocator/src/lib.rs`, and `kernel/heap/src/lib.rs`. These layers isolate unsafe hardware mapping and allocation policy from higher-level crates.

#### Devices, storage, networking, and UI
ACPI and PCI expose discovered platform devices to device management: `kernel/acpi/src/lib.rs`, `kernel/pci/src/lib.rs`, and `kernel/device_manager/src/lib.rs`. NIC drivers and queues feed the network stack, whose device/interface/socket boundary is in `kernel/net/src/lib.rs`, `kernel/net/src/interface.rs`, and `kernel/net/src/socket.rs`. Storage is surfaced through device/manager abstractions and filesystem nodes in `kernel/storage_manager/src/lib.rs`, `kernel/vfs_node/src/lib.rs`, and `kernel/memfs/src/lib.rs`. Console/TTY and framebuffer/window subsystems provide interactive output.

#### Applications, compatibility, and execution environments
Applications are Rust crates loaded into Theseus, including shell and system utilities in `applications/shell/src/lib.rs`, `applications/hull/src/lib.rs`, and `applications/ls/src/lib.rs`. Compatibility layers include a Theseus-oriented standard-library port at `ports/theseus_std/src/lib.rs` and C-library support at `tlibc/src/lib.rs`. WebAssembly execution is supported through `applications/wasm/src/lib.rs` and `kernel/wasi_interpreter/src/lib.rs`. Runtime validation primarily uses QEMU; supported deployment also includes real hardware, USB/PXE boot, and optional KVM acceleration.

Main entry points: [`kernel/root/src/lib.rs`](https://github.com/theseus-os/theseus/blob/theseus_main/kernel/root/src/lib.rs) (Root initialization), [`kernel/mod_mgmt/src/lib.rs`](https://github.com/theseus-os/theseus/blob/theseus_main/kernel/mod_mgmt/src/lib.rs) (Module management), [`kernel/task/src/lib.rs`](https://github.com/theseus-os/theseus/blob/theseus_main/kernel/task/src/lib.rs) (Tasks & scheduler), [`kernel/device_manager/src/lib.rs`](https://github.com/theseus-os/theseus/blob/theseus_main/kernel/device_manager/src/lib.rs) (Device manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_build["Build &amp; targets"]
  node_make["Make build orchestration"]
end

subgraph group_boot["Boot &amp; composition"]
  node_nano_core{{"Architecture nano-core<br/>boot runtime<br/>[lib.rs]"}}
  node_boot_info["Boot metadata<br/>boot contract<br/>[lib.rs]"]
  node_root["Root initialization<br/>kernel init<br/>[lib.rs]"]
  node_captain["Captain<br/>system coordinator<br/>[lib.rs]"]
end

subgraph group_runtime["Runtime evolution"]
  node_mod_mgmt["Module management<br/>runtime loader<br/>[lib.rs]"]
  node_crate_metadata["Crate metadata<br/>module metadata<br/>[lib.rs]"]
  node_crate_swap["Crate swapping<br/>live evolution<br/>[lib.rs]"]
end

subgraph group_core["CPU, tasks &amp; memory"]
  node_cpu["CPU abstraction<br/>architecture runtime<br/>[lib.rs]"]
  node_interrupts["Interrupt controller<br/>hardware interrupts<br/>[lib.rs]"]
  node_context_switch["Context switching<br/>task switching<br/>[lib.rs]"]
  node_tasks["Tasks &amp; scheduler<br/>concurrency runtime<br/>[lib.rs]"]
  node_memory["Paging abstractions<br/>virtual memory<br/>[lib.rs]"]
  node_frames["Frame allocator<br/>physical memory<br/>[lib.rs]"]
  node_heap["Heap allocator<br/>dynamic allocation<br/>[lib.rs]"]
end

subgraph group_services["Devices &amp; execution"]
  node_device_manager["Device manager<br/>device discovery<br/>[lib.rs]"]
  node_net["Network stack<br/>networking<br/>[lib.rs]"]
  node_storage["Storage manager<br/>storage services<br/>[lib.rs]"]
  node_vfs["VFS nodes<br/>filesystem interface<br/>[lib.rs]"]
  node_wasi["WASI interpreter<br/>WebAssembly runtime<br/>[lib.rs]"]
end

subgraph group_apps["Applications &amp; compatibility"]
  node_shell["Shell<br/>Theseus application<br/>[lib.rs]"]
  node_theseus_std["Theseus std port<br/>compatibility library<br/>[lib.rs]"]
end

node_make -->|"builds image with"| node_nano_core
node_nano_core -->|"normalizes boot data"| node_boot_info
node_boot_info -->|"initializes"| node_root
node_root -->|"starts"| node_captain
node_captain -->|"loads crates through"| node_mod_mgmt
node_mod_mgmt -->|"uses"| node_crate_metadata
node_mod_mgmt -->|"enables"| node_crate_swap
node_cpu -->|"implements platform support for"| node_interrupts
node_interrupts -->|"delivers deferred work to"| node_tasks
node_context_switch -->|"switches"| node_tasks
node_tasks -->|"uses address spaces"| node_memory
node_memory -->|"maps physical frames from"| node_frames
node_heap -->|"allocates pages through"| node_memory
node_root -->|"initializes"| node_cpu
node_root -->|"establishes"| node_memory
node_mod_mgmt -->|"loads"| node_shell
node_shell -->|"uses"| node_theseus_std
node_root -->|"initializes"| node_device_manager
node_device_manager -->|"provides NIC devices to"| node_net
node_device_manager -->|"provides storage devices to"| node_storage
node_storage -->|"surfaces filesystem nodes through"| node_vfs
node_mod_mgmt -->|"loads"| node_wasi
node_tasks -.->|"coordinates driver work"| node_device_manager

click node_make "https://github.com/theseus-os/theseus/blob/theseus_main/Makefile"
click node_nano_core "https://github.com/theseus-os/theseus/blob/theseus_main/kernel/nano_core/src/lib.rs"
click node_boot_info "https://github.com/theseus-os/theseus/blob/theseus_main/kernel/boot_info/src/lib.rs"
click node_root "https://github.com/theseus-os/theseus/blob/theseus_main/kernel/root/src/lib.rs"
click node_captain "https://github.com/theseus-os/theseus/blob/theseus_main/kernel/captain/src/lib.rs"
click node_mod_mgmt "https://github.com/theseus-os/theseus/blob/theseus_main/kernel/mod_mgmt/src/lib.rs"
click node_crate_metadata "https://github.com/theseus-os/theseus/blob/theseus_main/kernel/crate_metadata/src/lib.rs"
click node_crate_swap "https://github.com/theseus-os/theseus/blob/theseus_main/kernel/crate_swap/src/lib.rs"
click node_cpu "https://github.com/theseus-os/theseus/blob/theseus_main/kernel/cpu/src/lib.rs"
click node_interrupts "https://github.com/theseus-os/theseus/blob/theseus_main/kernel/interrupt_controller/src/lib.rs"
click node_context_switch "https://github.com/theseus-os/theseus/blob/theseus_main/kernel/context_switch_regular/src/lib.rs"
click node_tasks "https://github.com/theseus-os/theseus/blob/theseus_main/kernel/task/src/lib.rs"
click node_memory "https://github.com/theseus-os/theseus/blob/theseus_main/kernel/memory/src/lib.rs"
click node_frames "https://github.com/theseus-os/theseus/blob/theseus_main/kernel/frame_allocator/src/lib.rs"
click node_heap "https://github.com/theseus-os/theseus/blob/theseus_main/kernel/heap/src/lib.rs"
click node_device_manager "https://github.com/theseus-os/theseus/blob/theseus_main/kernel/device_manager/src/lib.rs"
click node_net "https://github.com/theseus-os/theseus/blob/theseus_main/kernel/net/src/lib.rs"
click node_storage "https://github.com/theseus-os/theseus/blob/theseus_main/kernel/storage_manager/src/lib.rs"
click node_vfs "https://github.com/theseus-os/theseus/blob/theseus_main/kernel/vfs_node/src/lib.rs"
click node_wasi "https://github.com/theseus-os/theseus/blob/theseus_main/kernel/wasi_interpreter/src/lib.rs"
click node_shell "https://github.com/theseus-os/theseus/blob/theseus_main/applications/shell/src/lib.rs"
click node_theseus_std "https://github.com/theseus-os/theseus/blob/theseus_main/ports/theseus_std/src/lib.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_make toneBlue
class node_nano_core,node_boot_info,node_root,node_captain toneAmber
class node_mod_mgmt,node_crate_metadata,node_crate_swap toneMint
class node_cpu,node_interrupts,node_context_switch,node_tasks,node_memory,node_frames,node_heap toneRose
class node_device_manager,node_net,node_storage,node_vfs,node_wasi toneIndigo
class node_shell,node_theseus_std toneTeal
```

## Components

### Build & targets

- [Make build orchestration](https://github.com/theseus-os/theseus/blob/theseus_main/Makefile): build · Builds bootable images and launches QEMU. · `Makefile`

### Boot & composition

- [Architecture nano-core](https://github.com/theseus-os/theseus/blob/theseus_main/kernel/nano_core/src/lib.rs): boot runtime · BIOS/UEFI entry, assembly startup, and early runtime. · `kernel/nano_core/src/lib.rs`
- [Boot metadata](https://github.com/theseus-os/theseus/blob/theseus_main/kernel/boot_info/src/lib.rs): boot contract · `kernel/boot_info/src/lib.rs`
- [Root initialization](https://github.com/theseus-os/theseus/blob/theseus_main/kernel/root/src/lib.rs): kernel init · `kernel/root/src/lib.rs`
- [Captain](https://github.com/theseus-os/theseus/blob/theseus_main/kernel/captain/src/lib.rs): system coordinator · `kernel/captain/src/lib.rs`

### Runtime evolution

- [Module management](https://github.com/theseus-os/theseus/blob/theseus_main/kernel/mod_mgmt/src/lib.rs): runtime loader · Discovers, loads, and manages independently compiled crates. · `kernel/mod_mgmt/src/lib.rs`
- [Crate metadata](https://github.com/theseus-os/theseus/blob/theseus_main/kernel/crate_metadata/src/lib.rs): module metadata · `kernel/crate_metadata/src/lib.rs`
- [Crate swapping](https://github.com/theseus-os/theseus/blob/theseus_main/kernel/crate_swap/src/lib.rs): live evolution · Replaces and serializes crate/module units for recovery and upgrades. · `kernel/crate_swap/src/lib.rs`

### CPU, tasks & memory

- [CPU abstraction](https://github.com/theseus-os/theseus/blob/theseus_main/kernel/cpu/src/lib.rs): architecture runtime · Separates x86_64 and AArch64 CPU and exception support. · `kernel/cpu/src/lib.rs`
- [Interrupt controller](https://github.com/theseus-os/theseus/blob/theseus_main/kernel/interrupt_controller/src/lib.rs): hardware interrupts · `kernel/interrupt_controller/src/lib.rs`
- [Context switching](https://github.com/theseus-os/theseus/blob/theseus_main/kernel/context_switch_regular/src/lib.rs): task switching · `kernel/context_switch_regular/src/lib.rs`
- [Tasks & scheduler](https://github.com/theseus-os/theseus/blob/theseus_main/kernel/task/src/lib.rs): concurrency runtime · Owns task lifecycle, preemption, deferred work, channels, and wait queues. · `kernel/task/src/lib.rs`
- [Paging abstractions](https://github.com/theseus-os/theseus/blob/theseus_main/kernel/memory/src/lib.rs): virtual memory · General mapping interface over architecture-specific paging. · `kernel/memory/src/lib.rs`
- [Frame allocator](https://github.com/theseus-os/theseus/blob/theseus_main/kernel/frame_allocator/src/lib.rs): physical memory · `kernel/frame_allocator/src/lib.rs`
- [Heap allocator](https://github.com/theseus-os/theseus/blob/theseus_main/kernel/heap/src/lib.rs): dynamic allocation · Provides heap and slab allocation above page/frame layers. · `kernel/heap/src/lib.rs`

### Devices & execution

- [Device manager](https://github.com/theseus-os/theseus/blob/theseus_main/kernel/device_manager/src/lib.rs): device discovery · Exposes ACPI/PCI-discovered platform devices. · `kernel/device_manager/src/lib.rs`
- [Network stack](https://github.com/theseus-os/theseus/blob/theseus_main/kernel/net/src/lib.rs): networking · Provides NIC, interface, and socket boundaries. · `kernel/net/src/lib.rs`
- [Storage manager](https://github.com/theseus-os/theseus/blob/theseus_main/kernel/storage_manager/src/lib.rs): storage services · `kernel/storage_manager/src/lib.rs`
- [VFS nodes](https://github.com/theseus-os/theseus/blob/theseus_main/kernel/vfs_node/src/lib.rs): filesystem interface · `kernel/vfs_node/src/lib.rs`
- [WASI interpreter](https://github.com/theseus-os/theseus/blob/theseus_main/kernel/wasi_interpreter/src/lib.rs): WebAssembly runtime · `kernel/wasi_interpreter/src/lib.rs`

### Applications & compatibility

- [Shell](https://github.com/theseus-os/theseus/blob/theseus_main/applications/shell/src/lib.rs): Theseus application · `applications/shell/src/lib.rs`
- [Theseus std port](https://github.com/theseus-os/theseus/blob/theseus_main/ports/theseus_std/src/lib.rs): compatibility library · `ports/theseus_std/src/lib.rs`

## Connections

- Make build orchestration → Architecture nano-core: builds image with
- Architecture nano-core → Boot metadata: normalizes boot data
- Boot metadata → Root initialization: initializes
- Root initialization → Captain: starts
- Captain → Module management: loads crates through
- Module management → Crate metadata: uses
- Module management → Crate swapping: enables
- CPU abstraction → Interrupt controller: implements platform support for
- Interrupt controller → Tasks & scheduler: delivers deferred work to
- Context switching → Tasks & scheduler: switches
- Tasks & scheduler → Paging abstractions: uses address spaces
- Paging abstractions → Frame allocator: maps physical frames from
- Heap allocator → Paging abstractions: allocates pages through
- Root initialization → CPU abstraction: initializes
- Root initialization → Paging abstractions: establishes
- Module management → Shell: loads
- Shell → Theseus std port: uses
- Root initialization → Device manager: initializes
- Device manager → Network stack: provides NIC devices to
- Device manager → Storage manager: provides storage devices to
- Storage manager → VFS nodes: surfaces filesystem nodes through
- Module management → WASI interpreter: loads
- Tasks & scheduler → Device manager: coordinates driver work
