# mildlybrutal/cpu-scheduling architecture

> Architecture diagram of the GitHub repository mildlybrutal/cpu-scheduling, 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/mildlybrutal/cpu-scheduling
- Repository: https://github.com/mildlybrutal/cpu-scheduling

## Overview

##### Main Components
- Frontend (Presentation Layer):
- Next.js App Router: Represents the primary structure of the pages contained in the src/app directory (e.g., home page, simulator page, docs pages).
- Documentation Pages: Under src/app/docs, these pages present educational content and details for each algorithm.
- Shared UI Components: Located in src/components (e.g., GanttChart, ProcessForm, SimulationControls, and common UI elements contained in src/components/ui).
- State Management:
- SchedulingContext: Found in src/context, this provides a global context for managing simulation state and data.
- Business Logic and Simulation Engine:
- Scheduler Library: In src/lib/schedulers, separate files for fcfs.ts, sjf.ts, roundRobin.ts, and priority.ts implement the respective simulation algorithms.
- Scheduling Controller: src/lib/schedulingController.ts acts as a coordinator that likely integrates the simulation algorithms with the application’s state.
- Utility Functions: In src/lib/utils and metrics (src/lib/utils/metrics.ts) for calculations, data processing, and performance metric computation.
- Configuration and Styling:
- Next.js and Tailwind configurations: next.config.ts, tailwind.config.ts, and global styles (src/app/globals.css).

##### Relationships and Interactions
- The UI Layer sends user input (process details and simulation controls) from components (ProcessForm and SimulationControls) to the SchedulingContext.
- SchedulingContext acts as the mediator that passes simulation data to the scheduling controller and the corresponding scheduler algorithm (from src/lib/schedulers) based on user selection.
- Scheduler algorithms process simulation data and return performance metrics which are then passed back through the context to update UI components (GanttChart and MetricsDisplay).
- Documentation pages (under src/app/docs) provide interactive explanations of each algorithm, likely integrating similar UI components or specialized content.
- Utility functions support both the simulation computational logic (e.g., calculating statistics) and UI data formatting.

##### Architectural Patterns and Technologies
- The application follows a component-based architecture using Next.js (with the new App Router paradigm) and React 18+ for interactive UI and concurrent rendering.
- TypeScript is used throughout for type safety.
- The separation of concerns is clear: presentation (in src/app & src/components), state management (src/context), business logic (src/lib), and styling (Tailwind CSS).
- Patterns such as MVC-like separation or service/module-based separation can be observed here: UI components trigger interactions, the context handles state, and lib modules perform core business logic.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend / UI Layer
    subgraph "Frontend (UI Layer)"
        A["Next.js App Router"]:::frontend
        B["Documentation Pages"]:::frontend
        C["Shared UI Components"]:::frontend
    end

    %% State Management Layer
    subgraph "State Management"
        D["SchedulingContext"]:::state
    end

    %% Business Logic / Simulation Engine
    subgraph "Business Logic"
        E["Scheduling Controller"]:::business
        subgraph "Scheduler Algorithms"
            F["FCFS"]:::business
            G["SJF"]:::business
            H["Round Robin"]:::business
            I["Priority Scheduling"]:::business
        end
        J["Utilities"]:::business
        K["Metrics Calculations"]:::business
    end

    %% Configuration & Styling
    subgraph "Configuration and Styling"
        L["Next.js Config"]:::config
        M["Tailwind Config"]:::config
        N["Global Styles"]:::config
    end

    %% Connections
    A -->|"routes to"| C
    B -->|"renders"| C
    C -->|"user input"| D
    D -->|"triggers simulation"| E
    E -->|"executes"| F
    E -->|"executes"| G
    E -->|"executes"| H
    E -->|"executes"| I
    E -->|"calls"| J
    E -->|"calls"| K
    E -->|"updates"| C

    %% Click Events
    click A "https://github.com/mildlybrutal/cpu-scheduling/tree/main/src/app"
    click B "https://github.com/mildlybrutal/cpu-scheduling/tree/main/src/app/docs"
    click C "https://github.com/mildlybrutal/cpu-scheduling/tree/main/src/components"
    click D "https://github.com/mildlybrutal/cpu-scheduling/blob/main/src/context/SchedulingContext.tsx"
    click F "https://github.com/mildlybrutal/cpu-scheduling/blob/main/src/lib/schedulers/fcfs.ts"
    click G "https://github.com/mildlybrutal/cpu-scheduling/blob/main/src/lib/schedulers/sjf.ts"
    click H "https://github.com/mildlybrutal/cpu-scheduling/blob/main/src/lib/schedulers/roundRobin.ts"
    click I "https://github.com/mildlybrutal/cpu-scheduling/blob/main/src/lib/schedulers/priority.ts"
    click E "https://github.com/mildlybrutal/cpu-scheduling/blob/main/src/lib/schedulingController.ts"
    click J "https://github.com/mildlybrutal/cpu-scheduling/blob/main/src/lib/utils.ts"
    click K "https://github.com/mildlybrutal/cpu-scheduling/blob/main/src/lib/utils/metrics.ts"
    click L "https://github.com/mildlybrutal/cpu-scheduling/blob/main/next.config.ts"
    click M "https://github.com/mildlybrutal/cpu-scheduling/blob/main/tailwind.config.ts"
    click N "https://github.com/mildlybrutal/cpu-scheduling/blob/main/src/app/globals.css"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef state fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef business fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef config fill:#f8d7da,stroke:#721c24,stroke-width:2px;
```
