# hmz777/netstalkeravalonia architecture

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

- Interactive diagram: https://gitdiagram.com/hmz777/netstalkeravalonia
- Repository: https://github.com/hmz777/netstalkeravalonia

## Overview

1. **Overall structure**
   - This is a cross-platform desktop application built with **.NET + Avalonia** and organized as a **shared core** plus **platform host projects**.
   - The solution splits into:
     - `NetStalkerAvalonia.Core` — almost all app logic, view models, views, services, models, and UI assets.
     - `NetStalkerAvalonia.Windows` — Windows entry point and Windows-only services.
     - `NetStalkerAvalonia.Linux` — Linux entry point and Linux-only services.
     - `NetStalker.Tests` — service, view model, and UI tests.

2. **UI composition boundary**
   - The `Core` project contains the actual UI: `Views`, `ViewModels`, converters, behaviors, and shared assets/styles.
   - The app uses an MVVM-style split where views are thin XAML shells and state/commands live in view models.
   - A custom `ViewLocator`/`ConventionalViewLocator` and routed view model/view pairs indicate view selection is driven by type and navigation rather than hard-coded page wiring.

3. **Navigation and screen routing**
   - `MainViewModel` appears to be the top-level shell coordinator.
   - Feature screens are grouped under `RoutedViewModels` and `RoutedViews`:
     - Home
     - Options
     - Sniffer
     - Rule Builder
     - Help
     - About
   - This suggests a shell layout with a navigation bar and content area, rather than separate windows for each feature.

4. **Network capture and device discovery subsystem**
   - The core domain revolves around **network devices** and **packet capture**.
   - Key services:
     - `IPcapDeviceManager` / `PcapDeviceManager`
     - `IPcapLiveDevice` / `PcapLiveDevice`
     - `IPacketManager` / `PacketManager`
     - `IDeviceScanner` / `DeviceScanner`
   - The readme explicitly depends on **Npcap**, so packet capture is an external system dependency and a major architecture boundary.

5. **Blocking / redirection subsystem**
   - Device control is implemented through rules and a redirection layer:
     - `IRuleService` / `RuleService`
     - rule types: `BlockRule`, `LimitRule`, `RedirectRule`
     - `IBlockerRedirector` / `BlockerRedirector`
   - This is likely the main enforcement path: rules are created in UI, persisted/managed by services, then applied to network traffic or local routing/ARP behavior.
   - `ArpPacketType` in the blocking redirection folder indicates low-level network manipulation is part of the mechanism.

6. **Device enrichment pipeline**
   - Device records are not just raw scans; they are enriched by multiple services:
     - `IDeviceNameResolver` resolves human-readable names.
     - `IDeviceTypeIdentifier` identifies device category/type.
   - The `Device` model and helpers suggest the app builds a unified device list with identity, status, type, and network attributes.
   - The `DeviceListView` component and associated comparers/converters support that device-centric UI.

7. **Cross-cutting app services**
   - Several singleton-style services coordinate the app:
     - `IMessageBusService` for intra-app events/communication.
     - `IStatusMessageService` for user-visible status notifications.
     - `INotificationManager` for desktop notifications.
     - `IErrorHandler` for centralized error handling.
     - `IAppLockService` for single-instance / startup locking.
     - `IRouter` for navigation/routing.
   - These are the glue between view models and the lower-level network/rule services.

8. **Platform-specific host layer**
   - `NetStalkerAvalonia.Windows` and `NetStalkerAvalonia.Linux` contain the application entry points and platform-specific dependency injection setup.
   - Each platform project provides its own implementation of app locking:
     - `AppLockManagerWindows`
     - `AppLockManagerLinux`
   - This means the runtime composition is done at startup in the host project, while the shared app behavior remains in `Core`.

9. **Configuration and shared model layer**
   - Core configuration is centralized under `Configuration` and includes config keys/contracts.
   - Shared domain models include:
     - `Device`, `DeviceType`, `IpType`
     - `PacketType`, `PacketReceiveTechnique`
     - `NetworkClass`, `MessageType`
   - These models form the data contract passed between scanners, rule services, and the UI.

10. **UI support infrastructure**
   - The `Converters` and `Behaviors` folders show substantial XAML support code for presentation logic:
     - converting IP/MAC/enum/status values to display strings or icons
     - click/right-click behavior adjustments
     - image/icon lookup and theme-aware rendering
   - There is also a dedicated `Theme` area and reusable controls under `Views/Components`, indicating a heavily customized desktop UI.

11. **Assets and bundled static data**
   - The core project bundles icons, fonts, styles, and a `manuf.txt` asset.
   - `manuf.txt` likely supports vendor lookup from MAC addresses, reinforcing the device-identification workflow.
   - Static assets are part of the app runtime, not just design-time resources.

12. **Testing strategy**
   - Tests are divided by concern:
     - `ServiceSpecs` for lower-level service behavior like device scanning and blocker/redirection.
     - `ViewModelTests` for UI state/interaction logic.
     - `UITesting` for Avalonia UI integration tests.
   - The `AutoData` customizations indicate tests use fixture-based object generation with custom wiring for service and view model dependencies.

13. **Build and release plumbing**
   - GitHub Actions workflow exists for desktop Windows builds.
   - `GitVersion.yml` suggests versioning is automated from Git history.
   - `NetStalkerSetupScript.Windows.iss` indicates a Windows installer is built with Inno Setup.
   - `LocalSetupBuild.ps1` suggests local packaging/release automation.

14. **High-level runtime flow**
   - Startup occurs in the platform host project.
   - DI wires platform services plus shared services from `Core`.
   - `MainViewModel` and routing services establish the shell UI.
   - User actions flow into view models, then into services such as scanning, packet management, rules, and redirection.
   - Service events/status/messages flow back through the message bus and status/notification services into the UI.

15. **Architecture boundary to capture in a diagram**
   - The key boundary is between:
     - **UI/ViewModels** in `Core`
     - **domain/service layer** in `Core`
     - **platform-specific host services** in Windows/Linux
     - **external network capture dependency** via Npcap/Pcap
   - If you draw the system, the most important arrows are from views to view models, view models to services, services to packet/device/rule subsystems, and startup composition from each platform host into the shared core.

Main entry points: [`NetStalkerAvalonia.Core/Services/Implementations/DeviceScanning/DeviceScanner.cs`](https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Core/Services/Implementations/DeviceScanning/DeviceScanner.cs) (Device scan), [`NetStalkerAvalonia.Core/ViewModels/MainViewModel.cs`](https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Core/ViewModels/MainViewModel.cs) (Main VM), [`NetStalkerAvalonia.Core/ViewModels/RoutedViewModels/HomeViewModel.cs`](https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Core/ViewModels/RoutedViewModels/HomeViewModel.cs) (Routed VMs), [`NetStalkerAvalonia.Core/Views/MainView.axaml`](https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Core/Views/MainView.axaml) (Shell views)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core_ui["Core UI"]
  node_core_app["App shell<br/>Avalonia app<br/>[App.axaml]"]
  node_main_vm["Main VM<br/>shell coordinator<br/>[MainViewModel.cs]"]
  node_view_locator["View locator<br/>view resolution<br/>[ViewLocator.cs]"]
  node_routed_vms["Routed VMs<br/>feature view models<br/>[HomeViewModel.cs]"]
  node_routed_views["Routed views<br/>feature views<br/>[HomeView.axaml]"]
  node_shell_views["Shell views<br/>ui composition<br/>[MainView.axaml]"]
  node_ui_support["UI support<br/>presentation helpers"]
end

subgraph group_core_domain["Core Domain"]
  node_view_router["Router<br/>navigation service<br/>[ViewRouter.cs]"]
  node_device_scan["Device scan<br/>discovery pipeline<br/>[DeviceScanner.cs]"]
  node_device_mgr["Pcap devices<br/>capture adapter management"]
  node_packet_mgr["Packet manager<br/>packet pipeline<br/>[PacketManager.cs]"]
  node_rule_service["Rule service<br/>policy service<br/>[RuleService.cs]"]
  node_block_redirect["Redirector<br/>enforcement layer"]
  node_device_enrich["Device enrichers<br/>identity services"]
  node_glue_services["App services<br/>cross-cutting services"]
end

subgraph group_platform_hosts["Platform Hosts"]
  node_windows_host["Windows host<br/>desktop entrypoint<br/>[Program.cs]"]
  node_linux_host["Linux host<br/>desktop entrypoint<br/>[Program.cs]"]
end

subgraph group_tests["Tests"]
  node_tests_suite["Tests<br/>specs"]
end

subgraph group_build["Build & Release"]
  node_ci_release["CI & release<br/>automation"]
end

node_core_app -->|"starts shell"| node_main_vm
node_main_vm -->|"navigates"| node_view_router
node_view_router -->|"selects"| node_routed_vms
node_routed_vms -->|"paired with"| node_routed_views
node_view_locator -->|"resolves"| node_routed_views
node_shell_views -->|"binds to"| node_main_vm
node_shell_views -->|"hosts"| node_routed_views
node_shell_views -->|"uses"| node_ui_support
node_routed_vms -->|"requests scan"| node_device_scan
node_routed_vms -->|"edits rules"| node_rule_service
node_device_scan -->|"uses"| node_device_mgr
node_device_scan -->|"enriches"| node_device_enrich
node_device_scan -->|"observes traffic"| node_packet_mgr
node_packet_mgr -->|"captures via"| node_device_mgr
node_rule_service -->|"applies"| node_block_redirect
node_block_redirect -->|"acts on"| node_device_mgr
node_glue_services -->|"supports"| node_main_vm
node_windows_host -->|"composes"| node_core_app
node_linux_host -->|"composes"| node_core_app
node_windows_host -->|"registers"| node_glue_services
node_linux_host -->|"registers"| node_glue_services
node_tests_suite -->|"verifies"| node_device_scan
node_tests_suite -->|"verifies"| node_block_redirect
node_tests_suite -->|"verifies"| node_main_vm
node_ci_release -->|"builds"| node_windows_host

click node_core_app "https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Core/App.axaml"
click node_main_vm "https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Core/ViewModels/MainViewModel.cs"
click node_view_router "https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Core/Services/Implementations/ViewRouting/ViewRouter.cs"
click node_view_locator "https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Core/Helpers/ViewLocator.cs"
click node_routed_vms "https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Core/ViewModels/RoutedViewModels/HomeViewModel.cs"
click node_routed_views "https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Core/Views/RoutedViews/HomeView.axaml"
click node_shell_views "https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Core/Views/MainView.axaml"
click node_ui_support "https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Core/Converters/EnumToStringConverter.cs"
click node_device_scan "https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Core/Services/Implementations/DeviceScanning/DeviceScanner.cs"
click node_device_mgr "https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Core/Services/Implementations/PcapDeviceManagement/PcapDeviceManager.cs"
click node_packet_mgr "https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Core/Services/Implementations/Packets/PacketManager.cs"
click node_rule_service "https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Core/Services/Implementations/RulesService/RuleService.cs"
click node_block_redirect "https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Core/Services/Implementations/BlockingRedirection/BlockerRedirector.cs"
click node_device_enrich "https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Core/Services/Implementations/DeviceNameResolving/DeviceNameResolver.cs"
click node_glue_services "https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Core/Services/IMessageBusService.cs"
click node_windows_host "https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Windows/Program.cs"
click node_linux_host "https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Linux/Program.cs"
click node_tests_suite "https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalker.Tests/ServiceSpecs/DeviceScannerSpec.cs"
click node_ci_release "https://github.com/hmz777/netstalkeravalonia/blob/master/.github/workflows/dotnet-desktop-windows.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_core_app,node_main_vm,node_view_locator,node_routed_vms,node_routed_views,node_shell_views,node_ui_support toneBlue
class node_view_router,node_device_scan,node_device_mgr,node_packet_mgr,node_rule_service,node_block_redirect,node_device_enrich,node_glue_services toneAmber
class node_windows_host,node_linux_host toneMint
class node_tests_suite toneRose
class node_ci_release toneIndigo
```

## Components

### Core UI

Shared Avalonia shell, routed screens, and UI support code.

- [App shell](https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Core/App.axaml): Avalonia app · Shared application entry, lifetime, and root resources. · `NetStalkerAvalonia.Core/App.axaml`
- [Main VM](https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Core/ViewModels/MainViewModel.cs): shell coordinator · Top-level view model that coordinates navigation and app state. · `NetStalkerAvalonia.Core/ViewModels/MainViewModel.cs`
- [View locator](https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Core/Helpers/ViewLocator.cs): view resolution · Maps view models to views through conventional lookup. · `NetStalkerAvalonia.Core/Helpers/ViewLocator.cs`
- [Routed VMs](https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Core/ViewModels/RoutedViewModels/HomeViewModel.cs): feature view models · Home, options, sniffer, rule builder, help, and about screens. · `NetStalkerAvalonia.Core/ViewModels/RoutedViewModels/HomeViewModel.cs`
- [Routed views](https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Core/Views/RoutedViews/HomeView.axaml): feature views · Shell pages corresponding to the routed feature view models. · `NetStalkerAvalonia.Core/Views/RoutedViews/HomeView.axaml`
- [Shell views](https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Core/Views/MainView.axaml): ui composition · Main window and shared UI components such as navigation and device lists. · `NetStalkerAvalonia.Core/Views/MainView.axaml`
- [UI support](https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Core/Converters/EnumToStringConverter.cs): presentation helpers · Converters, behaviors, theme resources, and icon assets used by Avalonia bindings. · `NetStalkerAvalonia.Core/Converters/EnumToStringConverter.cs`

### Core Domain

Shared models and services for device discovery, packet capture, rules, and routing.

- [Router](https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Core/Services/Implementations/ViewRouting/ViewRouter.cs): navigation service · Resolves and switches routed views for the shell. · `NetStalkerAvalonia.Core/Services/Implementations/ViewRouting/ViewRouter.cs`
- [Device scan](https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Core/Services/Implementations/DeviceScanning/DeviceScanner.cs): discovery pipeline · Discovers network devices and enriches them with name and type data. · `NetStalkerAvalonia.Core/Services/Implementations/DeviceScanning/DeviceScanner.cs`
- [Pcap devices](https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Core/Services/Implementations/PcapDeviceManagement/PcapDeviceManager.cs): capture adapter management · Manages capture devices and live device wrappers for packet access. · `NetStalkerAvalonia.Core/Services/Implementations/PcapDeviceManagement/PcapDeviceManager.cs`
- [Packet manager](https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Core/Services/Implementations/Packets/PacketManager.cs): packet pipeline · Handles packet reception and capture flow from live devices. · `NetStalkerAvalonia.Core/Services/Implementations/Packets/PacketManager.cs`
- [Rule service](https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Core/Services/Implementations/RulesService/RuleService.cs): policy service · Creates and manages block, limit, and redirect rules. · `NetStalkerAvalonia.Core/Services/Implementations/RulesService/RuleService.cs`
- [Redirector](https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Core/Services/Implementations/BlockingRedirection/BlockerRedirector.cs): enforcement layer · Applies blocking and redirection behavior at the network layer. · `NetStalkerAvalonia.Core/Services/Implementations/BlockingRedirection/BlockerRedirector.cs`
- [Device enrichers](https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Core/Services/Implementations/DeviceNameResolving/DeviceNameResolver.cs): identity services · Resolves device names and identifies device types. · `NetStalkerAvalonia.Core/Services/Implementations/DeviceNameResolving/DeviceNameResolver.cs`
- [App services](https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Core/Services/IMessageBusService.cs): cross-cutting services · Message bus, status messages, notifications, error handling, app lock, and shared routing contracts. · `NetStalkerAvalonia.Core/Services/IMessageBusService.cs`

### Platform Hosts

Windows and Linux startup projects that compose platform-specific services.

- [Windows host](https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Windows/Program.cs): desktop entrypoint · Windows startup project and platform DI composition. · `NetStalkerAvalonia.Windows/Program.cs`
- [Linux host](https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalkerAvalonia.Linux/Program.cs): desktop entrypoint · Linux startup project and platform DI composition. · `NetStalkerAvalonia.Linux/Program.cs`

### Tests

Service, view model, and UI test projects.

- [Tests](https://github.com/hmz777/netstalkeravalonia/blob/master/NetStalker.Tests/ServiceSpecs/DeviceScannerSpec.cs): specs · Service specs, view model tests, and Avalonia UI tests. · `NetStalker.Tests/ServiceSpecs/DeviceScannerSpec.cs`

### Build & Release

Automation and packaging files for versioning, CI, and installers.

- [CI & release](https://github.com/hmz777/netstalkeravalonia/blob/master/.github/workflows/dotnet-desktop-windows.yml): automation · GitHub Actions, versioning, and Windows installer packaging. · `.github/workflows/dotnet-desktop-windows.yml`

## Connections

- App shell → Main VM: starts shell · The application root hosts the top-level shell view model.
- Main VM → Router: navigates · The shell delegates page switching to the router.
- Router → Routed VMs: selects · Routing targets the feature view models.
- Routed VMs → Routed views: paired with · Feature view models are rendered by matching routed views.
- View locator → Routed views: resolves · Conventional lookup binds view models to their view types.
- Shell views → Main VM: binds to · The main shell view binds its state and commands to the shell view model.
- Shell views → Routed views: hosts · The shell contains the routed content area and shared navigation UI.
- Shell views → UI support: uses · Shared presentation helpers support styling and binding.
- Routed VMs → Device scan: requests scan · Feature screens drive discovery and refresh flows.
- Routed VMs → Rule service: edits rules · Rule builder and related screens create and manage policy.
- Device scan → Pcap devices: uses · Scanning depends on capture-device management.
- Device scan → Device enrichers: enriches · Discovered devices are decorated with names and types.
- Device scan → Packet manager: observes traffic · Discovery and monitoring are tied to packet reception.
- Packet manager → Pcap devices: captures via · Packet processing runs through live Pcap devices.
- Rule service → Redirector: applies · Rules are enforced through the blocker/redirection layer.
- Redirector → Pcap devices: acts on · Redirection and blocking operate on network interfaces and capture context.
- App services → Main VM: supports · Shared app services provide UI messaging, routing, notifications, and errors.
- Windows host → App shell: composes · The Windows host wires the shared application into platform startup.
- Linux host → App shell: composes · The Linux host wires the shared application into platform startup.
- Windows host → App services: registers · Windows startup provides platform-specific implementations such as app lock.
- Linux host → App services: registers · Linux startup provides platform-specific implementations such as app lock.
- Tests → Device scan: verifies · Service specs cover scanning behavior.
- Tests → Redirector: verifies · Service specs cover enforcement behavior.
- Tests → Main VM: verifies · View model tests exercise shell interaction logic.
- CI & release → Windows host: builds · CI and packaging are focused on the Windows desktop build.
