How hmz777/netstalkeravalonia works
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: DeviceScanner.cs Device scan · MainViewModel.cs Main VM · HomeViewModel.cs Routed VMs · MainView.axaml Shell views
Components 19
Core UI
Shared Avalonia shell, routed screens, and UI support code.
- App shell · Shared application entry, lifetime, and root resources.
NetStalkerAvalonia.Core/App.axaml - Main VM · Top-level view model that coordinates navigation and app state.
NetStalkerAvalonia.Core/ViewModels/MainViewModel.cs - View locator · Maps view models to views through conventional lookup.
NetStalkerAvalonia.Core/Helpers/ViewLocator.cs - Routed VMs · Home, options, sniffer, rule builder, help, and about screens.
NetStalkerAvalonia.Core/ViewModels/RoutedViewModels/HomeViewModel.cs - Routed views · Shell pages corresponding to the routed feature view models.
NetStalkerAvalonia.Core/Views/RoutedViews/HomeView.axaml - Shell views · Main window and shared UI components such as navigation and device lists.
NetStalkerAvalonia.Core/Views/MainView.axaml - UI support · 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 · Resolves and switches routed views for the shell.
NetStalkerAvalonia.Core/Services/Implementations/ViewRouting/ViewRouter.cs - Device scan · Discovers network devices and enriches them with name and type data.
NetStalkerAvalonia.Core/Services/Implementations/DeviceScanning/DeviceScanner.cs - Pcap devices · Manages capture devices and live device wrappers for packet access.
NetStalkerAvalonia.Core/Services/Implementations/PcapDeviceManagement/PcapDeviceManager.cs - Packet manager · Handles packet reception and capture flow from live devices.
NetStalkerAvalonia.Core/Services/Implementations/Packets/PacketManager.cs - Rule service · Creates and manages block, limit, and redirect rules.
NetStalkerAvalonia.Core/Services/Implementations/RulesService/RuleService.cs - Redirector · Applies blocking and redirection behavior at the network layer.
NetStalkerAvalonia.Core/Services/Implementations/BlockingRedirection/BlockerRedirector.cs - Device enrichers · Resolves device names and identifies device types.
NetStalkerAvalonia.Core/Services/Implementations/DeviceNameResolving/DeviceNameResolver.cs - App 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 · Windows startup project and platform DI composition.
NetStalkerAvalonia.Windows/Program.cs - Linux host · Linux startup project and platform DI composition.
NetStalkerAvalonia.Linux/Program.cs
Tests
Service, view model, and UI test projects.
- Tests · 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 · GitHub Actions, versioning, and Windows installer packaging.
.github/workflows/dotnet-desktop-windows.yml
Connections 25
- 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.