How netxspider/real-time-multi-threaded-application-simulator works
1. What this repo is
- A browser-only React simulator for operating-system thread scheduling, plus a separate thread-synchronization simulator.
- There is no backend, no database, and no Web Workers; the whole app runs in the client and advances by ticks.
2. Top-level application shape
- src/main.jsx boots the app into the Vite-generated index.html.
- src/App.jsx appears to assemble the main dashboard layout, which the README describes as a three-column simulator UI with controls on the left, visualizations in the center, and metrics on the right.
- src/pages/SyncSimulatorPage.jsx is the page-level entry for the synchronization simulator flow.
3. Core architectural boundary: state vs. engine
- The central boundary is between UI components and the simulation engine.
- UI writes user configuration into Zustand stores; the engine consumes that state and produces the next simulation tick and derived metrics.
- This keeps the simulation deterministic and easy to replay or inspect.
4. Simulation state stores
- src/store/simulationStore.js is the main state container for scheduling: thread definitions, current tick, running/ready queues, logs, speed, algorithm choice, and results.
- src/store/syncStore.js holds state for the synchronization simulator.
- src/store/navStore.js likely manages navigation between simulator sections/pages.
5. Scheduling engine
- src/engine/scheduler.js contains the pure scheduling logic for FCFS, SJF, Round Robin, SRTF, and Priority.
- src/engine/gameLoop.js drives the main scheduler forward on a timer, likely using setInterval with a speed multiplier.
- src/engine/threadModel.js computes the user-thread to kernel-thread mapping used by the thread-model visualization.
- src/engine/syncGameLoop.js is the parallel tick loop for the synchronization simulator.
6. Main data flow
- User edits configuration in the control panel.
- The store updates thread inputs and algorithm settings.
- The game loop calls into the scheduler each tick.
- The scheduler updates thread states, queue order, CPU assignment, and metrics.
- Those updates propagate to charts, tables, logs, and the results modal.
7. Scheduling dashboard UI
- src/components/controls/ControlPanel.jsx is the main entry for algorithm selection, speed control, and thread configuration.
- ThreadConfigModal.jsx handles per-thread arrival, burst, and priority editing.
- src/components/scheduling/GanttChart.jsx renders the timeline of CPU occupancy.
- ReadyQueuePanel.jsx shows the live running thread, ready queue, and arriving threads.
8. Visual explanation layer
- src/components/visualization/ThreadMapper.jsx is the thread-model diagram, showing user threads mapped to kernel threads and then to the CPU.
- StateLegend.jsx explains state colors and is part of the simulator’s visual language.
- These are presentation components fed by simulation state, not independent logic.
9. Metrics and observability
- src/components/metrics/RightSidebar.jsx is the dashboard wrapper for live metrics.
- CpuUtilChart.jsx and ThreadStateChart.jsx visualize runtime trends with Recharts.
- ThreadTable.jsx presents per-thread live status.
- LogConsole.jsx and ToastNotification.jsx provide event feedback and simulator messages.
- ResultsModal.jsx is the post-run summary with per-thread and aggregate scheduling metrics.
10. Synchronization simulator subsystem
- The src/components/sync/ folder indicates a separate educational module for synchronization concepts.
- SyncLeftPanel.jsx, SyncCenterPanel.jsx, and SyncRightPanel.jsx suggest a three-panel layout similar to the main scheduler UI.
- This subsystem is isolated from the scheduling simulator by its own store and loop, which helps keep the two simulations conceptually separate.
11. Styling and rendering approach
- The project uses Tailwind CSS v4 plus local CSS files like src/index.css and src/App.css for the overall dark-dashboard look and animations.
- The key visuals, especially the thread mapper and Gantt chart, are SVG-based rather than relying on a diagramming library.
- Recharts is used only for chart components where standard chart primitives are sufficient.
12. Tooling and runtime
- Vite is the build/dev runtime, which makes this a modern SPA rather than a server-rendered app.
- ESLint is present for code quality, and package-lock.json shows npm-managed dependencies.
- External libraries that materially affect architecture are React 19, Zustand, Recharts, and Lucide React.
Main entry points: simulationStore.js Sim store · App.jsx Dashboard · RightSidebar.jsx Metrics sidebar · SyncLeftPanel.jsx Sync panels
Components 26
App shell
Vite/React entry and global layout
- Main entry · Bootstraps the SPA into the Vite index page
src/main.jsx - Dashboard · Assembles the main simulator layout and routes UI regions
src/App.jsx - Styles · Global CSS and dashboard theming
src/App.css
Scheduling simulator
Main OS thread scheduling simulation
- Scheduler · Pure tick-level scheduling logic for FCFS, SJF, RR, SRTF, and Priority
src/engine/scheduler.js - Game loop · Advances the scheduling simulation over time
src/engine/gameLoop.js - Thread model · Computes user-thread to kernel-thread mapping for visualization
src/engine/threadModel.js - Controls · Algorithm selection, speed control, and thread configuration entry point
src/components/controls/ControlPanel.jsx - Thread editor · Edits per-thread arrival, burst, and priority values
src/components/controls/ThreadConfigModal.jsx - Gantt chart · Renders CPU occupancy over time
src/components/scheduling/GanttChart.jsx - Queue panel · Shows running thread, ready queue, and arrivals
src/components/scheduling/ReadyQueuePanel.jsx - Thread mapper · Shows user threads mapped to kernel threads and CPU
src/components/visualization/ThreadMapper.jsx - State legend · Explains simulator state colors and symbols
src/components/visualization/StateLegend.jsx - Metrics sidebar · Wraps the live metrics and observability views
src/components/metrics/RightSidebar.jsx - CPU chart · Visualizes CPU utilization trends
src/components/metrics/CpuUtilChart.jsx - State chart · Visualizes thread state trends over time
src/components/metrics/ThreadStateChart.jsx - Thread table · Shows per-thread live status and metrics
src/components/metrics/ThreadTable.jsx - Log console · Displays simulator events and messages
src/components/metrics/LogConsole.jsx - Results modal · Summarizes per-thread and aggregate scheduling results
src/components/metrics/ResultsModal.jsx
Sync simulator
Thread synchronization simulation
- Sync loop · Advances the synchronization simulator over time
src/engine/syncGameLoop.js - Sync page · Page-level entry for the synchronization simulator
src/pages/SyncSimulatorPage.jsx - Sync panels · Layout for the synchronization simulator controls, center view, and output
src/components/sync/SyncLeftPanel.jsx - Sync center · Central synchronization simulator view
src/components/sync/SyncCenterPanel.jsx - Sync right · Right-side synchronization outputs and metrics
src/components/sync/SyncRightPanel.jsx
Shared state
Cross-cutting client state and navigation
- Sim store · Holds scheduling simulation state, queues, speed, logs, and results
src/store/simulationStore.js - Sync store · Holds state for the synchronization simulator
src/store/syncStore.js - Nav store · Tracks navigation between simulator sections and pages
src/store/navStore.js
Connections 31
- Main entry → Dashboard: boots · Entry point mounts the root React application
- Dashboard → Controls: layout · Places simulator controls in the left column
- Dashboard → Gantt chart: layout · Places the timeline visualization in the center column
- Dashboard → Metrics sidebar: layout · Places live metrics in the right column
- Dashboard → Sync page: navigates · Can route to the separate synchronization simulator page
- Controls → Sim store: writes · Updates algorithm, speed, and thread inputs
- Thread editor → Sim store: edits · Commits per-thread configuration into the simulation store
- Sim store → Game loop: drives · Provides state and settings to the main tick loop
- Game loop → Scheduler: ticks · Invokes scheduling logic each simulation step
- Scheduler → Sim store: updates · Writes thread state, queue order, CPU assignment, and metrics
- Scheduler → Results modal: summarizes · Produces final results for the run summary
- Sim store → Gantt chart: feeds · Supplies timeline data for rendering
- Sim store → Queue panel: feeds · Supplies live queue and running-thread state
- Sim store → Thread mapper: feeds · Supplies thread-model data for the mapping diagram
- Thread model → Thread mapper: renders · Generates mapping relationships for the visualization
- Sim store → State legend: feeds · Provides state palette and labels to the legend
- Sim store → Metrics sidebar: feeds · Supplies live data to the metrics sidebar
- Metrics sidebar → CPU chart: contains · Hosts CPU utilization chart
- Metrics sidebar → State chart: contains · Hosts thread-state trend chart
- Metrics sidebar → Thread table: contains · Hosts per-thread status table
- Metrics sidebar → Log console: contains · Hosts event log console
- Sim store → Results modal: feeds · Provides aggregate and per-thread results
- Nav store → Dashboard: controls · Supports page and section navigation
- Sync page → Sync panels: assembles · Builds the synchronization simulator layout
- Sync page → Sync store: uses · Reads and writes sync simulation state
- Sync store → Sync loop: drives · Provides state and settings to the sync tick loop
- Sync loop → Sync store: updates · Advances sync state over time
- Sync panels → Sync center: contains · Central panel for sync visualization
- Sync panels → Sync right: contains · Right panel for sync output and metrics
- Styles → Dashboard: styles · Provides the global dashboard look and feel
- Styles → Sync panels: styles · Provides styling for the synchronization layout