# firnsy/barnyard2 architecture

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

- Interactive diagram: https://gitdiagram.com/firnsy/barnyard2
- Repository: https://github.com/firnsy/barnyard2

## Overview

##### Project type and purpose
- Barnyard2 is a C-based, command-line, plugin-driven interpreter for Snort unified2 binary log files.
- Its sole purpose is to decouple Snort’s high-throughput packet capture from the work of parsing, formatting, and exporting alerts.

##### File structure
- Top-level directories:
- src/                        ← core source code
– barnyard2.c, spooler.c, parser.c, decode.c, util.c, log.c, debug.c
– input-plugins/            ← unified2 reader
– output-plugins/           ← many alert sink plugins
– sfutil/                   ← shared Snort utilities
- schemas/                    ← SQL schema definitions for databases
- etc/                        ← default configuration templates
- doc/                        ← INSTALL and plugin-specific READMEs
- tools/                      ← ancillary scripts (e.g., odlaw)
- Build/config: autogen.sh, configure.ac, Makefile.am, rpm/
- Key architectural pattern: a single process with
plugin loader → input plugins → core parser/spooler → output plugins.

##### README for additional insights
- Barnyard2 runs in batch or continuous modes (with optional bookmarking).
- Controlled by configuration file with two directive types:
- input processors (currently only unified2)
- output plugins (database, CSV, syslog, Bro, Prelude, etc.)

##### Elements
CLI → Loader → Spooler → Parser → Dispatcher → Plugins → External

##### Detail checklist
- Don’t omit any plugin category – there are dozens in output-plugins/
- Use of sfutil library under src/sfutil
- That input and output plugins share the plugbase API
- Annotation about GNU Autotools build/config layer

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CLI Layer
    subgraph "CLI Layer"
        CLI["CLI Entrypoint & Configuration Loader"]:::core
        ConfigTemplate["Default Configuration Template"]:::file
    end

    %% Plugin Management
    subgraph "Plugin Management"
        PluginManager["Plugin Manager / Loader"]:::core
    end

    %% Input Plugins
    subgraph "Input Plugins" 
        SPI_UNIFIED2["spi_unified2"]:::plugin
    end

    %% Core Processing Engine
    subgraph "Core Processing Engine"
        Spooler["Spooler\n(batch vs continuous mode)"]:::core
        ParserDecoder["Parser & Decoder"]:::core
        EventDispatcher["Event Dispatcher"]:::core
        SFUtil["Shared Snort Utilities (sfutil/)"]:::library
    end

    %% Output Plugins
    subgraph "Output Plugins"
        SPO_COMMON["spo_common"]:::plugin
        SPO_DATABASE["spo_database"]:::plugin
        SPO_DB_CACHE["spo_database_cache"]:::plugin
        LOG_ASCII["spo_log_ascii"]:::plugin
        LOG_NULL["spo_log_null"]:::plugin
        LOG_TCPDUMP["spo_log_tcpdump"]:::plugin
        ALERT_CSV["spo_alert_csv"]:::plugin
        ALERT_CEF["spo_alert_cef"]:::plugin
        ALERT_BRO["spo_alert_bro"]:::plugin
        ALERT_SYSLOG["spo_alert_syslog"]:::plugin
        ALERT_FULL["spo_alert_full"]:::plugin
        ALERT_FAST["spo_alert_fast"]:::plugin
        ALERT_FWSAM["spo_alert_fwsam"]:::plugin
        ALERT_ARUBA["spo_alert_arubaaction"]:::plugin
        ALERT_PRELUDE["spo_alert_prelude"]:::plugin
        ALERT_UNIXSOCK["spo_alert_unixsock"]:::plugin
        ALERT_SF_SOCKET["spo_alert_sf_socket"]:::plugin
        ALERT_TEST["spo_alert_test"]:::plugin
        ECHIDNA["spo_echidna"]:::plugin
        SQUIL["spo_sguil"]:::plugin
    end

    %% External Systems
    subgraph "External Systems"
        Filesystem["Filesystem\n(unified2 spool, archive, waldo)"]:::file
        WaldoFile["waldo bookmark file"]:::file
        RDBMS["RDBMS\n(MySQL, PostgreSQL, Oracle, MSSQL, DB2)"]:::database
        SyslogDaemon["Syslog Daemon / UNIX Socket"]:::network
        Monitoring["Monitoring/Forensics Tools\n(Sguil, Prelude)"]:::network
        Schemas["SQL Schemas"]:::file
    end

    %% Build & Docs
    subgraph "Build & Configuration"
        Autotools["GNU Autotools\n(autogen.sh, configure.ac, Makefile.am)"]:::infra
    end
    subgraph "Documentation"
        DOCS["Documentation & Plugin READMEs"]:::infra
    end
    subgraph "Ancillary Tools"
        Tools["tools/ (e.g., odlaw)"]:::infra
    end

    %% Connections
    CLI -->|loads| ConfigTemplate
    CLI -->|invokes| PluginManager
    PluginManager -->|loads| SPI_UNIFIED2
    PluginManager -->|loads| SPO_COMMON
    PluginManager -->|loads| SPO_DATABASE
    PluginManager -->|loads| SPO_DB_CACHE
    PluginManager -->|loads| LOG_ASCII
    PluginManager -->|loads| LOG_NULL
    PluginManager -->|loads| LOG_TCPDUMP
    PluginManager -->|loads| ALERT_CSV
    PluginManager -->|loads| ALERT_CEF
    PluginManager -->|loads| ALERT_BRO
    PluginManager -->|loads| ALERT_SYSLOG
    PluginManager -->|loads| ALERT_FULL
    PluginManager -->|loads| ALERT_FAST
    PluginManager -->|loads| ALERT_FWSAM
    PluginManager -->|loads| ALERT_ARUBA
    PluginManager -->|loads| ALERT_PRELUDE
    PluginManager -->|loads| ALERT_UNIXSOCK
    PluginManager -->|loads| ALERT_SF_SOCKET
    PluginManager -->|loads| ALERT_TEST
    PluginManager -->|loads| ECHIDNA
    PluginManager -->|loads| SQUIL

    Spooler -->|polls| Filesystem
    Spooler -->|reads/writes| WaldoFile
    Spooler -->|passes files to| SPI_UNIFIED2
    SPI_UNIFIED2 -->|decodes| ParserDecoder
    ParserDecoder -->|produces events| EventDispatcher
    EventDispatcher -->|dispatches to| SPO_COMMON
    EventDispatcher -->|dispatches to| SPO_DATABASE
    EventDispatcher -->|dispatches to| SPO_DB_CACHE
    EventDispatcher -->|dispatches to| LOG_ASCII
    EventDispatcher -->|dispatches to| LOG_NULL
    EventDispatcher -->|dispatches to| LOG_TCPDUMP
    EventDispatcher -->|dispatches to| ALERT_CSV
    EventDispatcher -->|dispatches to| ALERT_CEF
    EventDispatcher -->|dispatches to| ALERT_BRO
    EventDispatcher -->|dispatches to| ALERT_SYSLOG
    EventDispatcher -->|dispatches to| ALERT_FULL
    EventDispatcher -->|dispatches to| ALERT_FAST
    EventDispatcher -->|dispatches to| ALERT_FWSAM
    EventDispatcher -->|dispatches to| ALERT_ARUBA
    EventDispatcher -->|dispatches to| ALERT_PRELUDE
    EventDispatcher -->|dispatches to| ALERT_UNIXSOCK
    EventDispatcher -->|dispatches to| ALERT_SF_SOCKET
    EventDispatcher -->|dispatches to| ALERT_TEST
    EventDispatcher -->|dispatches to| ECHIDNA
    EventDispatcher -->|dispatches to| SQUIL

    SPO_DATABASE -->|writes| RDBMS
    SPO_DB_CACHE -->|writes| RDBMS
    LOG_ASCII -->|writes| Filesystem
    LOG_NULL -->|no-op| Filesystem
    LOG_TCPDUMP -->|writes| Filesystem
    ALERT_SYSLOG -->|sends| SyslogDaemon
    ALERT_UNIXSOCK -->|sends| SyslogDaemon
    ALERT_SF_SOCKET -->|sends| SyslogDaemon
    ALERT_PRELUDE -->|integrates| Monitoring
    SQUIL -->|integrates| Monitoring

    SPO_COMMON --> SFUtil
    SPI_UNIFIED2 --> SFUtil
    ParserDecoder --> SFUtil

    CLI --> Autotools
    PluginManager --> Schemas
    DOCS --> Autotools
    Tools --> Spooler

    %% Click Events
    click CLI "https://github.com/firnsy/barnyard2/blob/master/src/barnyard2.c"
    click ConfigTemplate "https://github.com/firnsy/barnyard2/blob/master/etc/barnyard2.conf"
    click PluginManager "https://github.com/firnsy/barnyard2/blob/master/src/plugbase.c"
    click SPI_UNIFIED2 "https://github.com/firnsy/barnyard2/blob/master/src/input-plugins/spi_unified2.c"
    click Spooler "https://github.com/firnsy/barnyard2/blob/master/src/spooler.c"
    click ParserDecoder "https://github.com/firnsy/barnyard2/blob/master/src/parser.c"
    click SFUtil "https://github.com/firnsy/barnyard2/tree/master/src/sfutil/"
    click SPO_COMMON "https://github.com/firnsy/barnyard2/blob/master/src/output-plugins/spo_common.c"
    click SPO_DATABASE "https://github.com/firnsy/barnyard2/blob/master/src/output-plugins/spo_database.c"
    click SPO_DB_CACHE "https://github.com/firnsy/barnyard2/blob/master/src/output-plugins/spo_database_cache.c"
    click LOG_ASCII "https://github.com/firnsy/barnyard2/blob/master/src/output-plugins/spo_log_ascii.c"
    click LOG_NULL "https://github.com/firnsy/barnyard2/blob/master/src/output-plugins/spo_log_null.c"
    click LOG_TCPDUMP "https://github.com/firnsy/barnyard2/blob/master/src/output-plugins/spo_log_tcpdump.c"
    click ALERT_CSV "https://github.com/firnsy/barnyard2/blob/master/src/output-plugins/spo_alert_csv.c"
    click ALERT_CEF "https://github.com/firnsy/barnyard2/blob/master/src/output-plugins/spo_alert_cef.c"
    click ALERT_BRO "https://github.com/firnsy/barnyard2/blob/master/src/output-plugins/spo_alert_bro.c"
    click ALERT_SYSLOG "https://github.com/firnsy/barnyard2/blob/master/src/output-plugins/spo_alert_syslog.c"
    click ALERT_FULL "https://github.com/firnsy/barnyard2/blob/master/src/output-plugins/spo_alert_full.c"
    click ALERT_FAST "https://github.com/firnsy/barnyard2/blob/master/src/output-plugins/spo_alert_fast.c"
    click ALERT_FWSAM "https://github.com/firnsy/barnyard2/blob/master/src/output-plugins/spo_alert_fwsam.c"
    click ALERT_ARUBA "https://github.com/firnsy/barnyard2/blob/master/src/output-plugins/spo_alert_arubaaction.c"
    click ALERT_PRELUDE "https://github.com/firnsy/barnyard2/blob/master/src/output-plugins/spo_alert_prelude.c"
    click ALERT_UNIXSOCK "https://github.com/firnsy/barnyard2/blob/master/src/output-plugins/spo_alert_unixsock.c"
    click ALERT_SF_SOCKET "https://github.com/firnsy/barnyard2/blob/master/src/output-plugins/spo_alert_sf_socket.c"
    click ALERT_TEST "https://github.com/firnsy/barnyard2/blob/master/src/output-plugins/spo_alert_test.c"
    click ECHIDNA "https://github.com/firnsy/barnyard2/blob/master/src/output-plugins/spo_echidna.c"
    click SQUIL "https://github.com/firnsy/barnyard2/blob/master/src/output-plugins/spo_sguil.c"
    click Schemas "https://github.com/firnsy/barnyard2/tree/master/schemas/"
    click Autotools "https://github.com/firnsy/barnyard2/blob/master/autogen.sh"
    click DOCS "https://github.com/firnsy/barnyard2/tree/master/doc/"
    click Tools "https://github.com/firnsy/barnyard2/tree/master/tools/odlaw"

    %% Styles
    classDef core fill:#f9f,stroke:#333,stroke-width:2px;
    classDef plugin fill:#afa,stroke:#333,stroke-width:2px;
    classDef external fill:#faa,stroke:#333,stroke-width:2px;
    classDef database fill:#ccf,stroke:#333,stroke-width:2px;
    classDef file fill:#efe,stroke:#333,stroke-width:2px;
    classDef network fill:#eef,stroke:#333,stroke-width:2px;
    classDef library fill:#ffc,stroke:#333,stroke-width:2px;
    classDef infra fill:#ddd,stroke:#333,stroke-width:2px;
```
