# abdenasser/neohtop architecture

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

- Interactive diagram: https://gitdiagram.com/abdenasser/neohtop
- Repository: https://github.com/abdenasser/neohtop

## Overview

##### Major Components
- Frontend (UI):
- Built using SvelteKit with TypeScript and organized under the "src" directory.
- Contains UI elements/components (in “src/lib/components” such as AppInfo, Toolbar, Stats panels, modals, etc.) to render process data, system statistics, search/filter functionality, and theming.
- Backend (System Monitoring and Process Management):
- Implemented in Rust and managed via Tauri.
- Resides in the "src-tauri" directory – includes modules for commands (commands.rs), monitoring system and process details (monitoring folder with process_monitor.rs, system_monitor.rs, etc.), and UI bridge (in the ui folder for window management).
- Application Shell & Integration:
- Tauri config (tauri.conf.json and Cargo configs) coordinates communication between the frontend and backend.
- The integration leverages Tauri’s API to allow the SvelteKit frontend to call backend commands (using IPC mechanisms offered by Tauri).

##### Relationships and Data Flow
- The frontend, built in Svelte, interacts with the backend via Tauri’s command invocation system. This is the primary communication channel.
- User actions (e.g., performing a process search, refreshing stats, or executing process kill commands) trigger events in the Svelte components, which then call the underlying Rust commands.
- The Rust backend is responsible for querying system metrics (CPU, memory usage, process list) and managing process state. Once data is processed, it is sent back to the frontend for rendering.
- Showing arrowed two-way communications, where the frontend requests data to be fetched or a process to be manipulated, and the backend pushes updates to the UI.

##### Architectural Patterns and Design Principles
- Separation of Concerns: There is a clear split between the UI logic (presentation) and system-level operations (business logic / system monitoring).
- Modularization: Both the frontend (with distinct components for toolbars, stats, modals) and backend (with separate modules for commands, process monitoring, and UI integration) exhibit high cohesiveness.
- Use of IPC (Inter-Process Communication): The design relies on Tauri continuously bridging JS and Rust code, ensuring smooth data flow.

##### Technologies and Frameworks
- Frontend:
- SvelteKit, Svelte, TypeScript, CSS (with custom theming via variables)
- Vite as a bundler (configuration shown in vite.config.js)
- Backend:
- Rust, Tauri framework (with its configuration in tauri.conf.json and Cargo.toml)
- Additional tooling/configuration:
- Prettier for code formatting, Husky for git hook enforcement, and GitHub Actions for CI/CD workflows.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend Layer"
        SvelteUI["Svelte UI (Frontend)"]:::frontend
        UIComponents["UI Components"]:::frontend
    end

    %% Central Bridge
    TauriBridge["Tauri Bridge"]:::bridge

    %% Backend Layer
    subgraph "Backend Layer"
        CommandHandlers["Command Handlers"]:::backend
        MonitoringModules["Monitoring Modules"]:::backend
        UIBridge["UI Bridge"]:::backend
        TauriConfig["Tauri Config (tauri.conf.json)"]:::backend
        CargoConfig["Cargo Config (Cargo.toml)"]:::backend
    end

    %% Connections between Frontend and Bridge
    SvelteUI -->|"IPC_invoke"| TauriBridge
    UIComponents -->|"compose"| SvelteUI

    %% Connections from Bridge to Backend
    TauriBridge -->|"handle_commands"| CommandHandlers
    TauriBridge -->|"fetch_metrics"| MonitoringModules

    %% Backend internal communication
    MonitoringModules -->|"update_UI"| UIBridge

    %% Communication from Backend back to Frontend
    UIBridge -->|"render_data"| SvelteUI

    %% Configuration feeding into Bridge
    TauriConfig -->|"load_config"| TauriBridge
    CargoConfig -->|"build_info"| TauriBridge

    %% Click Events for Frontend
    click SvelteUI "https://github.com/abdenasser/neohtop/tree/main/src/"
    click UIComponents "https://github.com/abdenasser/neohtop/tree/main/src/lib/components/"

    %% Click Events for Backend
    click CommandHandlers "https://github.com/abdenasser/neohtop/blob/main/src-tauri/src/commands.rs"
    click MonitoringModules "https://github.com/abdenasser/neohtop/tree/main/src-tauri/src/monitoring/"
    click UIBridge "https://github.com/abdenasser/neohtop/tree/main/src-tauri/src/ui/"
    click TauriConfig "https://github.com/abdenasser/neohtop/blob/main/src-tauri/tauri.conf.json"
    click CargoConfig "https://github.com/abdenasser/neohtop/blob/main/src-tauri/Cargo.toml"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef backend fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
    classDef bridge fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
```
