# dynatrace/dynatrace-configuration-as-code-core architecture

> Architecture diagram of the GitHub repository dynatrace/dynatrace-configuration-as-code-core, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dynatrace/dynatrace-configuration-as-code-core
- Repository: https://github.com/dynatrace/dynatrace-configuration-as-code-core

## Overview

##### Project type and purpose
- This is a Go library (not an end-user application) that provides reusable building blocks for “Configuration as Code” tools targeting the Dynatrace API.
- It offers two layers of clients:
- api/clients – low-level, one-to-one Go wrappers around REST calls.
- clients – higher-level, “smarter” abstractions (CRUD + Upsert) that build on api/clients to simplify common use cases.

##### File structure
- Top-level packages:
- api/… – basic clients, REST helpers (api/rest), authentication (api/auth), response handling.
- clients/… – factory, smart clients per domain (automation, buckets, documents, etc.).
- gen/… – auto-generated OpenAPI client code for account_management (not hand-written).
- internal/… – shared/internal utilities (pointer helpers).
- testutils/… – helper server/context for tests.
- tools/… – developer scripts (lint, license checks, git hooks).
- Configuration & CI files: .github/workflows, Makefile, sonar, golangci lint, etc., indicate a robust CI/CD and code-quality pipeline.

##### README for additional insights
- Describes purpose: not a general Dynatrace client, but a helper for Config-as-Code tools (e.g., Monaco CLI, Terraform provider).
- Shows usage: clients.Factory → WithEnvironmentURL/WithOAuthCredentials → factory.BucketClient() → .Get() → api.DecodeJSON.
- Mentions optional logging via logr and HTTPListener injection.

##### Main components & interactions (
a. Clients.Factory
– Entry point: configures base URL, auth, optional HTTPListener & logger.
b. “Smarter” clients (clients/…)
– Depend on: Factory → api/clients lower layer.
– Offer: CRUD + Upsert, domain-specific logic (automation, buckets, documents, openpipeline, segments, SLO).
c. “Basic” API clients (api/clients/…)
– Wrap: HTTP calls (api/rest package) to Dynatrace endpoints.
– Include auth/token management (api/auth).
d. REST layer (api/rest)
– Core HTTP logic: concurrency, retries, rate limiting, listener callbacks, request/response parsing.
e. Code-generated layer (gen)
– Provides strongly typed models & client for account_management domain.
– Used by clients if account_management support is needed.
f. External Dependencies & Services
– Dynatrace API (external HTTP service).
– logr (logging interface).
– Context propagation for logging & cancellation.
g. Developer tooling & tests
– testutils: in-process HTTP server for unit tests.
– tools: formatting, license, hooks.

##### Architectural patterns & design principles
- Layered architecture:
- Presentation/API‐wrapper (api/clients)
- Business/service layer (clients/…)
- Infrastructure/HTTP concerns (api/rest)
- Dependency injection: Factory configures clients with auth, URL, logger, HTTPListener.
- Code generation: gen/… isolates spec-driven code from handwritten.
- Internal package for non-public utilities.
- Testability: testutils to spin up fake HTTP endpoints; HTTPListener for observability.

2. Inside it, partition into three horizontal layers:
Layer 1 (top): clients.Factory & “Smarter Clients” (clients/*)
Layer 2 (middle): Basic API Clients (api/clients/*)
Layer 3 (bottom): REST & Auth (api/rest, api/auth)
6. Annotate:
- Auth flow: api/auth → token.go → REST calls include token header.
- HTTPListener: plug into REST layer.
- Logging: propagate via context.
- Rounded rectangles for packages.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Consumers
    subgraph "External Consumers" 
        Monaco("Monaco CLI"):::external
        Terraform("Terraform Provider"):::external
    end

    %% Core Library Container
    subgraph "Dynatrace Config-as-Code Core (Go Library)"
        direction TB

        %% Layer 1: Smarter Clients
        subgraph "Layer 1: Factory & Smarter Clients"
            direction TB
            Factory["Clients.Factory"]:::smarter
            AutomationSmarter["Automation Client"]:::smarter
            BucketsSmarter["Buckets Client"]:::smarter
            DocumentsSmarter["Documents Client"]:::smarter
            OpenPipelineSmarter["OpenPipeline Client"]:::smarter
            SegmentsSmarter["Segments Client"]:::smarter
            SLOSmarter["SLO Client"]:::smarter
            PermissionsSmarter["Settings Permissions Client"]:::smarter
        end

        %% Layer 2: Basic API Clients
        subgraph "Layer 2: Basic API Clients"
            direction TB
            AccountsBasic["Accounts API Client"]:::basic
            AutomationBasic["Automation API Client"]:::basic
            BucketsBasic["Buckets API Client"]:::basic
            DocumentsBasic["Documents API Client"]:::basic
            OpenPipelineBasic["OpenPipeline API Client"]:::basic
            GeneralAPIDoc["API Package Doc"]:::basic
        end

        %% Layer 3: REST & Auth
        subgraph "Layer 3: REST & Auth"
            direction TB
            RestClient["REST Client"]:::rest
            Concurrent["Concurrency Helpers"]:::rest
            RateLimiting["Rate Limiting"]:::rest
            RetryLogic["Retry Logic"]:::rest
            Listener["Listener Callbacks"]:::rest
            ResponseParsing["Response Parsing"]:::rest
            OAuth["OAuth Credentials"]:::auth
            TokenMgmt["Token Management"]:::auth
        end

        %% Common Utilities
        PointerUtil["Pointer Helpers"]:::util
    end

    %% Code-generated Layer
    gen["gen/account_management"]:::gen

    %% External Dynatrace API
    DynatraceAPI["Dynatrace API (HTTP)"]:::external

    %% Test & Tooling
    TestUtils["testutils (HTTP Server & Context)"]:::util
    Tools["tools (Scripts & Hooks)"]:::tool

    %% Connections
    Monaco -->|"uses"| Factory
    Terraform -->|"uses"| Factory

    Factory -->|"provides dependency"| AutomationSmarter
    Factory --> BucketsSmarter
    Factory --> DocumentsSmarter
    Factory --> OpenPipelineSmarter
    Factory --> SegmentsSmarter
    Factory --> SLOSmarter
    Factory --> PermissionsSmarter

    AutomationSmarter -->|"calls"| AutomationBasic
    BucketsSmarter --> BucketsBasic
    DocumentsSmarter --> DocumentsBasic
    OpenPipelineSmarter --> OpenPipelineBasic
    SegmentsSmarter --> AutomationBasic
    SLOSmarter --> AutomationBasic
    PermissionsSmarter --> AutomationBasic

    AccountsBasic --> RestClient
    AutomationBasic --> RestClient
    BucketsBasic --> RestClient
    DocumentsBasic --> RestClient
    OpenPipelineBasic --> RestClient
    GeneralAPIDoc --> RestClient

    RestClient --> Concurrent
    RestClient --> RateLimiting
    RestClient --> RetryLogic
    RestClient --> Listener
    RestClient --> ResponseParsing

    RestClient -->|"calls"| DynatraceAPI
    OAuth --> RestClient
    TokenMgmt --> RestClient

    Factory -.-> gen
    PointerUtil --> Factory

    TestUtils -.-> RestClient
    TestUtils -.-> Factory
    Tools -.-> Factory

    %% Click Events
    click Factory "https://github.com/dynatrace/dynatrace-configuration-as-code-core/blob/main/clients/factory.go"
    click AutomationSmarter "https://github.com/dynatrace/dynatrace-configuration-as-code-core/blob/main/clients/automation/automation.go"
    click BucketsSmarter "https://github.com/dynatrace/dynatrace-configuration-as-code-core/blob/main/clients/buckets/bucket.go"
    click DocumentsSmarter "https://github.com/dynatrace/dynatrace-configuration-as-code-core/blob/main/clients/documents/client.go"
    click OpenPipelineSmarter "https://github.com/dynatrace/dynatrace-configuration-as-code-core/blob/main/clients/openpipeline/openpipeline.go"
    click SegmentsSmarter "https://github.com/dynatrace/dynatrace-configuration-as-code-core/blob/main/clients/segments/segments.go"
    click SLOSmarter "https://github.com/dynatrace/dynatrace-configuration-as-code-core/blob/main/clients/slo/slo.go"
    click PermissionsSmarter "https://github.com/dynatrace/dynatrace-configuration-as-code-core/blob/main/clients/settings/permissions/permissions.go"
    click AccountsBasic "https://github.com/dynatrace/dynatrace-configuration-as-code-core/blob/main/api/clients/accounts/accounts.go"
    click AutomationBasic "https://github.com/dynatrace/dynatrace-configuration-as-code-core/blob/main/api/clients/automation/automation.go"
    click BucketsBasic "https://github.com/dynatrace/dynatrace-configuration-as-code-core/blob/main/api/clients/buckets/bucket.go"
    click DocumentsBasic "https://github.com/dynatrace/dynatrace-configuration-as-code-core/blob/main/api/clients/documents/document.go"
    click DocumentsBasic "https://github.com/dynatrace/dynatrace-configuration-as-code-core/blob/main/api/clients/documents/documents.go"
    click GeneralAPIDoc "https://github.com/dynatrace/dynatrace-configuration-as-code-core/blob/main/api/clients/doc.go"
    click RestClient "https://github.com/dynatrace/dynatrace-configuration-as-code-core/blob/main/api/rest/client.go"
    click Concurrent "https://github.com/dynatrace/dynatrace-configuration-as-code-core/blob/main/api/rest/concurrent.go"
    click RateLimiting "https://github.com/dynatrace/dynatrace-configuration-as-code-core/blob/main/api/rest/rate.go"
    click RetryLogic "https://github.com/dynatrace/dynatrace-configuration-as-code-core/blob/main/api/rest/retry.go"
    click Listener "https://github.com/dynatrace/dynatrace-configuration-as-code-core/blob/main/api/rest/listener.go"
    click ResponseParsing "https://github.com/dynatrace/dynatrace-configuration-as-code-core/blob/main/api/rest/response.go"
    click ResponseParsing "https://github.com/dynatrace/dynatrace-configuration-as-code-core/blob/main/api/rest/reader.go"
    click OAuth "https://github.com/dynatrace/dynatrace-configuration-as-code-core/blob/main/api/auth/oauth.go"
    click TokenMgmt "https://github.com/dynatrace/dynatrace-configuration-as-code-core/blob/main/api/auth/token.go"
    click PointerUtil "https://github.com/dynatrace/dynatrace-configuration-as-code-core/blob/main/internal/pointer/pointer.go"
    click TestUtils "https://github.com/dynatrace/dynatrace-configuration-as-code-core/blob/main/testutils/testserver.go"
    click gen "https://github.com/dynatrace/dynatrace-configuration-as-code-core/tree/main/gen/account_management"
    click Tools "https://github.com/dynatrace/dynatrace-configuration-as-code-core/blob/main/tools/check-format.sh"

    %% Styles
    classDef smarter fill:#cce5ff,stroke:#004085,color:#004085,stroke-width:1px
    classDef basic fill:#d4edda,stroke:#155724,color:#155724,stroke-width:1px
    classDef rest fill:#fff3cd,stroke:#856404,color:#856404,stroke-width:1px
    classDef auth fill:#f8d7da,stroke:#721c24,color:#721c24,stroke-width:1px
    classDef gen fill:#e2e3e5,stroke:#6c757d,color:#6c757d,stroke-width:1px
    classDef util fill:#f5c6cb,stroke:#721c24,color:#721c24,stroke-width:1px
    classDef external fill:#d1ecf1,stroke:#0c5460,color:#0c5460,stroke-width:1px
    classDef tool fill:#fff5cd,stroke:#8a6d3b,color:#8a6d3b,stroke-width:1px
```
