# evilsocket/opensnitch architecture

> Architecture diagram of the GitHub repository evilsocket/opensnitch, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/evilsocket/opensnitch
- Repository: https://github.com/evilsocket/opensnitch

## Overview

##### Main Components Identification

The system consists of three major components that should be prominently featured:

a) Daemon (Core Component):
- Subcomponents:
- Firewall Engine (nftables/iptables)
- Process Monitor (eBPF/audit)
- DNS Monitor
- Connection Manager
- Rules Engine

b) UI Component:
- Connection to daemon via gRPC
- Features:
- Statistics Display
- Rules Editor
- Firewall Configuration
- Multi-node Management

c) eBPF Programs:
- At the bottom
- Connection to kernel space
- Monitoring capabilities

##### Interaction Flows

- Network traffic flow through the firewall
- Communication between UI and daemon (gRPC)
- eBPF programs interaction with kernel
- Process monitoring flow
- Rules enforcement path

##### Component Details

For each major component, include:

a) Daemon:
- Core Engine
- * Connection Handling
- * Rule Processing
- * Event Logging
- Firewall Backend
- * NFTables/IPTables Integration
- * Rule Management
- Monitoring Systems
- * Process Monitor
- * Network Monitor
- * DNS Monitor

b) UI:
- User Interface
- * Interactive Prompts
- * Statistics
- * Rule Management
- * System Configuration
- Plugin System
- * Virus Total Integration
- * Custom Extensions

c) eBPF Programs:
- Kernel Probes
- * Process Monitoring
- * Network Tracking
- * DNS Monitoring

##### External Interactions

Connections to:
- System Firewall
- Network Stack
- Logging Systems
- External Services (optional)

##### Technical Details

- Protocols Used (gRPC, netlink, etc.)
- Data Flow Types
- Component Types
- Security Boundaries

##### Architectural Patterns

Following patterns:
- Client-Server Architecture (UI-Daemon)
- Event-Driven System
- Plugin Architecture
- Multi-node Support

This architecture should emphasize OpenSnitch's role as a security tool while showing its extensibility and monitoring capabilities.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph UI["User Interface Layer"]
        direction TB
        Stats["Statistics Display"]
        RulesEd["Rules Editor"]
        FWConf["Firewall Configuration"]
        Prompt["Prompt Dialog"]
        Plugin["Plugin System"]
        MultiNode["Multi-node Management"]
    end

    subgraph Daemon["Daemon Layer"]
        direction TB
        Core["Daemon Core"]
        
        subgraph FW["Firewall Components"]
            direction TB
            NFT["NFTables"]
            IPT["IPTables"]
        end
        
        subgraph Monitors["Monitoring Systems"]
            direction TB
            ProcMon["Process Monitor"]
            DNSMon["DNS Monitor"]
            ConnMan["Connection Manager"]
        end
        
        RulesEngine["Rules Engine"]
    end

    subgraph eBPF["eBPF Layer"]
        direction TB
        MaineBPF["Main eBPF"]
        DNSeBPF["DNS eBPF"]
        ProceBPF["Process eBPF"]
    end

    %% Connections
    UI --> |gRPC| Core
    Core --> FW
    Core --> Monitors
    Core --> RulesEngine
    Monitors --> eBPF
    eBPF --> |Kernel Space| System((System Kernel))

    %% Click Events
    click Core "https://github.com/evilsocket/opensnitch/blob/master/daemon/core/core.go"
    click NFT "https://github.com/evilsocket/opensnitch/tree/master/daemon/firewall/nftables/"
    click IPT "https://github.com/evilsocket/opensnitch/tree/master/daemon/firewall/iptables/"
    click ProcMon "https://github.com/evilsocket/opensnitch/tree/master/daemon/procmon/"
    click DNSMon "https://github.com/evilsocket/opensnitch/tree/master/daemon/dns/"
    click ConnMan "https://github.com/evilsocket/opensnitch/tree/master/daemon/conman/"
    click RulesEngine "https://github.com/evilsocket/opensnitch/tree/master/daemon/rule/"
    click Stats "https://github.com/evilsocket/opensnitch/blob/master/ui/opensnitch/dialogs/stats.py"
    click RulesEd "https://github.com/evilsocket/opensnitch/blob/master/ui/opensnitch/dialogs/ruleseditor.py"
    click FWConf "https://github.com/evilsocket/opensnitch/blob/master/ui/opensnitch/dialogs/firewall.py"
    click Prompt "https://github.com/evilsocket/opensnitch/tree/master/ui/opensnitch/dialogs/prompt/"
    click MaineBPF "https://github.com/evilsocket/opensnitch/blob/master/ebpf_prog/opensnitch.c"
    click DNSeBPF "https://github.com/evilsocket/opensnitch/blob/master/ebpf_prog/opensnitch-dns.c"
    click ProceBPF "https://github.com/evilsocket/opensnitch/blob/master/ebpf_prog/opensnitch-procs.c"
    click MultiNode "https://github.com/evilsocket/opensnitch/tree/master/daemon/tasks/nodemonitor/"
    click Plugin "https://github.com/evilsocket/opensnitch/tree/master/ui/opensnitch/plugins/"

    %% Styling
    classDef ui fill:#f96,stroke:#333
    classDef daemon fill:#58a,stroke:#333
    classDef monitor fill:#7b4,stroke:#333
    classDef ebpf fill:#b66,stroke:#333
    classDef system fill:#999,stroke:#333

    class Stats,RulesEd,FWConf,Prompt,Plugin,MultiNode ui
    class Core,NFT,IPT,RulesEngine daemon
    class ProcMon,DNSMon,ConnMan monitor
    class MaineBPF,DNSeBPF,ProceBPF ebpf
    class System system
```
