This document provides a deep dive into the internal mechanics of the AI-Driven Process Recommendation System.
The system follows a decoupled Client-Server architecture:
graph TD
subgraph "Frontend (Single File)"
UI[React Dashboard]
Charts[Real-time Charts]
Actions[Action Triggers]
end
subgraph "Backend (Flask)"
API[REST API]
Cache[Process Cache Thread]
RuleEngine[Rule Engine v1]
MLEngine[ML Engine v2]
ProcManager[psutil Manager]
end
subgraph "Storage"
Model[process_model.pkl]
Meta[model_metadata.json]
end
UI <--> API
API <--> Cache
Cache <--> ProcManager
API <--> RuleEngine
API <--> MLEngine
MLEngine <--> Model
MLEngine <--> Meta
The rule engine uses a prioritized list of heuristics to make recommendations:
- User Overrides: Checks for manual labels first.
- Protection: Targets "System" processes for
prioritize. - Thresholds:
- CPU > 70% | Memory > 30% →
terminate - CPU > 40% | Memory > 15% →
pause - CPU > 20% | Memory > 8% →
monitor - Default →
monitor
- CPU > 70% | Memory > 30% →
When enough data is collected, the system switches to a RandomForestClassifier.
- Features Extracted:
cpu_percent: Resource usage.memory_percent: RAM impact.category: Categorical integer (System=0, Browser=1, etc.).num_threads: Process complexity.user_label: Historical importance assigned by user.
- Workflow:
- Feature vectors are normalized.
- Model is trained on labeled snapshots.
predict_proba()is used to provide a confidence score.
To prevent slow system calls (like psutil.process_iter) from blocking the UI, the backend runs a dedicated refresh thread.
- Refreshes every 2 seconds.
- Uses a
threading.Lockto ensure atomic updates to the shared_cacheobject. - API requests always return the latest cached data instantly (~1ms response time).
When an action (Kill/Pause) is triggered on a PID:
- The system identifies all child processes recursively.
- Termination Logic: Kills children first (bottom-up), then the parent, to prevent orphaned processes.
- Resume Logic: Resumes the parent first, then children, to ensure the main thread is ready to receive data.
The dashboard uses a Modern Glassmorphism aesthetic:
- Style: Semi-transparent backgrounds (
rgba), backdrop filters (blur), and subtle borders. - Interactivity: Hover effects, smooth transitions, and "shimmer" loading skeletons.
- Responsiveness: Grid-based layout that adapts to various screen sizes.
- Performance: Single-file delivery using Babel Standalone for minimal setup overhead.
- CORS Enabled: Allows development from separate frontend servers.
- Error Boundaries: Handles
AccessDeniedorNoSuchProcesserrors gracefully (common when interacting with restricted system processes). - Persistence: Metadata is saved to disk so accuracy metrics survive server restarts.
Documentation Version: 1.1