# arnested/ldddns architecture

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

- Interactive diagram: https://gitdiagram.com/arnested/ldddns
- Repository: https://github.com/arnested/ldddns

## Overview

##### Main Components

a) Core Components:
- Docker Host System
- ldddns Service (Main Service)
- Docker Engine/API
- mDNS Broadcasting System
- DNS-SD Service Discovery

b) Integration Points:
- Container Monitoring System
- Hostname Management System
- Configuration Management

**┌─ Host System ──────────────────────────────────────┐**

- ┌─ ldddns Service ───────────────────────────┐    │

- ┌─ Container Monitor ─┐  ┌─ Hostname ─┐   │    │
- Manager   │   │    │
- ┘  └───────────┘   │    │

- ┌─ mDNS Broadcaster ─┐  ┌─ DNS-SD ─┐     │    │
- Service  │     │    │
- ┘  └─────────┘     │    │

- ┘    │

- ┌─ Docker Engine ─────────────────────────────┐   │

- ┌─ Container 1 ─┐   ┌─ Container 2 ─┐     │   │

- ┘   └───────────────┘     │   │

- ┘   │

- ┘

##### Key Interactions to Highlight

a) Configuration Flow:
- How the service reads configuration from systemd environment variables
- Hostname lookup sources (env vars, container names, labels)

b) Container Monitoring:
- Connection between ldddns and Docker Engine API
- Container event monitoring

c) DNS Broadcasting:
- How hostnames are broadcast via mDNS
- DNS-SD service discovery for exposed ports

##### Important Details

- Configuration options (LDDDNS_HOSTNAME_LOOKUP, LDDDNS_IGNORE_DOCKER_COMPOSE_ONEOFF)
- Hostname rewriting rules (.local TLD requirement)
- Service discovery limitations (one domain per service per container)
- Port mapping for DNS-SD

##### Implementation Notes

- Main service logic (main.go)
- Container management (container.go, internal/container/)
- Hostname handling (internal/hostname/)
- Logging system (internal/log/)

Remember to include:
- Systemd integration points
- Security boundaries
- Configuration file locations
- Update mechanism through APT

This system design should provide a clear understanding of how ldddns integrates with both Docker and the local network infrastructure while maintaining its primary purpose of providing convenient local DNS resolution for Docker containers.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Host["Host System"]
        subgraph Service["ldddns Service"]
            Main["Main Service"]:::service
            ContainerMon["Container Monitor"]:::monitor
            HostMgr["Hostname Manager"]:::manager
            DNSBroadcast["mDNS Broadcaster"]:::dns
            DNSSD["DNS-SD Service"]:::dns
            Logger["Logging System"]:::util
            
            Main --> ContainerMon
            Main --> HostMgr
            Main --> DNSBroadcast
            Main --> DNSSD
            Main --> Logger
            
            ContainerMon --> HostMgr
            HostMgr --> DNSBroadcast
            DNSBroadcast --> DNSSD
        end
        
        subgraph Docker["Docker Engine"]
            API["Docker API"]:::docker
            Container1["Container 1"]:::container
            Container2["Container 2"]:::container
            
            API --> Container1
            API --> Container2
        end
        
        subgraph Config["Configuration"]
            InstallScripts["Installation Scripts"]:::config
            SystemdConfig["Systemd Config"]:::config
        end
        
        ContainerMon --> API
        Main --> InstallScripts
        Main --> SystemdConfig
    end
    
    %% Click Events
    click Main "https://github.com/arnested/ldddns/blob/main/main.go"
    click ContainerMon "https://github.com/arnested/ldddns/blob/main/internal/container/container.go"
    click HostMgr "https://github.com/arnested/ldddns/blob/main/internal/hostname/hostname.go"
    click DNSBroadcast "https://github.com/arnested/ldddns/blob/main/dns.go"
    click DNSSD "https://github.com/arnested/ldddns/blob/main/entry_groups.go"
    click Logger "https://github.com/arnested/ldddns/blob/main/internal/log/log.go"
    click InstallScripts "https://github.com/arnested/ldddns/blob/main/install.sh"
    click SystemdConfig "https://github.com/arnested/ldddns/blob/main/systemd/ldddns.service"
    
    %% Styling
    classDef service fill:#3498db,stroke:#2980b9,color:white
    classDef monitor fill:#2ecc71,stroke:#27ae60,color:white
    classDef manager fill:#e74c3c,stroke:#c0392b,color:white
    classDef dns fill:#f1c40f,stroke:#f39c12,color:black
    classDef docker fill:#34495e,stroke:#2c3e50,color:white
    classDef container fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef config fill:#9b59b6,stroke:#8e44ad,color:white
    classDef util fill:#1abc9c,stroke:#16a085,color:white
```
