# automatanexus/nexusshield architecture

> Architecture diagram of the GitHub repository automatanexus/nexusshield, 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/automatanexus/nexusshield
- Repository: https://github.com/automatanexus/nexusshield

## Overview

1. **What this repo is**
   NexusShield is a single Rust workspace/crate that combines two runtime roles in one process: a **security gateway** and an **endpoint protection engine**. The main binary (`src/bin/main.rs`) hosts the HTTP server, reverse proxy, CLI, and optional endpoint monitors. A second binary (`src/bin/daily_report.rs`) is a reporting utility.

2. **Top-level runtime shape**
   The primary executable is an **async Rust server** built on `tokio` + `axum`/`hyper`. It can run in:
   - **standalone mode**: serves security endpoints and dashboard only
   - **proxy mode**: inspects inbound requests and forwards clean traffic to an upstream app
   - **endpoint mode**: enables local host monitoring and malware detection

3. **Gateway request path**
   Incoming HTTP traffic flows through a layered defense pipeline before any upstream forwarding. The key request-side modules are:
   - `sql_firewall` for SQL AST inspection
   - `ssrf_guard` for IP/DNS-based destination checks
   - `rate_governor` for adaptive throttling/banning
   - `fingerprint` for behavioral fingerprinting
   - `email_guard`, `sanitizer`, `quarantine`, and `credential_vault` for specific payload/data protections  
   These signals are combined by `threat_score`, which drives allow/warn/block decisions.

4. **Central trust and audit boundary**
   `audit_chain` is the core cross-cutting subsystem. It records security events in a **SHA-256 hash-chained log**, so gateway events, endpoint detections, quarantine actions, and reportable incidents all share the same tamper-evident history. This audit stream is also the source for metrics, SSE, SIEM export, journaling, and compliance reporting.

5. **Endpoint engine orchestration**
   `src/endpoint/mod.rs` is the coordinator for the endpoint side. It defines the scanner abstractions, result types, severity levels, and the orchestration path that fans out to multiple detectors. The engine can perform:
   - **real-time monitoring**
   - **on-demand file/directory scans**
   - **continuous background polling**
   - **quarantine and alert dispatch**

6. **Endpoint input sources**
   Endpoint detection is driven by several OS-level feeds:
   - `watcher` uses filesystem notifications for create/write events
   - `process_monitor` polls `/proc` for suspicious process behavior
   - `network_monitor` parses `/proc/net/tcp`
   - `memory_scanner` inspects `/proc/[pid]/maps`
   - `usb_monitor` watches `/sys/block` and mount state
   - `fim` snapshots and rechecks critical system paths
   - `dns_filter` acts as a local UDP DNS proxy and enforcement point

7. **Detection engines**
   The actual malware/threat analysis is split across specialized scanners:
   - `signatures` for SHA-256 exact matches from NDJSON databases
   - `heuristics` for entropy, file-type mismatch, ELF/script anomalies, and embedded payloads
   - `yara_engine` for YARA-like pattern matching without libyara
   - `allowlist` for developer-tool awareness and false-positive suppression
   - `threat_intel` for IOC lookups
   - `rootkit_detector`, `container_scanner`, and `supply_chain` for host, image, and dependency risk  
   These scanners all feed back into the same endpoint result stream.

8. **Quarantine and containment**
   When a threat is confirmed, `file_quarantine` moves it into an encrypted local vault and strips access permissions. That quarantine state is persistent and includes chain-of-custody metadata. On the gateway side, `quarantine` is also used for risky imported data such as CSV/JSON payloads.

9. **Local state and persistence**
   The repo is designed to run mostly from **local filesystem state**, not an external database. Important stateful locations include:
   - `/etc/nexus-shield/config.toml` for configuration
   - `~/.nexus-shield/signatures.ndjson` for custom signatures
   - `~/.nexus-shield/threat-intel/` for IOC files
   - `~/.nexus-shield/quarantine/` for isolated artifacts
   - persisted baselines for FIM/rootkit-related checks  
   `credential_vault` adds encrypted local secret storage using AES-GCM.

10. **Telemetry and external export**
   Multiple consumers read from the shared security event stream:
   - `metrics` exposes Prometheus counters at `/metrics`
   - `sse_events` pushes live events to `/events`
   - `journal` writes structured events to the systemd journal
   - `siem_export` forwards to Syslog, Elasticsearch, Splunk HEC, or generic webhooks
   - `webhook`, `ferrum_integration`, and `nexuspulse_integration` push alerts to external notification systems

11. **Operator-facing surfaces**
   The server also exposes read/report endpoints such as `/health`, `/status`, `/audit`, `/stats`, `/report`, and endpoint-specific `/endpoint/*` routes when monitoring is enabled. `widget/index.html` is the embedded dashboard UI, and `compliance_report` generates the HTML report used for audit/compliance views.

12. **Control plane and deployment behavior**
   `config.rs` is the central configuration boundary, with CLI flags overriding TOML defaults. `auth.rs` protects sensitive endpoints with bearer tokens, while TLS is optional via rustls cert/key configuration. `signature_updater` periodically refreshes malware definitions from a remote feed, making signature data an operational input rather than a code-only asset.

13. **Important architectural boundary**
   The dominant boundary in this repository is between **network gateway enforcement** and **host endpoint monitoring**, but both converge on the same internal event model: detections are scored, recorded in the audit chain, optionally quarantined, then exported to dashboards, metrics, logs, and external alerting systems. That shared event spine is what makes the system feel like one product rather than two separate tools.

Main entry points: [`src/endpoint/mod.rs`](https://github.com/automatanexus/nexusshield/blob/main/src/endpoint/mod.rs) (Endpoint engine), [`src/bin/main.rs`](https://github.com/automatanexus/nexusshield/blob/main/src/bin/main.rs) (Main server), [`src/audit_chain.rs`](https://github.com/automatanexus/nexusshield/blob/main/src/audit_chain.rs) (Audit chain), [`src/threat_score.rs`](https://github.com/automatanexus/nexusshield/blob/main/src/threat_score.rs) (Threat score)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Control plane"]
  node_main["Main server<br/>async runtime<br/>[main.rs]"]
  node_daily_report_bin["Daily report<br/>reporting bin<br/>[daily_report.rs]"]
  node_config["Config<br/>settings boundary<br/>[config.rs]"]
  node_auth{{"Auth<br/>access control<br/>[auth.rs]"}}
  node_credential_vault[("Vault<br/>secret store")]
  node_signature_updater["Signature updater<br/>feed sync"]
end

subgraph group_gateway["Gateway"]
  node_gateway_core["Gateway<br/>request pipeline"]
  node_request_guards["Request guards<br/>filters"]
  node_threat_score(("Threat score<br/>decision engine<br/>[threat_score.rs]"))
  node_quarantine[("Quarantine<br/>containment<br/>[quarantine.rs]")]
end

subgraph group_endpoint["Endpoint"]
  node_endpoint_core["Endpoint engine<br/>orchestrator<br/>[mod.rs]"]
  node_input_feeds["Host feeds<br/>os monitors"]
  node_detectors["Detectors<br/>analysis engines"]
  node_host_risk["Host risk<br/>specialized scanners"]
  node_file_quarantine[("File quarantine<br/>artifact vault<br/>[file_quarantine.rs]")]
end

subgraph group_telemetry["Telemetry"]
  node_audit_chain[("Audit chain<br/>hash log<br/>[audit_chain.rs]")]
  node_telemetry_bus["Event bus<br/>security stream"]
  node_metrics["Metrics<br/>prometheus<br/>[metrics.rs]"]
  node_sse_events["SSE events<br/>live feed<br/>[sse_events.rs]"]
  node_journal["Journal<br/>system log<br/>[journal.rs]"]
  node_siem_export["SIEM export<br/>external export<br/>[siem_export.rs]"]
  node_compliance_report["Compliance report<br/>html report"]
  node_dashboard["Dashboard UI<br/>embedded ui<br/>[index.html]"]
end

node_config -->|"loads"| node_main
node_auth -->|"protects"| node_main
node_main -->|"runs"| node_gateway_core
node_main -->|"enables"| node_endpoint_core
node_main -->|"serves"| node_dashboard
node_gateway_core -->|"filters"| node_request_guards
node_request_guards -->|"scores"| node_threat_score
node_threat_score -->|"diverts"| node_quarantine
node_quarantine -->|"protects"| node_credential_vault
node_endpoint_core -->|"ingests"| node_input_feeds
node_endpoint_core -->|"dispatches"| node_detectors
node_endpoint_core -->|"dispatches"| node_host_risk
node_detectors -->|"contains"| node_file_quarantine
node_host_risk -->|"contains"| node_file_quarantine
node_signature_updater -->|"feeds"| node_detectors
node_endpoint_core -->|"records"| node_audit_chain
node_gateway_core -->|"records"| node_audit_chain
node_audit_chain -->|"publishes"| node_telemetry_bus
node_telemetry_bus -->|"exports"| node_metrics
node_telemetry_bus -->|"streams"| node_sse_events
node_telemetry_bus -->|"logs"| node_journal
node_telemetry_bus -->|"forwards"| node_siem_export
node_telemetry_bus -->|"summarizes"| node_compliance_report
node_telemetry_bus -->|"renders"| node_dashboard
node_daily_report_bin -->|"generates"| node_compliance_report

click node_main "https://github.com/automatanexus/nexusshield/blob/main/src/bin/main.rs"
click node_daily_report_bin "https://github.com/automatanexus/nexusshield/blob/main/src/bin/daily_report.rs"
click node_config "https://github.com/automatanexus/nexusshield/blob/main/src/config.rs"
click node_auth "https://github.com/automatanexus/nexusshield/blob/main/src/auth.rs"
click node_audit_chain "https://github.com/automatanexus/nexusshield/blob/main/src/audit_chain.rs"
click node_threat_score "https://github.com/automatanexus/nexusshield/blob/main/src/threat_score.rs"
click node_quarantine "https://github.com/automatanexus/nexusshield/blob/main/src/quarantine.rs"
click node_credential_vault "https://github.com/automatanexus/nexusshield/blob/main/src/credential_vault.rs"
click node_endpoint_core "https://github.com/automatanexus/nexusshield/blob/main/src/endpoint/mod.rs"
click node_file_quarantine "https://github.com/automatanexus/nexusshield/blob/main/src/endpoint/file_quarantine.rs"
click node_signature_updater "https://github.com/automatanexus/nexusshield/blob/main/src/signature_updater.rs"
click node_metrics "https://github.com/automatanexus/nexusshield/blob/main/src/metrics.rs"
click node_sse_events "https://github.com/automatanexus/nexusshield/blob/main/src/sse_events.rs"
click node_journal "https://github.com/automatanexus/nexusshield/blob/main/src/journal.rs"
click node_siem_export "https://github.com/automatanexus/nexusshield/blob/main/src/siem_export.rs"
click node_compliance_report "https://github.com/automatanexus/nexusshield/blob/main/src/compliance_report.rs"
click node_dashboard "https://github.com/automatanexus/nexusshield/blob/main/widget/index.html"

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_daily_report_bin,node_config,node_auth,node_credential_vault,node_signature_updater toneBlue
class node_gateway_core,node_request_guards,node_threat_score,node_quarantine toneAmber
class node_endpoint_core,node_input_feeds,node_detectors,node_host_risk,node_file_quarantine toneMint
class node_audit_chain,node_telemetry_bus,node_metrics,node_sse_events,node_journal,node_siem_export,node_compliance_report,node_dashboard toneRose
```

## Components

### Control plane

Configuration, auth, startup, and reporting entrypoints.

- [Main server](https://github.com/automatanexus/nexusshield/blob/main/src/bin/main.rs): async runtime · Primary Rust binary hosting HTTP server, proxy, CLI, and optional endpoint mode. · `src/bin/main.rs`
- [Daily report](https://github.com/automatanexus/nexusshield/blob/main/src/bin/daily_report.rs): reporting bin · Secondary binary for report generation. · `src/bin/daily_report.rs`
- [Config](https://github.com/automatanexus/nexusshield/blob/main/src/config.rs): settings boundary · Central TOML and CLI configuration boundary. · `src/config.rs`
- [Auth](https://github.com/automatanexus/nexusshield/blob/main/src/auth.rs): access control · Bearer-token protection for sensitive endpoints. · `src/auth.rs`
- [Vault](https://github.com/automatanexus/nexusshield/blob/main/src/credential_vault.rs): secret store · Encrypted local storage for secrets and protected data. · `src/credential_vault.rs`
- [Signature updater](https://github.com/automatanexus/nexusshield/blob/main/src/signature_updater.rs): feed sync · Periodic refresh of malware definitions from remote feeds. · `src/signature_updater.rs`

### Gateway

HTTP request inspection and forwarding enforcement path.

- **Gateway**: request pipeline · HTTP inspection and decision pipeline before any upstream forwarding.
- **Request guards**: filters · SQL, SSRF, rate, fingerprint, email, and sanitization checks.
- [Threat score](https://github.com/automatanexus/nexusshield/blob/main/src/threat_score.rs): decision engine · Combines guard signals into allow, warn, or block decisions. · `src/threat_score.rs`
- [Quarantine](https://github.com/automatanexus/nexusshield/blob/main/src/quarantine.rs): containment · Gateway-side isolation for risky imported data and payloads. · `src/quarantine.rs`

### Endpoint

Host monitoring, detection, and containment path.

- [Endpoint engine](https://github.com/automatanexus/nexusshield/blob/main/src/endpoint/mod.rs): orchestrator · Coordinates scanning, monitoring, and alert dispatch on the host. · `src/endpoint/mod.rs`
- **Host feeds**: os monitors · Filesystem, process, network, memory, USB, FIM, and DNS enforcement inputs.
- **Detectors**: analysis engines · Signatures, heuristics, YARA-like matching, allowlisting, and threat intel.
- **Host risk**: specialized scanners · Rootkit, container, and supply-chain checks for deeper host risk.
- [File quarantine](https://github.com/automatanexus/nexusshield/blob/main/src/endpoint/file_quarantine.rs): artifact vault · Encrypted quarantine for confirmed malicious artifacts with custody metadata. · `src/endpoint/file_quarantine.rs`

### Telemetry

Audit, metrics, logs, exports, and operator surfaces.

- [Audit chain](https://github.com/automatanexus/nexusshield/blob/main/src/audit_chain.rs): hash log · Tamper-evident SHA-256 event history shared by gateway, endpoint, and reporting flows. · `src/audit_chain.rs`
- **Event bus**: security stream · Shared event stream feeding metrics, SSE, journaling, export, and alerts.
- [Metrics](https://github.com/automatanexus/nexusshield/blob/main/src/metrics.rs): prometheus · Prometheus counters and operational stats. · `src/metrics.rs`
- [SSE events](https://github.com/automatanexus/nexusshield/blob/main/src/sse_events.rs): live feed · Server-sent event stream for live security updates. · `src/sse_events.rs`
- [Journal](https://github.com/automatanexus/nexusshield/blob/main/src/journal.rs): system log · Structured logging to the systemd journal. · `src/journal.rs`
- [SIEM export](https://github.com/automatanexus/nexusshield/blob/main/src/siem_export.rs): external export · Forwarding to syslog, Elasticsearch, Splunk HEC, and webhooks. · `src/siem_export.rs`
- [Compliance report](https://github.com/automatanexus/nexusshield/blob/main/src/compliance_report.rs): html report · HTML reporting used for audit and compliance views. · `src/compliance_report.rs`
- [Dashboard UI](https://github.com/automatanexus/nexusshield/blob/main/widget/index.html): embedded ui · Embedded operator dashboard served from widget/index.html. · `widget/index.html`

## Connections

- Config → Main server: loads · CLI flags override TOML defaults at startup.
- Auth → Main server: protects · Secures sensitive server endpoints.
- Main server → Gateway: runs · Hosts the primary HTTP gateway and proxy path.
- Main server → Endpoint engine: enables · Turns on endpoint monitoring when configured.
- Main server → Dashboard UI: serves · Exposes the embedded operator UI.
- Gateway → Request guards: filters · Applies layered request inspection before forwarding.
- Request guards → Threat score: scores · Individual guard signals feed the decision engine.
- Threat score → Quarantine: diverts · Risky payloads can be isolated instead of forwarded.
- Quarantine → Vault: protects · Sensitive quarantined material and secrets remain encrypted locally.
- Endpoint engine → Host feeds: ingests · Consumes host-level monitoring and polling inputs.
- Endpoint engine → Detectors: dispatches · Fans out scan results to core detectors.
- Endpoint engine → Host risk: dispatches · Runs deeper host, container, and supply-chain analysis.
- Detectors → File quarantine: contains · Confirmed threats are moved into encrypted quarantine.
- Host risk → File quarantine: contains · High-confidence detections are isolated.
- Signature updater → Detectors: feeds · Refreshes signature-based detection data.
- Endpoint engine → Audit chain: records · Endpoint detections and actions are written to the shared audit log.
- Gateway → Audit chain: records · Gateway decisions and incidents are written to the shared audit log.
- Audit chain → Event bus: publishes · The audit stream is the source for downstream telemetry consumers.
- Event bus → Metrics: exports · Feeds operational counters and health data.
- Event bus → SSE events: streams · Pushes live events to operators.
- Event bus → Journal: logs · Writes structured records to the systemd journal.
- Event bus → SIEM export: forwards · Sends events to external SIEM and alerting endpoints.
- Event bus → Compliance report: summarizes · Provides source data for audit and compliance reports.
- Event bus → Dashboard UI: renders · Supplies live status and audit views in the UI.
- Daily report → Compliance report: generates · Standalone reporting binary builds the report artifact.
