|
| 1 | +# Architecture |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +System Health Tool is a Tauri 2 desktop app: a Rust backend handles all system-level operations, and a React frontend provides the UI. They communicate via Tauri's `invoke()` IPC mechanism. |
| 6 | + |
| 7 | +``` |
| 8 | +┌─────────────────────────────────────────────────┐ |
| 9 | +│ Tauri Window │ |
| 10 | +│ ┌───────────────────────────────────────────┐ │ |
| 11 | +│ │ React Frontend │ │ |
| 12 | +│ │ ┌─────────┐ ┌──────────┐ ┌───────────┐ │ │ |
| 13 | +│ │ │Dashboard│ │DiskClean │ │MemoryPanel│ │ │ |
| 14 | +│ │ └────┬────┘ └────┬─────┘ └─────┬─────┘ │ │ |
| 15 | +│ │ │ │ │ │ │ |
| 16 | +│ │ ┌────┴───────────┴─────────────┴──────┐ │ │ |
| 17 | +│ │ │ api.ts (invoke wrappers) │ │ │ |
| 18 | +│ │ └────────────────┬────────────────────┘ │ │ |
| 19 | +│ └───────────────────┼───────────────────────┘ │ |
| 20 | +│ │ IPC (JSON serialization) │ |
| 21 | +│ ┌───────────────────┼───────────────────────┐ │ |
| 22 | +│ │ Rust Backend (Tauri) │ │ |
| 23 | +│ │ ┌────────┐ ┌────────┐ ┌──────────────┐ │ │ |
| 24 | +│ │ │disk.rs │ │memory │ │startup.rs │ │ │ |
| 25 | +│ │ │ │ │ .rs │ │ │ │ │ |
| 26 | +│ │ └────────┘ └────────┘ └──────────────┘ │ │ |
| 27 | +│ │ ┌──────────┐ ┌─────────────────────┐ │ │ |
| 28 | +│ │ │cleanup.rs│ │recommendations.rs │ │ │ |
| 29 | +│ │ └──────────┘ └─────────────────────┘ │ │ |
| 30 | +│ └───────────────────────────────────────────┘ │ |
| 31 | +└─────────────────────────────────────────────────┘ |
| 32 | + │ │ │ |
| 33 | + Win32 API PowerShell Registry |
| 34 | + (disk space, (VM info, (startup |
| 35 | + processes) services) items) |
| 36 | +``` |
| 37 | + |
| 38 | +## Backend Commands |
| 39 | + |
| 40 | +Each Rust module exposes `#[tauri::command]` functions that the frontend calls via `invoke()`. |
| 41 | + |
| 42 | +### disk.rs |
| 43 | + |
| 44 | +| Command | Returns | Description | |
| 45 | +|---|---|---| |
| 46 | +| `scan_disk()` | `DiskScanResult` | Scans all known cleanable locations, returns items with sizes and risk levels | |
| 47 | +| `get_drive_info()` | `Vec<DriveInfo>` | Enumerates all drives (A-Z) and returns total/free/used bytes via Win32 `GetDiskFreeSpaceExA` | |
| 48 | + |
| 49 | +**Scan locations:** User temp, Windows temp, Recycle Bin, Chrome/Edge/Firefox cache, crash dumps, Windows Update downloads, thumbnail cache, npm/pip/cargo/nuget/go caches, log files. |
| 50 | + |
| 51 | +Each item gets a risk classification: |
| 52 | +- `safe` — Always fine to delete (temp files, browser cache, crash dumps) |
| 53 | +- `moderate` — Will be re-downloaded when needed (dev caches, WU downloads) |
| 54 | +- `advanced` — Requires user judgment |
| 55 | + |
| 56 | +### memory.rs |
| 57 | + |
| 58 | +| Command | Returns | Description | |
| 59 | +|---|---|---| |
| 60 | +| `get_memory_info()` | `MemoryInfo` | Total/used/free RAM via `sysinfo` crate | |
| 61 | +| `get_processes()` | `Vec<ProcessInfo>` | Top 50 processes by RAM, with category labels and zombie detection | |
| 62 | +| `kill_process(pid)` | `Result<String>` | Terminates a process by PID | |
| 63 | +| `get_vm_info()` | `Vec<VmInfo>` | Detects Hyper-V VMs (via PowerShell `Get-VM`) and WSL distros (via `wsl --list`) | |
| 64 | + |
| 65 | +**Zombie detection:** A process is flagged as a potential zombie if it uses >25% CPU but less than 10 MB RAM (indicating a busy-loop with no real work). |
| 66 | + |
| 67 | +**Process categories:** Browser, Developer, Communication, Gaming, System, Other — determined by name matching. |
| 68 | + |
| 69 | +### startup.rs |
| 70 | + |
| 71 | +| Command | Returns | Description | |
| 72 | +|---|---|---| |
| 73 | +| `get_startup_items()` | `Vec<StartupItem>` | Reads from `HKCU\...\Run`, `HKLM\...\Run`, and the user's Startup folder | |
| 74 | +| `toggle_startup_item(id, enable)` | `Result<String>` | Enables/disables via `StartupApproved\Run` registry key or moving shortcut files | |
| 75 | + |
| 76 | +**Impact estimation:** Based on known high-impact apps (Steam, Docker, OneDrive = High), medium-impact (Discord, NVIDIA, Corsair = Medium), everything else = Low. |
| 77 | + |
| 78 | +**Recommended to disable:** Matches against a curated list of apps that are safe to not auto-start (Discord, Slack, Steam, Docker, Ollama, Figma, etc.). |
| 79 | + |
| 80 | +### cleanup.rs |
| 81 | + |
| 82 | +| Command | Returns | Description | |
| 83 | +|---|---|---| |
| 84 | +| `clean_items(item_ids, item_paths)` | `CleanupSummary` | Deletes selected items, returns per-item success/failure and total bytes freed | |
| 85 | + |
| 86 | +Special handling: |
| 87 | +- **Recycle Bin** — Uses PowerShell `Clear-RecycleBin` |
| 88 | +- **Windows Update** — Stops `wuauserv` service before deleting, restarts after |
| 89 | +- **Memory dump** — Single file deletion |
| 90 | +- **Everything else** — Recursive directory content deletion, skipping locked files |
| 91 | + |
| 92 | +### recommendations.rs |
| 93 | + |
| 94 | +| Command | Returns | Description | |
| 95 | +|---|---|---| |
| 96 | +| `get_recommendations()` | `Vec<Recommendation>` | Analyzes current state and generates prioritized tips | |
| 97 | + |
| 98 | +**Checks performed:** |
| 99 | +1. RAM usage > 85% → "Memory usage is very high" |
| 100 | +2. Any drive < 10% free → "Drive X is almost full" |
| 101 | +3. > 2 disableable startup items → "N programs launch at startup" |
| 102 | +4. Hyper-V VM memory > 3x startup and > 4 GB → "VM is using too much memory" |
| 103 | +5. > 1 GB cleanable junk → "Junk files detected" |
| 104 | +
|
| 105 | +## Frontend Components |
| 106 | + |
| 107 | +### Dashboard.tsx |
| 108 | +Entry point. Loads drives, memory, and scan data in parallel. Shows health score (0-100) computed from RAM usage, disk free space, and junk file accumulation. Quick Clean button triggers safe-only cleanup. |
| 109 | + |
| 110 | +### DiskCleanup.tsx |
| 111 | +Three-phase workflow: Scan → Review → Clean → Done. Items grouped by category (System, Browsers, Developer) with risk-colored badges. Checkboxes default to safe items selected. |
| 112 | + |
| 113 | +### MemoryPanel.tsx |
| 114 | +RAM bar with color thresholds (green < 60%, yellow < 90%, red > 90%). Horizontal bar chart of memory by category. Process table with kill buttons (disabled for System category). VM detection section. |
| 115 | + |
| 116 | +### StartupManager.tsx |
| 117 | +Toggle switches styled as iOS-like sliders. Warning banner when multiple items are recommended to disable. Impact badges (High/Medium/Low) with color coding. |
| 118 | + |
| 119 | +### Recommendations.tsx |
| 120 | +Cards with severity-based styling (red border = high, yellow = medium, blue = low). Each card has a navigation button that jumps to the relevant tab. |
| 121 | + |
| 122 | +## Data Flow |
| 123 | + |
| 124 | +1. User opens app → Dashboard loads `getDriveInfo()`, `getMemoryInfo()`, `scanDisk()` in parallel |
| 125 | +2. Health score computed client-side from the combined data |
| 126 | +3. Quick Clean → filters scan results to `risk === "safe"` → calls `cleanItems()` → refreshes Dashboard |
| 127 | +4. Disk Cleanup tab → auto-scans on mount → user checks/unchecks items → Clean button → `cleanItems()` → shows results |
| 128 | +5. Memory tab → `getProcesses()` with 500ms delay between two `refresh_processes()` calls for accurate CPU measurement |
| 129 | +6. Startup tab → `getStartupItems()` → toggle calls `toggleStartupItem()` → optimistic UI update |
| 130 | +7. Recommendations → `getRecommendations()` which internally calls `scanDisk()`, `getStartupItems()`, checks VMs and drives |
0 commit comments