# karib0u/rustinel architecture

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

- Interactive diagram: https://gitdiagram.com/karib0u/rustinel
- Repository: https://github.com/karib0u/rustinel

## Overview

1. **What this repo is**
   Rustinel is a Windows-only, user-mode EDR agent. Its core architecture is a pipeline: ETW telemetry in, normalization/enrichment in the middle, detection/response decisions after that, and ECS NDJSON alerts/logs out to disk for SIEM ingestion.

2. **Top-level runtime boundary**
   The main executable is `src/main.rs`, with shared application logic in `src/lib.rs`. There is also a separate maintenance binary, `src/bin/validate_rules.rs`, for validating Sigma/YARA rule files. The repo is organized as a long-running agent, not a request/response service.

3. **Telemetry collection layer**
   `src/collector/` is the ingestion boundary. Per the README, it collects kernel telemetry via ETW for process, network, file, registry, DNS, PowerShell, WMI, services, and tasks. This layer also applies some noise reduction early, such as keyword filtering and router-level filtering for high-volume event types.

4. **Normalization and schema mapping**
   `src/normalizer/` converts raw ETW events into a Sysmon-compatible internal schema. This is the key adapter layer that makes downstream Sigma rules usable. The mapping/field translation logic lives in `field_maps.rs` and `mapper.rs`, which suggests a deliberate separation between raw event shapes and the normalized event model.

5. **Core event model**
   `src/models/ecs.rs` and `src/models/mod.rs` define the output-facing ECS structure. The alert payloads are designed to be ECS NDJSON lines, which is the architectural contract with downstream log shipping and SIEM tooling.

6. **Detection engines are split by modality**
   `src/engine/` is the Sigma behavioral detection engine. `src/scanner/` is the YARA file-scanning worker. `src/ioc/` handles atomic IOC matching for hashes, IPs/CIDRs, domains, and path regexes. These are intentionally separate because they operate on different event types and have different performance characteristics.

7. **Where detection happens in the flow**
   Sigma runs on normalized telemetry events, YARA is triggered on process creation and runs in a background worker, and IOC checks are mixed between inline checks and background hashing. The design keeps the hot path light by only attaching expensive context and doing heavier work when needed.

8. **State and correlation services**
   `src/state/` is the shared cache/correlation layer. The README calls out process correlation, SID-to-username resolution, DNS caching/reverse mapping, and optional connection aggregation, so this module likely backs cross-event enrichment and deduplication. This is the main in-memory boundary that makes alerts more contextual than the raw ETW stream.

9. **Enrichment and utility boundaries**
   `src/utils/` contains supporting cross-cutting helpers: path normalization, PE metadata extraction, process/user helpers, time, and log rate limiting. These utilities support enrichment without polluting the collector or detection logic, which keeps the pipeline modular.

10. **Alerting and active response**
   `src/alerts.rs` and `src/response/` are the output/actuation side. Alerts are written as daily ECS NDJSON files, while active response can optionally terminate processes on critical detections. This is a clean separation between “observe and record” and “enforce.”

11. **Hot reload and operational control**
   `src/reload/` manages in-place reloading of Sigma, YARA, and IOC files with debounce and atomic swaps. `src/config.rs` owns configuration precedence across defaults, `config.toml`, environment variables, and CLI flags. This means the agent can be tuned and updated without restarting, which is important for endpoint operations.

12. **External interfaces and deployment shape**
   The agent supports Windows service mode and console mode, but it remains a single-host, local-first product: rules live on disk under `rules/`, alerts/logs go to local files under `logs/`, and ingestion happens directly from ETW rather than from a remote backend. The repo also includes docs, examples, and CI workflows, but those support the agent rather than defining runtime architecture.

13. **Architecture summary in one sentence**
   ETW events enter through a user-mode collector, are normalized into a Sysmon-like internal schema, enriched from local state/caches, evaluated by Sigma/YARA/IOC engines, and then emitted as ECS alerts or used for optional active response.

Main entry points: [`src/normalizer/mod.rs`](https://github.com/karib0u/rustinel/blob/main/src/normalizer/mod.rs) (Normalizer), [`src/lib.rs`](https://github.com/karib0u/rustinel/blob/main/src/lib.rs) (Core Lib), [`src/collector/mod.rs`](https://github.com/karib0u/rustinel/blob/main/src/collector/mod.rs) (Collector), [`src/engine/mod.rs`](https://github.com/karib0u/rustinel/blob/main/src/engine/mod.rs) (Sigma Engine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_main["Agent<br/>binary<br/>[main.rs]"]
  node_lib["Core Lib<br/>shared crate<br/>[lib.rs]"]
  node_validate_rules["Rule Check<br/>maintenance binary<br/>[validate_rules.rs]"]
  node_config["Config<br/>settings<br/>[config.rs]"]
end

subgraph group_pipeline["Pipeline"]
  node_collector["Collector<br/>ETW ingest<br/>[mod.rs]"]
  node_normalizer["Normalizer<br/>schema adapter<br/>[mod.rs]"]
  node_field_maps["Field Maps<br/>mapping tables<br/>[field_maps.rs]"]
  node_mapper["Mapper<br/>translator<br/>[mapper.rs]"]
  node_alerts["Alerts<br/>output writer<br/>[alerts.rs]"]
  node_response["Response<br/>[mod.rs]"]
end

subgraph group_detection["Detection"]
  node_engine["Sigma Engine<br/>behavioral detection<br/>[mod.rs]"]
  node_handler["Handler<br/>match flow<br/>[handler.rs]"]
  node_scanner["YARA Scanner<br/>file scanning<br/>[mod.rs]"]
  node_ioc["IOC Match<br/>atomic matching<br/>[mod.rs]"]
end

subgraph group_support["Support"]
  node_state[("State<br/>cache/correlation<br/>[mod.rs]")]
  node_utils["Utils<br/>helpers<br/>[mod.rs]"]
  node_models["ECS Models<br/>output schema<br/>[mod.rs]"]
  node_ecs["ECS<br/>payload schema<br/>[ecs.rs]"]
end

subgraph group_assets["Rules"]
  node_rules_sigma["Sigma Rules<br/>rule pack<br/>[example_whoami.yml]"]
  node_rules_yara["YARA Rules<br/>rule pack"]
  node_rules_ioc["IOC Lists<br/>rule pack<br/>[hashes.txt]"]
end

node_main -->|"uses"| node_lib
node_validate_rules -->|"checks"| node_rules_sigma
node_validate_rules -->|"checks"| node_rules_yara
node_lib -->|"loads"| node_config
node_lib -->|"starts"| node_collector
node_collector -->|"emits"| node_normalizer
node_normalizer -->|"uses"| node_field_maps
node_normalizer -->|"applies"| node_mapper
node_normalizer -->|"enriches with"| node_state
node_normalizer -->|"calls"| node_utils
node_normalizer -->|"feeds"| node_engine
node_collector -->|"inline checks"| node_ioc
node_lib -->|"spawns"| node_scanner
node_scanner -->|"loads"| node_rules_yara
node_engine -->|"dispatches"| node_handler
node_engine -->|"evaluates"| node_rules_sigma
node_ioc -->|"loads"| node_rules_ioc
node_handler -->|"writes"| node_alerts
node_handler -->|"may trigger"| node_response
node_alerts -->|"formats as"| node_models
node_models -->|"defines"| node_ecs

click node_main "https://github.com/karib0u/rustinel/blob/main/src/main.rs"
click node_lib "https://github.com/karib0u/rustinel/blob/main/src/lib.rs"
click node_validate_rules "https://github.com/karib0u/rustinel/blob/main/src/bin/validate_rules.rs"
click node_config "https://github.com/karib0u/rustinel/blob/main/src/config.rs"
click node_collector "https://github.com/karib0u/rustinel/blob/main/src/collector/mod.rs"
click node_normalizer "https://github.com/karib0u/rustinel/blob/main/src/normalizer/mod.rs"
click node_field_maps "https://github.com/karib0u/rustinel/blob/main/src/normalizer/field_maps.rs"
click node_mapper "https://github.com/karib0u/rustinel/blob/main/src/normalizer/mapper.rs"
click node_state "https://github.com/karib0u/rustinel/blob/main/src/state/mod.rs"
click node_utils "https://github.com/karib0u/rustinel/blob/main/src/utils/mod.rs"
click node_models "https://github.com/karib0u/rustinel/blob/main/src/models/mod.rs"
click node_ecs "https://github.com/karib0u/rustinel/blob/main/src/models/ecs.rs"
click node_engine "https://github.com/karib0u/rustinel/blob/main/src/engine/mod.rs"
click node_handler "https://github.com/karib0u/rustinel/blob/main/src/engine/handler.rs"
click node_scanner "https://github.com/karib0u/rustinel/blob/main/src/scanner/mod.rs"
click node_ioc "https://github.com/karib0u/rustinel/blob/main/src/ioc/mod.rs"
click node_alerts "https://github.com/karib0u/rustinel/blob/main/src/alerts.rs"
click node_response "https://github.com/karib0u/rustinel/blob/main/src/response/mod.rs"
click node_rules_sigma "https://github.com/karib0u/rustinel/blob/main/rules/sigma/example_whoami.yml"
click node_rules_yara "https://github.com/karib0u/rustinel/blob/main/rules/yara/example_test_string.yar"
click node_rules_ioc "https://github.com/karib0u/rustinel/blob/main/rules/ioc/hashes.txt"

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_main,node_lib,node_validate_rules,node_config toneBlue
class node_collector,node_normalizer,node_field_maps,node_mapper,node_alerts,node_response toneAmber
class node_engine,node_handler,node_scanner,node_ioc toneMint
class node_state,node_utils,node_models,node_ecs toneRose
class node_rules_sigma,node_rules_yara,node_rules_ioc toneIndigo
```

## Components

### Runtime

Long-running agent entrypoints and operational control.

- [Agent](https://github.com/karib0u/rustinel/blob/main/src/main.rs): binary · Windows service/console entrypoint for the EDR agent. · `src/main.rs`
- [Core Lib](https://github.com/karib0u/rustinel/blob/main/src/lib.rs): shared crate · Shared application logic used by the binaries. · `src/lib.rs`
- [Rule Check](https://github.com/karib0u/rustinel/blob/main/src/bin/validate_rules.rs): maintenance binary · Standalone validator for Sigma and YARA rule files. · `src/bin/validate_rules.rs`
- [Config](https://github.com/karib0u/rustinel/blob/main/src/config.rs): settings · Configuration precedence and runtime options. · `src/config.rs`

### Pipeline

Telemetry ingestion, normalization, enrichment, and alerting flow.

- [Collector](https://github.com/karib0u/rustinel/blob/main/src/collector/mod.rs): ETW ingest · Kernel telemetry ingestion and early noise reduction. · `src/collector/mod.rs`
- [Normalizer](https://github.com/karib0u/rustinel/blob/main/src/normalizer/mod.rs): schema adapter · Maps raw ETW events into a Sysmon-like internal schema. · `src/normalizer/mod.rs`
- [Field Maps](https://github.com/karib0u/rustinel/blob/main/src/normalizer/field_maps.rs): mapping tables · Field translation and schema mapping definitions. · `src/normalizer/field_maps.rs`
- [Mapper](https://github.com/karib0u/rustinel/blob/main/src/normalizer/mapper.rs): translator · Transforms raw events into normalized event models. · `src/normalizer/mapper.rs`
- [Alerts](https://github.com/karib0u/rustinel/blob/main/src/alerts.rs): output writer · Writes ECS NDJSON alerts and logs to disk. · `src/alerts.rs`
- [Response](https://github.com/karib0u/rustinel/blob/main/src/response/mod.rs): active response · Optional process termination on critical detections. · `src/response/mod.rs`

### Detection

Rule engines and matching modalities.

- [Sigma Engine](https://github.com/karib0u/rustinel/blob/main/src/engine/mod.rs): behavioral detection · Sigma rule evaluation over normalized telemetry. · `src/engine/mod.rs`
- [Handler](https://github.com/karib0u/rustinel/blob/main/src/engine/handler.rs): match flow · Event handling and detection dispatch logic. · `src/engine/handler.rs`
- [YARA Scanner](https://github.com/karib0u/rustinel/blob/main/src/scanner/mod.rs): file scanning · Background file scanning worker for YARA rules. · `src/scanner/mod.rs`
- [IOC Match](https://github.com/karib0u/rustinel/blob/main/src/ioc/mod.rs): atomic matching · Hash, IP, domain, CIDR, and path-regex matching. · `src/ioc/mod.rs`

### Support

Shared state, models, and utilities.

- [State](https://github.com/karib0u/rustinel/blob/main/src/state/mod.rs): cache/correlation · Process correlation, DNS cache, SID lookup, and aggregation state. · `src/state/mod.rs`
- [Utils](https://github.com/karib0u/rustinel/blob/main/src/utils/mod.rs): helpers · Cross-cutting enrichment helpers for path, PE, process, user, and time. · `src/utils/mod.rs`
- [ECS Models](https://github.com/karib0u/rustinel/blob/main/src/models/mod.rs): output schema · ECS-facing alert and log structures. · `src/models/mod.rs`
- [ECS](https://github.com/karib0u/rustinel/blob/main/src/models/ecs.rs): payload schema · NDJSON alert/log record definitions. · `src/models/ecs.rs`

### Rules

On-disk rule packs and validation tooling.

- [Sigma Rules](https://github.com/karib0u/rustinel/blob/main/rules/sigma/example_whoami.yml): rule pack · On-disk Sigma detection rules. · `rules/sigma/example_whoami.yml`
- [YARA Rules](https://github.com/karib0u/rustinel/blob/main/rules/yara/example_test_string.yar): rule pack · On-disk YARA scanning rules. · `rules/yara/example_test_string.yar`
- [IOC Lists](https://github.com/karib0u/rustinel/blob/main/rules/ioc/hashes.txt): rule pack · On-disk IOC lists for hashes, domains, IPs, and regex paths. · `rules/ioc/hashes.txt`

## Connections

- Agent → Core Lib: uses · Main runtime is built on shared library logic.
- Rule Check → Sigma Rules: checks · Validates Sigma rule files.
- Rule Check → YARA Rules: checks · Validates YARA rule files.
- Core Lib → Config: loads · Configuration is initialized from shared startup logic.
- Core Lib → Collector: starts · Agent boots the ETW collector.
- Collector → Normalizer: emits · Raw telemetry is passed into normalization.
- Normalizer → Field Maps: uses · Schema translation relies on field maps.
- Normalizer → Mapper: applies · Event mapping is performed by the mapper.
- Normalizer → State: enriches with · Normalized events are correlated with shared state.
- Normalizer → Utils: calls · Normalization uses common helper utilities.
- Normalizer → Sigma Engine: feeds · Sigma evaluates normalized telemetry.
- Collector → IOC Match: inline checks · High-volume telemetry can be filtered or matched early.
- Core Lib → YARA Scanner: spawns · Process creation can trigger background YARA scanning.
- YARA Scanner → YARA Rules: loads · YARA worker consumes local rule files.
- Sigma Engine → Handler: dispatches · Matches are routed through the engine handler.
- Sigma Engine → Sigma Rules: evaluates · Sigma detection uses local Sigma rules.
- IOC Match → IOC Lists: loads · IOC matcher reads local hash/IP/domain/path lists.
- Handler → Alerts: writes · Detections are written as ECS NDJSON alerts.
- Handler → Response: may trigger · Critical detections can invoke active response.
- Alerts → ECS Models: formats as · Alert output is shaped by ECS models.
- ECS Models → ECS: defines · ECS payload structure is implemented in the ECS module.
