# nangsontay/osassignment-hk242 architecture

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

- Interactive diagram: https://gitdiagram.com/nangsontay/osassignment-hk242
- Repository: https://github.com/nangsontay/osassignment-hk242

## Overview

##### Main Components
- Kernel Core: The heart of the OS (src/os.c) that integrates the various services.
- Memory Management: This includes modules for memory allocation and paging (see include/mem.h, include/mm.h, src/mm.c, src/mm-vm.c, and src/mm-memphy.c). These files implement both low-level memory management and virtual memory/paging mechanisms.
- Scheduler: Files under include/sched.h and src/sched.c indicate that process or thread scheduling has been implemented.
- System Call Interface: Modules related to system calls (include/syscall.h, src/syscall.c, and syscall tables/scripts like src/syscall.tbl and src/syscalltbl.sh) handle interactions between user processes and the kernel.
- CPU Component: CPU simulation/manipulation is present in include/cpu.h and src/cpu.c to mimic CPU operations essential to an OS.
- Loader & Other Utilities: The loader (include/loader.h and src/loader.c) prepares the execution environment, while additional utilities such as queue handling (include/queue.h, src/queue.c) and a timer (include/timer.h, src/timer.c) handle auxiliary tasks within the OS kernel.
- Input/Output Test Cases: The various files within the input and output directories represent different test cases or simulation configurations (for example, mlq, paging, syscall tests, and various process and scheduler tests).

##### Relationships and Data Flows
- Memory management interacts with both the paging logic and process scheduling to manage per-process memory.
- The Scheduler coordinates with the CPU module to schedule tasks and may use queues to manage ready and blocked processes.
- The Loader initializes processes by interacting with memory management and CPU configuration.
- The Timer component often serves to trigger context switches in the scheduler and should be linked accordingly.

##### Architectural Patterns and Design Principles
- Modular Design: Each major OS component (memory, scheduler, CPU, system calls) is separated into its own source and header files, illustrating a modular approach.
- Clear Separation of Concerns: Notice how input configurations and expected outputs are separate from the OS logic, reinforcing clean boundaries between the operating system's simulation and its test harness.
- Simulation/Mapping of Real Hardware: Components such as CPU, Memory Management, and Paging are implemented to simulate hardware behavior, a common pattern in educational OS projects.

##### Elements
- Clear Labels: Name each component explicitly (e.g., “Kernel Core”, “Memory Management”, “Scheduler”, “System Call Interface”, “CPU Simulation”, “Loader”, “Timer Service”).
- Interdependency Lines: Clearly mark dependencies such as the scheduler’s interaction with both the CPU and queues, and how system calls interact with various subsystems (memory, scheduling, etc.).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "External Layer"
        IOT("Input/Output Test Cases"):::external
    end
    subgraph "OS Kernel Components"
        SC("System Call Interface"):::kernel
        KC("Kernel Core"):::kernel
        MM("Memory Management"):::kernel
        SCH("Scheduler"):::kernel
        LD("Loader"):::kernel
        QU("Queue Utility"):::kernel
    end
    subgraph "Hardware Simulation"
        CPU("CPU Simulation"):::hardware
        TM("Timer Service"):::hardware
    end

    IOT -->|"invoke"| SC
    SC -->|"forwards"| KC
    KC -->|"manages"| MM
    KC -->|"manages"| SCH
    KC -->|"manages"| LD
    KC -->|"controls"| CPU
    MM -->|"allocates"| LD
    LD -->|"initializes"| CPU
    SCH -->|"schedules"| CPU
    TM -->|"triggers"| SCH
    SCH -->|"uses"| QU

    classDef external fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef kernel fill:#87CEEB,stroke:#333,stroke-width:2px;
    classDef hardware fill:#90EE90,stroke:#333,stroke-width:2px;

    click KC "https://github.com/nangsontay/osassignment-hk242/blob/master/src/os.c"
    click MM "https://github.com/nangsontay/osassignment-hk242/blob/master/include/mem.h"
    click MM "https://github.com/nangsontay/osassignment-hk242/blob/master/include/mm.h"
    click MM "https://github.com/nangsontay/osassignment-hk242/blob/master/src/mm.c"
    click MM "https://github.com/nangsontay/osassignment-hk242/blob/master/src/mm-vm.c"
    click MM "https://github.com/nangsontay/osassignment-hk242/blob/master/src/mm-memphy.c"
    click MM "https://github.com/nangsontay/osassignment-hk242/blob/master/src/mem.c"
    click SCH "https://github.com/nangsontay/osassignment-hk242/blob/master/include/sched.h"
    click SCH "https://github.com/nangsontay/osassignment-hk242/blob/master/src/sched.c"
    click SC "https://github.com/nangsontay/osassignment-hk242/blob/master/include/syscall.h"
    click SC "https://github.com/nangsontay/osassignment-hk242/blob/master/src/syscall.c"
    click SC "https://github.com/nangsontay/osassignment-hk242/blob/master/src/syscall.tbl"
    click SC "https://github.com/nangsontay/osassignment-hk242/blob/master/src/syscalltbl.sh"
    click CPU "https://github.com/nangsontay/osassignment-hk242/blob/master/include/cpu.h"
    click CPU "https://github.com/nangsontay/osassignment-hk242/blob/master/src/cpu.c"
    click LD "https://github.com/nangsontay/osassignment-hk242/blob/master/include/loader.h"
    click LD "https://github.com/nangsontay/osassignment-hk242/blob/master/src/loader.c"
    click TM "https://github.com/nangsontay/osassignment-hk242/blob/master/include/timer.h"
    click TM "https://github.com/nangsontay/osassignment-hk242/blob/master/src/timer.c"
    click QU "https://github.com/nangsontay/osassignment-hk242/blob/master/include/queue.h"
    click QU "https://github.com/nangsontay/osassignment-hk242/blob/master/src/queue.c"
    click IOT "https://github.com/nangsontay/osassignment-hk242/tree/master/input"
    click IOT "https://github.com/nangsontay/osassignment-hk242/tree/master/output"
```
