# middleware-labs/mw-agent architecture

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

- Interactive diagram: https://gitdiagram.com/middleware-labs/mw-agent
- Repository: https://github.com/middleware-labs/mw-agent

## Overview

##### Main Components

a. Agent Types (Primary Components):
- Host Agent (Linux/Windows/Darwin)
- Kubernetes Agent

b. Supporting Infrastructure:
- Configuration Management
- Metadata Processing
- Packaging Systems
- Deployment Mechanisms

**┌─ Host Environment ─────────┐    ┌─ Kubernetes Environment ─┐**
- ┌─ Host Agent ─────────┐ │    │  ┌─ Kube Agent ────────┐ │
- Linux              │ │    │  │ - DaemonSet/Pod     │ │
- Windows            │ │    │  │ - RBAC              │ │
- Darwin             │ │    │  │ - ConfigMaps        │ │
- ┬─┘ │    │  └──────────┬─────────┘ │
- ┬┘   │    └─────────────┬───────────┘

**┌─────────────────────┼─────┼───────────────────┘**
- OpenTelemetry      │     │
- Configuration ──────┘     │
- ┘

##### Detailed Component Breakdown

a. Host Agent Section:
- Platform-specific implementations (hostagent_darwin.go, hostagent_linux.go, hostagent_windows.go)
- Service management (systemd, Windows Service)
- Configuration handling

b. Kubernetes Agent Section:
- Kubernetes-specific components (RBAC, ConfigMaps, Secrets)
- Helm chart structure
- Monitoring paths

c. Packaging & Distribution:
- Package formats (DEB, RPM, MSI, PKG)
- Build pipeline connections
- Deployment workflows

##### Important Relationships

- Configuration flow from various sources (env vars, CLI flags, config files)
- Data collection paths
- Deployment workflows
- Integration points with OpenTelemetry

##### Technical Details

- Go-based implementation
- OpenTelemetry integration
- Platform-specific monitoring capabilities
- Configuration management
- Package management systems

##### Specific Implementation Notes

- The separation between host and Kubernetes agents
- Configuration management across platforms
- Package distribution mechanisms
- Monitoring and telemetry flows
- Security considerations (RBAC, certificates)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Agents
        HostAgent["Host Agent"]:::core
        KubeAgent["Kubernetes Agent"]:::core
        
        subgraph "Host Agent Implementations"
            Linux["Linux Implementation"]:::platform
            Windows["Windows Implementation"]:::platform
            Darwin["Darwin Implementation"]:::platform
            
            HostAgent --> Linux
            HostAgent --> Windows
            HostAgent --> Darwin
        end
        
        subgraph "Kubernetes Components"
            KubeDeploy["Deployments"]:::k8s
            RBAC["RBAC"]:::k8s
            ServiceAccounts["Service Accounts"]:::k8s
            
            KubeAgent --> KubeDeploy
            KubeAgent --> RBAC
            KubeAgent --> ServiceAccounts
        end
    end
    
    subgraph "Configuration Management"
        OtelConfig["OpenTelemetry Config"]:::config
        K8sConfig["Kubernetes Config"]:::config
        
        OtelConfig --> HostAgent
        OtelConfig --> KubeAgent
        K8sConfig --> KubeAgent
    end
    
    subgraph "Package Management"
        subgraph "Linux Packages"
            DEB["DEB Package"]:::package
            RPM["RPM Package"]:::package
        end
        
        subgraph "Other Packages"
            MSI["Windows MSI"]:::package
            PKG["Darwin PKG"]:::package
        end
        
        Linux --> DEB
        Linux --> RPM
        Windows --> MSI
        Darwin --> PKG
    end
    
    subgraph "Service Management"
        LinuxService["Systemd Service"]:::service
        DarwinService["Darwin Service"]:::service
        
        Linux --> LinuxService
        Darwin --> DarwinService
    end
    
    subgraph "Build & Deployment"
        Docker["Docker Builds"]:::build
        Helm["Helm Charts"]:::build
        
        Docker --> KubeAgent
        Helm --> KubeAgent
    end
    
    subgraph "Metadata Management"
        MetricsBase["Base Metrics"]:::metadata
        MetadataGen["Metadata Generator"]:::metadata
        
        MetricsBase --> MetadataGen
        MetadataGen --> HostAgent
        MetadataGen --> KubeAgent
    end
    
    %% Component Mappings
    click HostAgent "https://github.com/middleware-labs/mw-agent/blob/master/pkg/agent/hostagent.go"
    click Linux "https://github.com/middleware-labs/mw-agent/blob/master/pkg/agent/hostagent_linux.go"
    click Windows "https://github.com/middleware-labs/mw-agent/blob/master/pkg/agent/hostagent_windows.go"
    click Darwin "https://github.com/middleware-labs/mw-agent/blob/master/pkg/agent/hostagent_darwin.go"
    click KubeAgent "https://github.com/middleware-labs/mw-agent/blob/master/pkg/agent/kubeagent.go"
    click Helm "https://github.com/middleware-labs/mw-agent/tree/master/package-tooling/helm/mw-agent-chart/"
    click K8sConfig "https://github.com/middleware-labs/mw-agent/tree/master/configyamls-k8s/"
    click RBAC "https://github.com/middleware-labs/mw-agent/blob/master/package-tooling/helm/mw-agent-chart/templates/cluster-role.yaml"
    click ServiceAccounts "https://github.com/middleware-labs/mw-agent/blob/master/package-tooling/helm/mw-agent-chart/templates/serviceaccount.yaml"
    click KubeDeploy "https://github.com/middleware-labs/mw-agent/blob/master/package-tooling/helm/mw-agent-chart/templates/deployment.yaml"
    click OtelConfig "https://github.com/middleware-labs/mw-agent/blob/master/package-tooling/otel-config.yaml.sample"
    click LinuxService "https://github.com/middleware-labs/mw-agent/blob/master/package-tooling/linux/mw-agent.service"
    click DarwinService "https://github.com/middleware-labs/mw-agent/blob/master/package-tooling/darwin/io.middleware.mw-agent.plist"
    click Docker "https://github.com/middleware-labs/mw-agent/tree/master/Dockerfiles/"
    click MetricsBase "https://github.com/middleware-labs/mw-agent/blob/master/metadata/base/metrics.json"
    click MetadataGen "https://github.com/middleware-labs/mw-agent/tree/master/metadata-yaml"
    
    %% Styling
    classDef core fill:#2374ab
    classDef platform fill:#ff7f50
    classDef k8s fill:#9370db
    classDef config fill:#32cd32
    classDef package fill:#daa520
    classDef service fill:#778899
    classDef build fill:#4682b4
    classDef metadata fill:#808080
    
    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Platform Specific"]:::platform
        L3["Kubernetes Components"]:::k8s
        L4["Configuration"]:::config
        L5["Packages"]:::package
        L6["Services"]:::service
        L7["Build Tools"]:::build
        L8["Metadata"]:::metadata
    end
```
