# ignacio-chiazzo/ruby_whatsapp_sdk architecture

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

- Interactive diagram: https://gitdiagram.com/ignacio-chiazzo/ruby_whatsapp_sdk
- Repository: https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk

## Overview

##### Main Components
- Client Initialization & Configuration:
– Represent the configuration block (see examples under “Option 1” in the README) where the user sets access tokens, API version, and logger details.
– This maps to the configuration code in lib/whatsapp_sdk/configuration.rb and the client wrapper in lib/whatsapp_sdk/api/client.rb.
- API Client:
– Show the central “Client” component (WhatsappSdk::Api::Client) that users instantiate.
– This client serves as a façade for the various API operations.
- API Endpoints (Modules):
▪ Messages – from lib/whatsapp_sdk/api/messages.rb (and associated response classes in lib/whatsapp_sdk/api/responses).
▪ Media – for uploading, downloading, and deleting media (library under lib/whatsapp_sdk/api/medias.rb).
▪ Phone Numbers – managing registration and queries (in lib/whatsapp_sdk/api/phone_numbers.rb).
▪ Business Profiles – for getting and updating business information.
▪ Templates – for creating, updating, and deleting message templates.
- Resource Classes:
– Under lib/whatsapp_sdk/resource, list the various resource classes that model the data objects (such as Message, Media, Currency, DateTime, etc.). These handle conversion and validations before being sent to the API.
- Error Handling:
– Include a component (like “Error Handler” or “Response Handler”) to represent modules such as WhatsappSdk::Error and the responses under lib/whatsapp_sdk/api/responses.
- External Service:

##### Out the Relationships and Data Flow
- This configuration feeds into the API Client.
- Each of these modules utilizes one or several resource classes to structure data payloads.
- Additionally, include a pathway for error handling where API responses are parsed and exceptions such as HttpResponseError are raised.

##### Architectural Patterns
- That the SDK is designed using a modular and layered architecture:
– A configuration layer (initialization).
– An abstraction layer (the API Client and endpoint modules that encapsulate HTTP calls).
– A presentation/representation layer (the Resource classes that define the data model for messages, media, etc.).
- This separation provides clear responsibilities and makes testing easier—as seen by the comprehensive test directory.

##### Additional Elements
- Optionally, reference CI/CD configurations (located in .circleci, .github, .travis.yml) as part of the project’s overall architecture for automated testing and deployment.
- Finally, mention the gemspec and setup scripts (bin/setup, Rakefile) as part of the build/installation process.

## Diagram (Mermaid)

```mermaid
graph TD
    User["User Code"]:::default
    Config["Configuration"]:::config
    Client["API Client"]:::client
    Messages["Messages API"]:::api
    Media["Media API"]:::api
    PhoneNumbers["Phone Numbers API"]:::api
    BusinessProfiles["Business Profiles API"]:::api
    Templates["Templates API"]:::api
    Resources["Resource Classes"]:::resource
    ErrorHandler["Error Handling"]:::error
    External["External WhatsApp Cloud API"]:::external

    User -->|"configures"| Config
    Config -->|"initializes"| Client
    Client -->|"communicatesWith"| Messages
    Client -->|"communicatesWith"| Media
    Client -->|"communicatesWith"| PhoneNumbers
    Client -->|"communicatesWith"| BusinessProfiles
    Client -->|"communicatesWith"| Templates

    Messages -->|"usesData"| Resources
    Media -->|"usesData"| Resources
    PhoneNumbers -->|"usesData"| Resources
    BusinessProfiles -->|"usesData"| Resources
    Templates -->|"usesData"| Resources

    Messages -->|"sendsTo"| External
    Media -->|"sendsTo"| External
    PhoneNumbers -->|"sendsTo"| External
    BusinessProfiles -->|"sendsTo"| External
    Templates -->|"sendsTo"| External

    Messages -->|"handlesError"| ErrorHandler
    Media -->|"handlesError"| ErrorHandler
    PhoneNumbers -->|"handlesError"| ErrorHandler
    BusinessProfiles -->|"handlesError"| ErrorHandler
    Templates -->|"handlesError"| ErrorHandler

    subgraph "Development Tools"
        TestSuite["Test Suite (test/)"]:::dev
        CICD["CI/CD Configurations (.circleci, .github, .travis.yml)"]:::dev
        TestSuite --- CICD
    end

    %% Click Events
    click Config "https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/blob/main/lib/whatsapp_sdk/configuration.rb"
    click Client "https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/blob/main/lib/whatsapp_sdk/api/client.rb"
    click Messages "https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/blob/main/lib/whatsapp_sdk/api/messages.rb"
    click Media "https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/blob/main/lib/whatsapp_sdk/api/medias.rb"
    click PhoneNumbers "https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/blob/main/lib/whatsapp_sdk/api/phone_numbers.rb"
    click BusinessProfiles "https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/blob/main/lib/whatsapp_sdk/api/business_profile.rb"
    click Templates "https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/blob/main/lib/whatsapp_sdk/api/templates.rb"
    click Resources "https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/tree/main/lib/whatsapp_sdk/resource"
    click ErrorHandler "https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/blob/main/lib/whatsapp_sdk/error.rb"

    %% Styles
    classDef config fill:#e0f7fa,stroke:#006064,stroke-width:2px;
    classDef client fill:#e8f5e9,stroke:#1b5e20,stroke-width:2px;
    classDef api fill:#e3f2fd,stroke:#0d47a1,stroke-width:2px;
    classDef external fill:#f1f8e9,stroke:#33691e,stroke-width:2px;
    classDef resource fill:#fff9c4,stroke:#f57f17,stroke-width:2px;
    classDef error fill:#ffcdd2,stroke:#b71c1c,stroke-width:2px;
    classDef dev fill:#f3e5f5,stroke:#6a1b9a,stroke-width:2px;
    classDef default fill:#ffffff,stroke:#000000,stroke-width:1px;
```
