# alexbeltran/gobacnet architecture

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

- Interactive diagram: https://gitdiagram.com/alexbeltran/gobacnet
- Repository: https://github.com/alexbeltran/gobacnet

## Overview

##### Main Components
- Command Line Interface (CLI): The baccli package which contains the main application (baccli/main.go and subcommands like discover.go, readprop.go, etc.). This module is the user-entry point.
- Core BACnet Client Library: The core package responsible for performing BACnet operations. It includes various utility files like const.go, device.go, iam.go, and listen.go which manage device communication.
- Encoding Module: The “encoding” directory holds code for forming, parsing, and validating BACnet messages using files such as apdu.go, npdu.go, and various helper modules (encoder.go, decoder.go). This represents the protocol marshalling layer.
- Property Module: The “property” folder, responsible for managing property-related functions (e.g., print.go and properties.go) that support reading/writing properties.
- Transaction Management: Two distinct subcomponents exist:
- TSM (in the “tsm” directory) handles transaction state management, likely overseeing message transactions and response tracking.
- UTSM (in the “utsm” directory) seems to manage subscriptions or message dispatching for asynchronous processes.
- Data Types: The “types” package abstracts BACnet-related data types such as APDU, NPDU, and other protocol constants. It provides structured representations used by the rest of the library.

##### Interactions and Data Flow
- The CLI (baccli) component acts as the user-facing controller. When a command (e.g., “whoIs”, “readprop”) is issued, it triggers calls into the BACnet client layer.
- The BACnet client layer calls into the Encoding module to build and decode messages. For instance, command handlers use functions from encoding/encoder.go and encoding/decoder.go.
- Parsed and constructed messages rely on data structures defined within the Types package.
- Transaction management handled in TSM and UTSM ensures that message exchanges (request/response) are tracked and managed, with a flow of state updates.
- The Property module is used when dealing with property-specific operations (such as enumerating and formatting device properties) which may be invoked by both the CLI and the core client.

##### Architectural Patterns & Design Principles
- Modular Design: The project is structured with separation of concerns—command parsing, protocol encoding/decoding, data type handling, and transaction management are isolated.
- Clear Layering: The CLI interacts with the core logic, which in turn handles protocols in the encoding layer. Data formats and constants are managed in the Types package.
- Testability: Notice the presence of several *_test.go files which suggest unit testing is considered across the modules.

##### Technologies and Relevant Frameworks
- BACnet protocol standards are implied in the encoding and types modules.
- Integration testing and continuous integration are suggested by the .travis.yml file.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Command Line Interface (CLI)"]:::cli
    B["Core BACnet Client Library"]:::core
    C["Encoding Module"]:::protocol
    D["Property Module"]:::core
    E["Transaction Management (TSM)"]:::transaction
    F["Transaction Management (UTSM)"]:::transaction
    G["Data Types"]:::protocol
    H(["BACnet Devices"]):::external

    %% Interactions
    A -->|"invoke_command"| B
    B -->|"build/parse_messages"| C
    B -->|"use_data_structures"| G
    B -->|"track_transaction"| E
    B -->|"async_notifications"| F
    A -->|"execute_property"| D
    B -->|"format_property"| D
    E --o|"state_update"| B
    F --o|"state_update"| B
    B -->|"communicates"| H
    H --o|"response"| B

    %% Click Events
    click A "https://github.com/alexbeltran/gobacnet/tree/master/baccli/"
    click B "https://github.com/alexbeltran/gobacnet/blob/master/const.go"
    click C "https://github.com/alexbeltran/gobacnet/tree/master/encoding/"
    click D "https://github.com/alexbeltran/gobacnet/tree/master/property/"
    click E "https://github.com/alexbeltran/gobacnet/tree/master/tsm/"
    click F "https://github.com/alexbeltran/gobacnet/tree/master/utsm/"
    click G "https://github.com/alexbeltran/gobacnet/tree/master/types/"

    %% Styles
    classDef cli fill:#a7d7f9,stroke:#1f77b4,stroke-width:2px;
    classDef core fill:#f9d6a2,stroke:#d0743c,stroke-width:2px;
    classDef protocol fill:#fceabb,stroke:#f8b500,stroke-width:2px;
    classDef transaction fill:#d5a6bd,stroke:#835c76,stroke-width:2px;
    classDef external fill:#b2d8b2,stroke:#5c8a5c,stroke-width:2px;
```
