# nuta/operating-system-in-1000-lines architecture

> Architecture diagram of the GitHub repository nuta/operating-system-in-1000-lines, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nuta/operating-system-in-1000-lines
- Repository: https://github.com/nuta/operating-system-in-1000-lines

## Overview

##### Core Components to Highlight

- Memory Allocator (kernel.c)
- Process Scheduler
- Page Table Manager
- Exception Handler
- System Call Interface
- VirtIO Block Driver
- File System Manager

- Shell Implementation (shell.c)
- User Programs (user.c)
- Common Libraries (common.c)

##### Interaction Flows

- System call flow from user space to kernel
- Memory management operations
- Process creation and scheduling
- File system operations
- Device I/O operations

##### Specific Implementation Details

- Linker scripts (kernel.ld, user.ld)
- Boot sequence
- Kernel panic handler
- Virtual memory layout
- File system structure

##### Additional Elements

A section showing:
- Disk management (disk directory)
- File system structure
- Memory layout
- Process state transitions

##### The basic but complete nature of the OS features

- Use a hierarchical layout to show the layers of abstraction
- Notes about key educational concepts where relevant
- Both static structure and dynamic interactions
- Minimal implementation aspect while showing all essential OS components

## Diagram (Mermaid)

```mermaid
graph TB
    %% Define styles
    classDef hardware fill:#FFE5CC,stroke:#FF9933
    classDef kernel fill:#CCE5FF,stroke:#3399FF
    classDef userspace fill:#D6F5D6,stroke:#4CAF50
    classDef documentation fill:#F5F5F5,stroke:#999999
    classDef critical fill:#FFCCCC,stroke:#FF6666

    %% Hardware Layer
    subgraph Hardware
        RISCV["RISC-V Architecture"]:::hardware
        VIRTIO["VirtIO Block Device"]:::hardware
    end

    %% Kernel Layer
    subgraph Kernel
        KCORE["Kernel Core"]:::kernel
        BOOT["Boot Sequence"]:::kernel
        MEMMAN["Memory Management"]:::kernel
        PROCMAN["Process Management"]:::kernel
        PGMAN["Page Table Manager"]:::kernel
        SYSCALL["System Call Interface"]:::kernel
        VIRTDRV["VirtIO Driver"]:::kernel
        FSMAN["File System Manager"]:::kernel
        PANIC["Kernel Panic Handler"]:::critical
    end

    %% User Space Layer
    subgraph UserSpace
        SHELL["Shell"]:::userspace
        USERPROG["User Programs"]:::userspace
        LIBC["Standard C Library"]:::userspace
    end

    %% Documentation Layer
    subgraph Documentation
        BOOTDOC["Boot Documentation"]:::documentation
        MEMDOC["Memory Documentation"]:::documentation
        PROCDOC["Process Documentation"]:::documentation
        PAGEDOC["Page Table Documentation"]:::documentation
        SYSDOC["System Calls Documentation"]:::documentation
        VIRTDOC["VirtIO Documentation"]:::documentation
        FSDOC["File System Documentation"]:::documentation
    end

    %% Relationships
    RISCV --> BOOT
    VIRTIO --> VIRTDRV
    BOOT --> KCORE
    KCORE --> MEMMAN
    KCORE --> PROCMAN
    KCORE --> PGMAN
    KCORE --> SYSCALL
    KCORE --> FSMAN
    VIRTDRV --> FSMAN
    SYSCALL --> USERPROG
    LIBC --> USERPROG
    USERPROG --> SHELL
    FSMAN --> SHELL

    %% Click events
    click KCORE "https://github.com/nuta/operating-system-in-1000-lines/blob/main/kernel.c"
    click USERPROG "https://github.com/nuta/operating-system-in-1000-lines/blob/main/user.c"
    click SHELL "https://github.com/nuta/operating-system-in-1000-lines/blob/main/shell.c"
    click LIBC "https://github.com/nuta/operating-system-in-1000-lines/blob/main/common.c"
    click FSMAN "https://github.com/nuta/operating-system-in-1000-lines/tree/main/disk/"
    click BOOTDOC "https://github.com/nuta/operating-system-in-1000-lines/blob/main/website/en/04-boot.md"
    click MEMDOC "https://github.com/nuta/operating-system-in-1000-lines/blob/main/website/en/09-memory-allocation.md"
    click PROCDOC "https://github.com/nuta/operating-system-in-1000-lines/blob/main/website/en/10-process.md"
    click PAGEDOC "https://github.com/nuta/operating-system-in-1000-lines/blob/main/website/en/11-page-table.md"
    click SYSDOC "https://github.com/nuta/operating-system-in-1000-lines/blob/main/website/en/14-system-call.md"
    click VIRTDOC "https://github.com/nuta/operating-system-in-1000-lines/blob/main/website/en/15-virtio-blk.md"
    click FSDOC "https://github.com/nuta/operating-system-in-1000-lines/blob/main/website/en/16-file-system.md"

    %% Legend
    subgraph Legend
        H["Hardware Component"]:::hardware
        K["Kernel Component"]:::kernel
        U["User Space Component"]:::userspace
        D["Documentation"]:::documentation
        C["Critical Path"]:::critical
    end
```
