# menndouyukkuri/explorer_ghost_cleaner architecture

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

- Interactive diagram: https://gitdiagram.com/menndouyukkuri/explorer_ghost_cleaner
- Repository: https://github.com/menndouyukkuri/explorer_ghost_cleaner

## Overview

##### Project Type and Purpose
- This is a standalone, full-client desktop (Windows) “tray” application written in Rust.
- Its sole responsibility is to monitor and clean up idle “ghost” explorer.exe processes.
- There is no remote server, database, or network layer—everything runs locally.

##### File Structure
Top-level files & directories:
- Cargo.toml / build.rs – Rust project metadata and build script.
- config/config.toml – Runtime configuration file (scan interval, thresholds).
- src/
– main.rs: application entrypoint; initializes components.
– lib.rs: core library exports.
– worker.rs: scheduling and orchestration of scan/cleanup tasks.
– system_ext.rs: high-level wrappers around OS process enumeration and metrics.
– format.rs: formatting utilities (e.g., logs, status messages).
– src/worker/os.rs: OS-specific implementations (Windows API calls for process stats and termination).
- docs/: documentation, including Japanese README.

##### README for Insights
- Single executable, zero dependencies beyond Windows.
- Configurable via config.toml (scan interval, CPU/disk thresholds).
- Monitors CPU & disk I/O metrics to decide idleness.

##### Main Components and Their Interactions
a. Configuration Loader
– Reads config/config.toml on startup.
– Passes parameters (interval_seconds, cpu_threshold, disk_threshold_bytes) to the scheduler.
b. Scheduler / Worker Orchestrator
– In worker.rs: kicks off periodic “scan” jobs per interval.
c. Process Scanner & Analyzer
– Uses system_ext.rs to enumerate all explorer.exe processes.
– For each, gathers CPU and disk I/O metrics via OS API in worker/os.rs.
d. Decision Engine
– Compares metrics against thresholds.
– Flags truly idle “ghost” processes.
e. Cleaner
– Invokes Windows API calls (TerminateProcess or equivalent) via worker/os.rs.
f. UI Layer
– Sends status updates (optional) or logs to the tray tooltip or log file.
g. Logging / Formatting
– format.rs for human‐readable messages; could be written to stdout, a file, or shown in the tray.

##### Architectural Patterns & Principles
- Layered Architecture:
– Presentation (UI)
– Application (Scheduler + Decision Engine)
– Domain services (Process scanning, metrics)
– Infrastructure (OS bindings)
- Separation of Concerns:
– UI code lives entirely in ui.rs.
– OS‐specific code isolated in worker/os.rs.
– Shared logic in lib.rs, worker.rs, system_ext.rs.
- Configuration-driven Behavior: simple config file drives runtime.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Configuration"
        ConfigLoader["Config Loader"]:::config
    end

    subgraph "Core Logic"
        Scheduler["Scheduler / Worker Orchestrator"]:::core
        ProcessScanner["Process Scanner & Analyzer"]:::core
        DecisionEngine["Decision Engine & Cleaner"]:::core
        Logging["Logging / Formatting Utilities"]:::core
    end

    subgraph "UI Layer"
        UI["UI Layer (Tray Icon & Menu)"]:::ui
        TrayIcon["Tray Icon Resource"]:::ui
    end

    subgraph "Infrastructure"
        OSAPI["OS API Bindings (metrics & termination)"]:::infra
    end

    Entrypoint["Application Entrypoint"]:::coreLib
    CoreLibrary["Core Library Exports"]:::coreLib

    Entrypoint -->|"initializes"| ConfigLoader
    Entrypoint -->|"initializes"| CoreLibrary
    Entrypoint -->|"initializes"| UI

    ConfigLoader -->|"interval, thresholds"| Scheduler

    Scheduler -->|"trigger scan"| ProcessScanner
    Scheduler -->|"log scheduling"| Logging

    ProcessScanner -->|"enumerate processes, metrics request"| OSAPI
    OSAPI -->|"process metrics"| ProcessScanner

    ProcessScanner -->|"process list"| DecisionEngine
    DecisionEngine -->|"terminate(process_id)"| OSAPI
    Scheduler -->|"scan results"| DecisionEngine

    DecisionEngine -->|"cleanup log"| Logging

    Scheduler -->|"status update"| UI
    DecisionEngine -->|"status update"| UI

    UI -->|"display status"| TrayIcon

    classDef config fill:#c8f7c5,stroke:#2e7d32,color:#000;
    classDef core fill:#bbdefb,stroke:#1565c0,color:#000;
    classDef ui fill:#e1bee7,stroke:#6a1b9a,color:#000;
    classDef infra fill:#eceff1,stroke:#455a64,color:#000;
    classDef coreLib fill:#fff9c4,stroke:#f9a825,color:#000;

    click ConfigLoader "https://github.com/menndouyukkuri/explorer_ghost_cleaner/blob/main/config/config.toml"
    click Scheduler "https://github.com/menndouyukkuri/explorer_ghost_cleaner/blob/main/src/worker.rs"
    click ProcessScanner "https://github.com/menndouyukkuri/explorer_ghost_cleaner/blob/main/src/system_ext.rs"
    click DecisionEngine "https://github.com/menndouyukkuri/explorer_ghost_cleaner/blob/main/src/worker.rs"
    click OSAPI "https://github.com/menndouyukkuri/explorer_ghost_cleaner/blob/main/src/worker/os.rs"
    click UI "https://github.com/menndouyukkuri/explorer_ghost_cleaner/blob/main/src/ui.rs"
    click TrayIcon "https://github.com/menndouyukkuri/explorer_ghost_cleaner/tree/main/icon/"
    click Logging "https://github.com/menndouyukkuri/explorer_ghost_cleaner/blob/main/src/format.rs"
    click Entrypoint "https://github.com/menndouyukkuri/explorer_ghost_cleaner/blob/main/src/main.rs"
    click CoreLibrary "https://github.com/menndouyukkuri/explorer_ghost_cleaner/blob/main/src/lib.rs"
```
