# ronin15/rust_edr_agent architecture

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

- Interactive diagram: https://gitdiagram.com/ronin15/rust_edr_agent
- Repository: https://github.com/ronin15/rust_edr_agent

## Overview

1. **Overall shape**
   This is a single Rust crate that builds an endpoint-detection agent. The code is organized as a library in `src/lib.rs` plus one main agent binary in `src/edr_main.rs`, with a few standalone test binaries under `src/bin/` and top-level test drivers like `test_linux_detection.rs`.

2. **Runtime and orchestration**
   `agent.rs` is the central coordinator. It owns the lifecycle of the monitoring pipeline: load config, start collectors, receive events, pass them through deduplication and detectors, then persist or emit alerts. The project is built around async execution with Tokio, which matters because collectors run concurrently.

3. **Configuration boundary**
   `config.rs` loads YAML-based settings from the repo’s `config.yaml` files. Configuration controls which collectors are enabled, batching behavior, storage/compression settings, logging, and detection thresholds. This is the main externalized control plane for the agent.

4. **Collection layer**
   `src/collectors/manager.rs` coordinates the individual data sources:
   - `process.rs` for process lifecycle and behavior tracking
   - `file.rs` for file-system activity and hashing
   - `network.rs` for network connections and DNS observation
   - `registry.rs` for Windows registry monitoring
   These collectors are the system-boundary adapters: they translate OS-specific telemetry into the project’s internal event model.

5. **Unified event model**
   `events.rs` defines the shared event structures that the rest of the system consumes. This is the normalization boundary between raw OS telemetry and higher-level security logic. The rest of the pipeline operates on these common events rather than directly on platform APIs.

6. **Detection layer**
   `src/detectors/manager.rs` dispatches events into the active detectors:
   - `behavioral.rs` for suspicious execution, process injection, and context-aware risk scoring
   - `dns_anomaly.rs` for DNS tunneling, suspicious domains, and C2-style patterns
   - `registry.rs` for registry-focused detections
   This is the analysis boundary: raw activity becomes security findings and risk scores here.

7. **Deduplication and alert suppression**
   `deduplication.rs` sits between event ingestion and downstream processing to reduce repeated noise. The readme makes clear that it is intentionally conservative: it preserves security-critical events while rate-limiting repetitive, low-value alerts. This module is important for diagramming because it changes the volume and shape of data flowing to detectors, storage, and logs.

8. **Storage and retention**
   `storage.rs` handles persistence of collected output, with compression enabled for efficiency. The design emphasizes low memory use and retention cleanup, so the storage subsystem is not just a sink; it is also a lifecycle manager for historical event data.

9. **Networking and external integrations**
   `src/network.rs` exists, but the readme explicitly says centralized management / phone-home networking is not implemented yet. So the architecture currently stops at local agent processing: no backend service, no SIEM connector, and no command-and-control channel in this repository.

10. **Platform-specific boundaries**
   The repo is explicitly cross-platform, but not all capabilities are universal. Registry monitoring is Windows-only, while the behavioral and DNS detectors have Linux/macOS-specific test coverage in `test_linux_detection.rs` and `test_mac_detection.rs`. Conditional compilation and platform-aware rules are important architectural boundaries.

11. **Validation and support tooling**
   The top-level test binaries exercise detection scenarios end-to-end, especially DNS anomaly handling and platform-specific behavioral rules. Documentation in `docs/` is extensive and maps to the code modules, so the repo is designed to be understood and tuned as a security-monitoring system rather than a simple library.

12. **Primary data flow**
   The core flow is:
   system activity → collectors → unified events → deduplication → detectors → alerts/storage.
   The important architectural point is that telemetry is normalized early, then fanned out into both storage and detection, with deduplication acting as a noise-control gate in the middle.

Main entry points: [`src/agent.rs`](https://github.com/ronin15/rust_edr_agent/blob/main/src/agent.rs) (Agent), [`src/lib.rs`](https://github.com/ronin15/rust_edr_agent/blob/main/src/lib.rs) (Library), [`src/detectors/manager.rs`](https://github.com/ronin15/rust_edr_agent/blob/main/src/detectors/manager.rs) (Detector mgr), [`src/collectors/manager.rs`](https://github.com/ronin15/rust_edr_agent/blob/main/src/collectors/manager.rs) (Collector mgr)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core agent"]
  node_lib["Library<br/>crate root<br/>[lib.rs]"]
  node_agent["Agent<br/>runtime coordinator<br/>[agent.rs]"]
  node_config["Config<br/>yaml settings<br/>[config.rs]"]
  node_events["Events<br/>shared model<br/>[events.rs]"]
  node_main_bin["EDR main<br/>agent binary<br/>[edr_main.rs]"]
end

subgraph group_collectors["Collectors"]
  node_collector_mgr["Collector mgr<br/>collection coordinator<br/>[manager.rs]"]
  node_process_collector(("Process<br/>[process.rs]"))
  node_file_collector(("File<br/>[file.rs]"))
  node_network_collector(("Network<br/>[network.rs]"))
  node_registry_collector(("Registry<br/>[registry.rs]"))
end

subgraph group_detection["Detection"]
  node_dedup{{"Deduplication<br/>noise gate<br/>[deduplication.rs]"}}
  node_detector_mgr["Detector mgr<br/>analysis dispatcher<br/>[manager.rs]"]
  node_behavioral(("Behavioral<br/>behavior detector<br/>[behavioral.rs]"))
  node_dns_anomaly(("DNS anomaly<br/>dns detector<br/>[dns_anomaly.rs]"))
  node_registry_det(("Registry det<br/>[registry.rs]"))
end

subgraph group_support["Support"]
  node_storage[("Storage<br/>persistent sink<br/>[storage.rs]")]
  node_network_api(("Network API<br/>external integration stub<br/>[network.rs]"))
end

subgraph group_validation["Validation"]
  node_integration_test["Integration test<br/>test driver"]
  node_linux_test["Linux test<br/>platform test"]
  node_mac_test["Mac test<br/>platform test"]
  node_dns_test["DNS test<br/>scenario test"]
end

node_lib -->|"orchestrates"| node_agent
node_lib -->|"loads"| node_config
node_lib -->|"defines"| node_events
node_lib -->|"exposes"| node_collector_mgr
node_lib -->|"includes"| node_dedup
node_lib -->|"exposes"| node_detector_mgr
node_lib -->|"includes"| node_storage
node_agent -->|"reads"| node_config
node_agent -->|"starts"| node_collector_mgr
node_agent -->|"gates"| node_dedup
node_agent -->|"dispatches"| node_detector_mgr
node_agent -->|"persists"| node_storage
node_collector_mgr -->|"runs"| node_process_collector
node_collector_mgr -->|"runs"| node_file_collector
node_collector_mgr -->|"runs"| node_network_collector
node_collector_mgr -->|"runs"| node_registry_collector
node_process_collector -->|"emits"| node_events
node_file_collector -->|"emits"| node_events
node_network_collector -->|"emits"| node_events
node_registry_collector -->|"emits"| node_events
node_dedup -->|"feeds"| node_detector_mgr
node_detector_mgr -->|"dispatches"| node_behavioral
node_detector_mgr -->|"dispatches"| node_dns_anomaly
node_detector_mgr -->|"dispatches"| node_registry_det
node_detector_mgr -->|"records"| node_storage
node_agent -.->|"does not use"| node_network_api
node_main_bin -->|"launches"| node_agent
node_integration_test -.->|"exercises"| node_agent
node_linux_test -.->|"covers"| node_behavioral
node_mac_test -.->|"covers"| node_behavioral
node_dns_test -.->|"covers"| node_dns_anomaly

click node_lib "https://github.com/ronin15/rust_edr_agent/blob/main/src/lib.rs"
click node_agent "https://github.com/ronin15/rust_edr_agent/blob/main/src/agent.rs"
click node_config "https://github.com/ronin15/rust_edr_agent/blob/main/src/config.rs"
click node_events "https://github.com/ronin15/rust_edr_agent/blob/main/src/events.rs"
click node_collector_mgr "https://github.com/ronin15/rust_edr_agent/blob/main/src/collectors/manager.rs"
click node_process_collector "https://github.com/ronin15/rust_edr_agent/blob/main/src/collectors/process.rs"
click node_file_collector "https://github.com/ronin15/rust_edr_agent/blob/main/src/collectors/file.rs"
click node_network_collector "https://github.com/ronin15/rust_edr_agent/blob/main/src/collectors/network.rs"
click node_registry_collector "https://github.com/ronin15/rust_edr_agent/blob/main/src/collectors/registry.rs"
click node_dedup "https://github.com/ronin15/rust_edr_agent/blob/main/src/deduplication.rs"
click node_detector_mgr "https://github.com/ronin15/rust_edr_agent/blob/main/src/detectors/manager.rs"
click node_behavioral "https://github.com/ronin15/rust_edr_agent/blob/main/src/detectors/behavioral.rs"
click node_dns_anomaly "https://github.com/ronin15/rust_edr_agent/blob/main/src/detectors/dns_anomaly.rs"
click node_registry_det "https://github.com/ronin15/rust_edr_agent/blob/main/src/detectors/registry.rs"
click node_storage "https://github.com/ronin15/rust_edr_agent/blob/main/src/storage.rs"
click node_network_api "https://github.com/ronin15/rust_edr_agent/blob/main/src/network.rs"
click node_main_bin "https://github.com/ronin15/rust_edr_agent/blob/main/src/edr_main.rs"
click node_integration_test "https://github.com/ronin15/rust_edr_agent/blob/main/src/bin/test_integration.rs"
click node_linux_test "https://github.com/ronin15/rust_edr_agent/blob/main/test_linux_detection.rs"
click node_mac_test "https://github.com/ronin15/rust_edr_agent/blob/main/test_mac_detection.rs"
click node_dns_test "https://github.com/ronin15/rust_edr_agent/blob/main/test_dns_anomaly_detection.rs"

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_lib,node_agent,node_config,node_events,node_main_bin toneBlue
class node_collector_mgr,node_process_collector,node_file_collector,node_network_collector,node_registry_collector toneAmber
class node_dedup,node_detector_mgr,node_behavioral,node_dns_anomaly,node_registry_det toneMint
class node_storage,node_network_api toneRose
class node_integration_test,node_linux_test,node_mac_test,node_dns_test toneIndigo
```

## Components

### Core agent

Runtime, config, events, and pipeline orchestration

- [Library](https://github.com/ronin15/rust_edr_agent/blob/main/src/lib.rs): crate root · Public crate surface and module wiring · `src/lib.rs`
- [Agent](https://github.com/ronin15/rust_edr_agent/blob/main/src/agent.rs): runtime coordinator · Owns lifecycle and end-to-end event flow · `src/agent.rs`
- [Config](https://github.com/ronin15/rust_edr_agent/blob/main/src/config.rs): yaml settings · Loads and applies agent configuration · `src/config.rs`
- [Events](https://github.com/ronin15/rust_edr_agent/blob/main/src/events.rs): shared model · Normalized internal event structures · `src/events.rs`
- [EDR main](https://github.com/ronin15/rust_edr_agent/blob/main/src/edr_main.rs): agent binary · Executable entry point for the agent · `src/edr_main.rs`

### Collectors

OS telemetry adapters and collection coordination

- [Collector mgr](https://github.com/ronin15/rust_edr_agent/blob/main/src/collectors/manager.rs): collection coordinator · Starts and coordinates OS-specific collectors · `src/collectors/manager.rs`
- [Process](https://github.com/ronin15/rust_edr_agent/blob/main/src/collectors/process.rs): process telemetry · Process lifecycle and behavior observation · `src/collectors/process.rs`
- [File](https://github.com/ronin15/rust_edr_agent/blob/main/src/collectors/file.rs): file telemetry · File activity and hashing collection · `src/collectors/file.rs`
- [Network](https://github.com/ronin15/rust_edr_agent/blob/main/src/collectors/network.rs): network telemetry · Connections and DNS observation · `src/collectors/network.rs`
- [Registry](https://github.com/ronin15/rust_edr_agent/blob/main/src/collectors/registry.rs): registry telemetry · Windows registry monitoring · `src/collectors/registry.rs`

### Detection

Deduplication and security analysis

- [Deduplication](https://github.com/ronin15/rust_edr_agent/blob/main/src/deduplication.rs): noise gate · Suppresses repetitive low-value events while preserving critical ones · `src/deduplication.rs`
- [Detector mgr](https://github.com/ronin15/rust_edr_agent/blob/main/src/detectors/manager.rs): analysis dispatcher · Routes events to active detectors · `src/detectors/manager.rs`
- [Behavioral](https://github.com/ronin15/rust_edr_agent/blob/main/src/detectors/behavioral.rs): behavior detector · Suspicious execution, injection, and risk scoring · `src/detectors/behavioral.rs`
- [DNS anomaly](https://github.com/ronin15/rust_edr_agent/blob/main/src/detectors/dns_anomaly.rs): dns detector · DNS tunneling and C2-style pattern detection · `src/detectors/dns_anomaly.rs`
- [Registry det](https://github.com/ronin15/rust_edr_agent/blob/main/src/detectors/registry.rs): registry detector · Registry-focused detection logic · `src/detectors/registry.rs`

### Support

Persistence, networking stubs, and shared helpers

- [Storage](https://github.com/ronin15/rust_edr_agent/blob/main/src/storage.rs): persistent sink · Compressed persistence and retention management · `src/storage.rs`
- [Network API](https://github.com/ronin15/rust_edr_agent/blob/main/src/network.rs): external integration stub · Placeholder networking surface; no backend channel yet · `src/network.rs`

### Validation

Standalone test drivers and platform coverage

- [Integration test](https://github.com/ronin15/rust_edr_agent/blob/main/src/bin/test_integration.rs): test driver · End-to-end scenario coverage for the agent pipeline · `src/bin/test_integration.rs`
- [Linux test](https://github.com/ronin15/rust_edr_agent/blob/main/test_linux_detection.rs): platform test · Linux-focused detection scenarios · `test_linux_detection.rs`
- [Mac test](https://github.com/ronin15/rust_edr_agent/blob/main/test_mac_detection.rs): platform test · macOS-focused detection scenarios · `test_mac_detection.rs`
- [DNS test](https://github.com/ronin15/rust_edr_agent/blob/main/test_dns_anomaly_detection.rs): scenario test · DNS anomaly detection coverage · `test_dns_anomaly_detection.rs`

## Connections

- Library → Agent: orchestrates · Library wires the agent runtime
- Library → Config: loads · Configuration boundary for the crate
- Library → Events: defines · Shared event model used across the pipeline
- Library → Collector mgr: exposes · Collector subsystem entry point
- Library → Deduplication: includes · Noise suppression layer
- Library → Detector mgr: exposes · Detection subsystem entry point
- Library → Storage: includes · Persistence and retention layer
- Agent → Config: reads · Agent bootstraps from config
- Agent → Collector mgr: starts · Agent enables collectors during runtime
- Agent → Deduplication: gates · Agent applies deduplication before downstream processing
- Agent → Detector mgr: dispatches · Agent sends normalized events to detectors
- Agent → Storage: persists · Agent stores collected output and findings
- Collector mgr → Process: runs · Process telemetry source
- Collector mgr → File: runs · File telemetry source
- Collector mgr → Network: runs · Network telemetry source
- Collector mgr → Registry: runs · Registry telemetry source
- Process → Events: emits · Collects into the shared event model
- File → Events: emits · Collects into the shared event model
- Network → Events: emits · Collects into the shared event model
- Registry → Events: emits · Collects into the shared event model
- Deduplication → Detector mgr: feeds · Reduced event stream enters analysis
- Detector mgr → Behavioral: dispatches · Behavioral analysis rules
- Detector mgr → DNS anomaly: dispatches · DNS anomaly rules
- Detector mgr → Registry det: dispatches · Registry detection rules
- Detector mgr → Storage: records · Detection output can be persisted
- Agent → Network API: does not use · Repository currently lacks a backend or phone-home channel
- EDR main → Agent: launches · Executable entry point starts the agent
- Integration test → Agent: exercises · End-to-end pipeline coverage
- Linux test → Behavioral: covers · Linux platform detection behavior
- Mac test → Behavioral: covers · macOS platform detection behavior
- DNS test → DNS anomaly: covers · DNS anomaly scenario coverage
