# datadog/datadog-api-client-go architecture

> Architecture diagram of the GitHub repository datadog/datadog-api-client-go, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/datadog/datadog-api-client-go
- Repository: https://github.com/datadog/datadog-api-client-go

## Overview

a. Client Initialization Flow:
- Application → Configuration → APIClient → Service APIs

b. Request/Response Flow:
- Service APIs → Request Handling → Authentication → HTTP Client → Datadog API

c. Data Processing Flow:
- Response → Decoder (JSON) → Model Objects → Client Application

##### Key Components Detail

a. Configuration Component:
- API/App Key Management
- Server Variables
- Retry Configuration
- Debug Settings
- Compression Settings
- Proxy Settings

b. API Client:
- Request Building
- Response Handling
- Error Management
- Pagination Support

c. Service APIs:
- V1 Services
- V2 Services
- Versioned Endpoints

##### Integration Points (Use interface symbols)

a. External Systems:
- Datadog API (Primary)
- Proxy Servers (Optional)
- Custom HTTP Clients

b. Authentication Systems:
- API Key Auth
- App Key Auth

##### Design Patterns (Use appropriate symbols)

a. Client Patterns:
- Factory Pattern (API Client Creation)
- Builder Pattern (Request Construction)
- Strategy Pattern (Authentication)

b. Service Patterns:
- Repository Pattern (API Services)
- Adapter Pattern (HTTP Client)

##### Cross-Cutting Concerns (Use horizontal layers)

a. Common Functionality:
- Context Management
- Error Handling
- Logging
- Configuration

b. Security:
- Authentication
- TLS/SSL
- Proxy Support

##### Version-specific model structures

Remember to include notes about the two available JSON encoders (standard library and goccy/go-json) and how they can be selected at build time.

This structure will provide a clear understanding of how the client interacts with Datadog's APIs while maintaining flexibility for different use cases and configurations.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Config["Configuration Management"]:::config
        Auth["Authentication & Client Setup"]:::config
        Compress["Compression Settings"]:::config
        JsonEnc["JSON Encoding"]:::config
        
        Common["Common Package"]:::core
        V1["DatadogV1 Client"]:::core
        V2["DatadogV2 Client"]:::core
    end

    subgraph "API Services V1"
        AuthV1["Authentication"]:::apiv1
        DashV1["Dashboards"]:::apiv1
        MetricsV1["Metrics"]:::apiv1
        LogsV1["Logs"]:::apiv1
        MonitorsV1["Monitors"]:::apiv1
        UsersV1["Users"]:::apiv1
    end

    subgraph "API Services V2"
        AuthV2["Authentication"]:::apiv2
        MetricsV2["Metrics"]:::apiv2
        LogsV2["Logs"]:::apiv2
        MonitorsV2["Monitors"]:::apiv2
        UsersV2["Users"]:::apiv2
    end

    subgraph "External"
        DD["Datadog API"]:::external
        Proxy["Proxy Servers"]:::external
    end

    subgraph "Testing & Documentation"
        Tests["Integration Tests"]:::test
        Scenarios["Scenario Tests"]:::test
        Examples["Examples"]:::docs
        Docs["Documentation"]:::docs
    end

    Config --> Auth
    Auth --> Common
    Compress --> Common
    JsonEnc --> Common
    Common --> V1
    Common --> V2

    V1 --> AuthV1
    V1 --> DashV1
    V1 --> MetricsV1
    V1 --> LogsV1
    V1 --> MonitorsV1
    V1 --> UsersV1

    V2 --> AuthV2
    V2 --> MetricsV2
    V2 --> LogsV2
    V2 --> MonitorsV2
    V2 --> UsersV2

    AuthV1 --> DD
    AuthV2 --> DD
    DD -.-> Proxy

    Tests --> V1
    Tests --> V2
    Scenarios --> V1
    Scenarios --> V2

    classDef core fill:#f9f,stroke:#333,stroke-width:2px
    classDef config fill:#fcf,stroke:#333
    classDef apiv1 fill:#ddf,stroke:#333
    classDef apiv2 fill:#dfd,stroke:#333
    classDef external fill:#fdd,stroke:#333
    classDef test fill:#ffd,stroke:#333
    classDef docs fill:#dff,stroke:#333

    click Config "https://github.com/DataDog/datadog-api-client-go/blob/master/api/datadog/configuration.go"
    click Auth "https://github.com/DataDog/datadog-api-client-go/blob/master/api/datadog/client.go"
    click Compress "https://github.com/DataDog/datadog-api-client-go/blob/master/api/datadog/zstd.go"
    click JsonEnc "https://github.com/DataDog/datadog-api-client-go/blob/master/api/datadog/encoding_json.go"
    click Common "https://github.com/DataDog/datadog-api-client-go/tree/master/api/datadog/"
    click V1 "https://github.com/DataDog/datadog-api-client-go/tree/master/api/datadogV1/"
    click V2 "https://github.com/DataDog/datadog-api-client-go/tree/master/api/datadogV2/"
    click AuthV1 "https://github.com/DataDog/datadog-api-client-go/blob/master/api/datadogV1/api_authentication.go"
    click DashV1 "https://github.com/DataDog/datadog-api-client-go/blob/master/api/datadogV1/api_dashboards.go"
    click MetricsV1 "https://github.com/DataDog/datadog-api-client-go/blob/master/api/datadogV1/api_metrics.go"
    click LogsV1 "https://github.com/DataDog/datadog-api-client-go/blob/master/api/datadogV1/api_logs.go"
    click MonitorsV1 "https://github.com/DataDog/datadog-api-client-go/blob/master/api/datadogV1/api_monitors.go"
    click UsersV1 "https://github.com/DataDog/datadog-api-client-go/blob/master/api/datadogV1/api_users.go"
    click AuthV2 "https://github.com/DataDog/datadog-api-client-go/blob/master/api/datadogV2/api_auth_n_mappings.go"
    click MetricsV2 "https://github.com/DataDog/datadog-api-client-go/blob/master/api/datadogV2/api_metrics.go"
    click LogsV2 "https://github.com/DataDog/datadog-api-client-go/blob/master/api/datadogV2/api_logs.go"
    click MonitorsV2 "https://github.com/DataDog/datadog-api-client-go/blob/master/api/datadogV2/api_monitors.go"
    click UsersV2 "https://github.com/DataDog/datadog-api-client-go/blob/master/api/datadogV2/api_users.go"
    click Tests "https://github.com/DataDog/datadog-api-client-go/tree/master/tests/api/"
    click Scenarios "https://github.com/DataDog/datadog-api-client-go/tree/master/tests/scenarios/"
    click Examples "https://github.com/DataDog/datadog-api-client-go/tree/master/examples/"
    click Docs "https://github.com/DataDog/datadog-api-client-go/blob/master/doc.go"
```
