# paddlehq/paddle-node-sdk architecture

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

- Interactive diagram: https://gitdiagram.com/paddlehq/paddle-node-sdk
- Repository: https://github.com/paddlehq/paddle-node-sdk

## Overview

a. External Interfaces
- Paddle API connection
- Webhook handling
- Authentication flow

b. Internal Communication
- Resource to Entity mappings
- Type transformations (snake_case to camelCase)
- Error handling flow

##### Key Architectural Patterns to Highlight

a. Resource Pattern
- How each resource (products, customers, etc.) follows a consistent pattern
- CRUD operations flow
- Collection handling for pagination

b. Type System
- Entity definitions
- Request/Response type mappings
- Enum definitions

c. Webhook System
- Signature verification flow
- Event handling pattern
- Notification processing

##### Implementation Details

- Public interfaces
- Internal utilities
- Type definitions
- Test components

b. Clear separation between:
- Node.js specific code
- Edge runtime support
- Shared utilities

##### Webhook Receipt → Validation → Event Processing

Use a hierarchical layout with the core SDK at the center, resources radiating outward, and supporting infrastructure (logging, crypto, etc.) as peripheral components.

Remember to include version compatibility notes and indicate how the system handles API versioning and type updates.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Core
        SDK[Main SDK Class]
        Config[Configuration Handler]
        Logger[Logger System]
    end

    subgraph Resources
        BaseResource[Base Resource Implementation]
        APIResources[API Resources]
    end

    subgraph Entities
        DataModels[Data Models]
        TypeDefs[Type Definitions]
        SharedTypes[Shared Types]
        NotifEntities[Notification Entities]
    end

    subgraph Infrastructure
        APIClient[API Client]
        RuntimeProvs[Runtime Providers]
        CryptoProvs[Crypto Providers]
    end

    subgraph WebhookSystem
        WebhookVal[Webhook Validator]
        EventHandlers[Event Handlers]
        NotifParser[Notification Parser]
    end

    %% Core relationships
    SDK --> Config
    SDK --> Logger
    SDK --> APIClient
    SDK --> BaseResource

    %% Resource relationships
    BaseResource --> APIResources
    APIResources --> APIClient
    APIResources --> DataModels

    %% Entity relationships
    DataModels --> TypeDefs
    DataModels --> SharedTypes
    NotifEntities --> TypeDefs

    %% Infrastructure relationships
    APIClient --> RuntimeProvs
    APIClient --> CryptoProvs

    %% Webhook system relationships
    WebhookVal --> CryptoProvs
    WebhookVal --> EventHandlers
    EventHandlers --> NotifParser
    NotifParser --> NotifEntities

    %% External connections
    PaddleAPI((Paddle API)) --> APIClient
    WebhookEvents((Webhook Events)) --> WebhookVal

    %% Styling
    classDef core fill:#f9f,stroke:#333,stroke-width:2px
    classDef resource fill:#bbf,stroke:#333
    classDef entity fill:#bfb,stroke:#333
    classDef infra fill:#fbb,stroke:#333
    classDef webhook fill:#ffb,stroke:#333
    classDef external fill:#ddd,stroke:#333,stroke-dasharray: 5 5

    class SDK,Config,Logger core
    class BaseResource,APIResources resource
    class DataModels,TypeDefs,SharedTypes,NotifEntities entity
    class APIClient,RuntimeProvs,CryptoProvs infra
    class WebhookVal,EventHandlers,NotifParser webhook
    class PaddleAPI,WebhookEvents external

    %% Click events
    click SDK "https://github.com/PaddleHQ/paddle-node-sdk/blob/main/src/paddle.ts"
    click Config "https://github.com/PaddleHQ/paddle-node-sdk/blob/main/src/internal/api/environment.ts"
    click Logger "https://github.com/PaddleHQ/paddle-node-sdk/blob/main/src/internal/base/logger.ts"
    click APIResources "https://github.com/PaddleHQ/paddle-node-sdk/tree/main/src/resources/"
    click BaseResource "https://github.com/PaddleHQ/paddle-node-sdk/blob/main/src/internal/base/base-resource.ts"
    click DataModels "https://github.com/PaddleHQ/paddle-node-sdk/tree/main/src/entities/"
    click TypeDefs "https://github.com/PaddleHQ/paddle-node-sdk/tree/main/src/types/"
    click SharedTypes "https://github.com/PaddleHQ/paddle-node-sdk/tree/main/src/entities/shared/"
    click NotifEntities "https://github.com/PaddleHQ/paddle-node-sdk/tree/main/src/notifications/entities/"
    click APIClient "https://github.com/PaddleHQ/paddle-node-sdk/blob/main/src/internal/api/client.ts"
    click RuntimeProvs "https://github.com/PaddleHQ/paddle-node-sdk/tree/main/src/internal/providers/runtime/"
    click CryptoProvs "https://github.com/PaddleHQ/paddle-node-sdk/tree/main/src/internal/providers/crypto/"
    click WebhookVal "https://github.com/PaddleHQ/paddle-node-sdk/blob/main/src/notifications/helpers/webhooks-validator.ts"
    click EventHandlers "https://github.com/PaddleHQ/paddle-node-sdk/tree/main/src/notifications/events/"
    click NotifParser "https://github.com/PaddleHQ/paddle-node-sdk/blob/main/src/__tests__/notifications/notifications-parser.test.ts"
```
