# anirudh-os/rustguard architecture

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

- Interactive diagram: https://gitdiagram.com/anirudh-os/rustguard
- Repository: https://github.com/anirudh-os/rustguard

## Overview

##### Project type and purpose
- This is a Rust-based network firewall tool (a CLI/daemon application).
- Its purpose is to read packet data (from a network interface or injected source), match each packet against a set of rules (in rules.json), and then allow or block traffic.

##### File structure
- Cargo.toml / Cargo.lock: Rust project manifest and dependency lockfile.
- src/main.rs: the binary entrypoint (initializes logging, loads rules, starts packet capture loop).
- src/firewall/: the core library module
- mod.rs – declares the firewall submodules
- firewall.rs – the “engine” that applies rules to packets
- packet.rs – the data model for captured packets
- rule.rs – the data model for a single firewall rule
- src/rules.json: the external rules store, loaded at startup.

##### README
- (Empty in this case – infer behavior from code and file names.)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation / Control Layer
    subgraph "Presentation / Control"
        Launcher["CLI / Daemon Launcher\n(main.rs)"]:::core
        Manifest["Cargo.toml"]:::config
        Lockfile["Cargo.lock"]:::config
    end

    %% Configuration
    subgraph "Configuration"
        RuleStore["Rule Store\n(rules.json)"]:::external
    end

    %% Business Logic Layer
    subgraph "Business Logic"
        Declaration["Module Declaration\n(mod.rs)"]:::core
        Engine["Firewall Engine\n(firewall.rs)"]:::core
    end

    %% Domain Models
    subgraph "Domain Models"
        Packet["Packet Model\n(packet.rs)"]:::core
        Rule["Rule Model\n(rule.rs)"]:::core
    end

    %% Runtime Components
    subgraph "Runtime Components"
        Source["Network Interface / pcap"]:::external
        Dispatcher["Action Dispatcher\n(accept/drop/log)"]:::runtime
        Logger["Logger / Logging"]:::runtime
    end

    %% Data Flows and Interactions
    Launcher -->|"reads rules json\n(Vec<Rule>)"| RuleStore
    RuleStore -->|"raw JSON"| Rule
    Launcher -->|"initializes Engine\n(with Vec<Rule>)"| Engine
    Source -->|"RawPacket"| Engine
    Engine -->|"constructs"| Packet
    Engine -->|"evaluates against"| Rule
    Engine -->|"invokes"| Dispatcher
    Dispatcher -->|"logs result"| Logger

    %% Click Events
    click Launcher "https://github.com/anirudh-os/rustguard/blob/main/src/main.rs"
    click Manifest "https://github.com/anirudh-os/rustguard/blob/main/Cargo.toml"
    click Lockfile "https://github.com/anirudh-os/rustguard/blob/main/Cargo.lock"
    click Declaration "https://github.com/anirudh-os/rustguard/blob/main/src/firewall/mod.rs"
    click Engine "https://github.com/anirudh-os/rustguard/blob/main/src/firewall/firewall.rs"
    click Packet "https://github.com/anirudh-os/rustguard/blob/main/src/firewall/packet.rs"
    click Rule "https://github.com/anirudh-os/rustguard/blob/main/src/firewall/rule.rs"
    click RuleStore "https://github.com/anirudh-os/rustguard/blob/main/src/rules.json"

    %% Styles
    classDef core fill:#AEDFF7,stroke:#036,stroke-width:2px
    classDef config fill:#D5F5E8,stroke:#0A3,stroke-width:2px
    classDef external fill:#FDEBD0,stroke:#E67E22,stroke-width:2px
    classDef runtime fill:#FADBD8,stroke:#C0392B,stroke-width:2px
```
