# grishy/go-avahi-cname architecture

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

- Interactive diagram: https://gitdiagram.com/grishy/go-avahi-cname
- Repository: https://github.com/grishy/go-avahi-cname

## Overview

##### Project type and purpose
- go-avahi-cname is a small Go-based command-line tool (also packaged as a container) that communicates with the local Avahi daemon over DBus to publish or reply to mDNS CNAME records on the LAN.
- It has two modes:
- Subdomain reply mode (“subdomain”): listens for any `*.hostname.local` queries and issues CNAME replies via Avahi.
- Interval publishing mode (“cname”): periodically sends out specified CNAME records for the host.

##### File structure
- Top-level:
- main.go – entry point
- cmd/ – two subcommands: cname.go, subdomain.go
- avahi/publisher.go – the DBus client and publishing logic
- Dockerfile, .devcontainer/ – container and dev environment setup
- go.mod/sum, CI & release workflows
- Patterns:
- CLI-driven single binary
- Separation between command parsing (cmd/) and Avahi/DBus interaction (avahi/)
- Optional container runtime (Dockerfile)

##### README for additional insights
- Describes data flows: CLI → DBus → Avahi daemon → mDNS network
- Deployment options: standalone binary under systemd or container with host network and DBus socket mount

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Go Application"
        direction TB
        GoApp["Go CLI Application"]:::goapp
        SubdomainCmd["Subdomain Reply Mode"]:::goapp
        IntervalCmd["Interval Publishing Mode"]:::goapp
        Publisher["Avahi/DBus Client & Logic"]:::ipc
        GoApp -->|"invokes"| SubdomainCmd
        GoApp -->|"invokes"| IntervalCmd
        SubdomainCmd -->|"handle query"| Publisher
        IntervalCmd -->|"Periodic timer"| Publisher
    end

    Publisher -->|"DBus method calls"| DBusSocket["DBus Socket"]:::ipc
    DBusSocket -->|"IPC"| AvahiDaemon["Avahi Daemon"]:::service
    AvahiDaemon -->|"mDNS packets"| mDNSNetwork["LAN mDNS Network"]:::network
    AvahiDaemon -->|"Query event"| SubdomainCmd
    Publisher -->|"Publish CNAME"| AvahiDaemon

    subgraph "Deployment Options" 
        direction TB
        DockerContainer["Docker Container"]:::deployment
        SystemdService["systemd Service"]:::deployment
        DockerContainer -->|"mounts socket\nhost network"| DBusSocket
        SystemdService -->|"launches"| GoApp
    end

    subgraph "Support Files"
        direction TB
        GoModules["go.mod / go.sum"]
        CI["CI Workflows"]
        Goreleaser[".goreleaser.yaml"]
        Docs["docs/"]
        DevContainer[".devcontainer"]
    end

    click GoApp "https://github.com/grishy/go-avahi-cname/blob/main/main.go"
    click SubdomainCmd "https://github.com/grishy/go-avahi-cname/blob/main/cmd/subdomain.go"
    click IntervalCmd "https://github.com/grishy/go-avahi-cname/blob/main/cmd/cname.go"
    click Publisher "https://github.com/grishy/go-avahi-cname/blob/main/avahi/publisher.go"
    click DockerContainer "https://github.com/grishy/go-avahi-cname/tree/main/Dockerfile"
    click DevContainer "https://github.com/grishy/go-avahi-cname/blob/main/.devcontainer/devcontainer.json"
    click GoModules "https://github.com/grishy/go-avahi-cname/blob/main/go.mod"
    click CI "https://github.com/grishy/go-avahi-cname/blob/main/.github/workflows/commit.yml"
    click CI "https://github.com/grishy/go-avahi-cname/blob/main/.github/workflows/release.yml"
    click Goreleaser "https://github.com/grishy/go-avahi-cname/blob/main/.goreleaser.yaml"
    click Docs "https://github.com/grishy/go-avahi-cname/tree/main/docs/"

    classDef goapp fill:#9f6,stroke:#333,stroke-width:1px
    classDef ipc fill:#ccc,stroke:#333,stroke-width:1px
    classDef service fill:#6cf,stroke:#333,stroke-width:1px
    classDef network fill:#fc6,stroke:#333,stroke-width:1px
    classDef deployment stroke-dasharray: 5 5,stroke:#333,fill:none
```
