# ulbios/bacnet architecture

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

- Interactive diagram: https://gitdiagram.com/ulbios/bacnet
- Repository: https://github.com/ulbios/bacnet

## Overview

##### Project Identification and Purpose
- This is a BACnet protocol implementation written in pure Golang.
- Its purpose is to provide the encoding/decoding (marshalling/unmarshalling) and service implementations (such as ReadProperty, WriteProperty, WhoIs, etc.) needed to work with the BACnet protocol over IP.
- The project also includes a Command-Line Interface (CLI) in the “examples” directory to demonstrate and test its functionality, as well as integration tests using a C-based BACnet server (included as a submodule).

##### Analyzing the File Structure and Key Components
- Main directories:
- common/: Contains utility functions and error handling (e.g., error.go, utils.go) used across the project.
- plumbing/: Focuses on lower-level message processing. It includes modules for BVLC, NPDU, APDU, and related constants and interfaces needed for protocol marshalling/unmarshalling.
- objects/: Defines the BACnet objects and related data types (properties, tags, priorities, object identifiers, etc.) that represent the data elements defined by BACnet.
- services/: Implements the higher-level BACnet services (e.g., ReadProperty, WriteProperty, WhoIs, etc.) that utilize the functionality from plumbing and objects.
- examples/: Provides sample applications (client/server examples with CLI) that demonstrate how to invoke services and handle BACnet messages.
- bacnet-stack (submodule): Contains an external C-based BACnet server implementation for testing; represents the server-side reference for interoperability.
- traffcaps/: Holds network packet capture files (PCAPNG) to show example BACnet traffic and support validation/testing against WireShark’s dissector.
- Additional key files:
- encoding.go and parsing.go: Serve as the entry points for constructing new messages and decoding incoming BACnet messages.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "CLI Layer"
        CLI("CLI Examples/Demo Applications"):::cli
    end

    subgraph "Library Core"
        SER("BACnet Services"):::library
        OBJ("BACnet Objects"):::library
        PLUM("Plumbing: BACnet Marshaller/Parser"):::library
        EN("encoding.go"):::library
        PA("parsing.go"):::library
        COMM("Common Utilities"):::library
    end

    subgraph "External Components"
        EXT("External BACnet Server"):::external
        TRAF("Traffic Captures"):::external
    end

    CLI -->|"calls"| SER
    SER -->|"uses"| OBJ
    SER -->|"calls"| PLUM
    PLUM -->|"includes"| EN
    PLUM -->|"includes"| PA
    PLUM -->|"utilizes"| COMM
    CLI -->|"interfaces"| EXT
    CLI -->|"monitors"| TRAF

    classDef library fill:#a3d5d3,stroke:#333,stroke-width:2px;
    classDef cli fill:#f9e79f,stroke:#333,stroke-width:2px;
    classDef external fill:#f5b7b1,stroke:#333,stroke-width:2px;

    click CLI "https://github.com/ulbios/bacnet/tree/master/examples/"
    click SER "https://github.com/ulbios/bacnet/tree/master/services/"
    click OBJ "https://github.com/ulbios/bacnet/tree/master/objects/"
    click PLUM "https://github.com/ulbios/bacnet/tree/master/plumbing/"
    click EN "https://github.com/ulbios/bacnet/blob/master/encoding.go"
    click PA "https://github.com/ulbios/bacnet/blob/master/parsing.go"
    click COMM "https://github.com/ulbios/bacnet/tree/master/common/"
    click EXT "https://github.com/ulbios/bacnet/tree/master/bacnet-stack"
    click TRAF "https://github.com/ulbios/bacnet/tree/master/traffcaps/"
```
