# pnmcosta/go-meta-webhooks architecture

> Architecture diagram of the GitHub repository pnmcosta/go-meta-webhooks, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pnmcosta/go-meta-webhooks
- Repository: https://github.com/pnmcosta/go-meta-webhooks

## Overview

##### Project Type and Purpose
- This project is a Go package that provides type‑safe payload verification, validation, parsing, and handling specifically for Meta’s Webhooks (e.g., Instagram notifications).
- Its primary purpose is to support subscription verification, event signature validation via SHA256, JSON Schema–based payload validation/unmarshalling, and composable handler interfaces for different event types.
- The README highlights use cases integrating with HTTP servers (such as with the Echo framework) as well as support for granular, scoped event handling (Instagram/Changes/Messaging).

##### Analyzing the File Structure
- The root directory contains several core Go files (e.g., changes.go, entry.go, event.go, instagram.go, messaging.go, webhooks.go) that implement the major functionalities:
- Verification and handling of webhook subscriptions and events.
- Implementation of distinct event types (Instagram, Messaging, etc.).
- The “handler” subdirectory contains handler implementations and tests, indicating that the system is built around composable handler interfaces.
- There are supporting files for configuration and options (options.go, options_instagram.go), payload and schema handling (payload.go, schema.go, schema.json), and token management (token.go).
- The presence of files like go.mod and go.sum signifies dependency management in a Go environment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "HTTP Layer"
        HTTP["HTTP Entry Point"]:::http
    end

    subgraph "Processing Layer"
        PROCESS["Core Webhook Processor"]:::processing
        TOKEN["Token/Signature Validator"]:::validator
        VAL_LOGIC["Payload Validator Logic"]:::validator
        SCHEMA_FILE["JSON Schema File"]:::validator
    end

    subgraph "Event Handling Layer"
        COMPOSABLE["Composable Handlers"]:::handler
        INST_LOGIC["Instagram Event Handler Logic"]:::handler
        INST_OPTIONS["Instagram Options"]:::handler
        MESSAGING["Messaging Event Handler"]:::handler
    end

    subgraph "Configuration Layer"
        OPTIONS["Configuration Manager / Options"]:::config
    end

    subgraph "Testing/Utility"
        TEST["Unit Tests & Utilities"]:::testing
    end

    HTTP -->|"receivesWebhook"| PROCESS
    PROCESS -->|"validatePayload"| VAL_LOGIC
    VAL_LOGIC -->|"uses"| SCHEMA_FILE
    PROCESS -->|"verifyToken"| TOKEN
    PROCESS -->|"dispatchToHandlers"| COMPOSABLE
    COMPOSABLE -->|"callsInstagram"| INST_LOGIC
    COMPOSABLE -->|"callsMessaging"| MESSAGING
    INST_LOGIC -->|"configuredBy"| INST_OPTIONS

    OPTIONS -->|"configuresProcessor"| PROCESS
    OPTIONS -->|"configuresInstagram"| INST_LOGIC
    OPTIONS -->|"configuresMessaging"| MESSAGING
    OPTIONS -->|"configuresHandlers"| COMPOSABLE

    %% Click Events
    click HTTP "https://github.com/pnmcosta/go-meta-webhooks/blob/main/entry.go"
    click PROCESS "https://github.com/pnmcosta/go-meta-webhooks/blob/main/webhooks.go"
    click TOKEN "https://github.com/pnmcosta/go-meta-webhooks/blob/main/token.go"
    click VAL_LOGIC "https://github.com/pnmcosta/go-meta-webhooks/blob/main/schema.go"
    click SCHEMA_FILE "https://github.com/pnmcosta/go-meta-webhooks/blob/main/schema.json"
    click INST_LOGIC "https://github.com/pnmcosta/go-meta-webhooks/blob/main/instagram.go"
    click INST_OPTIONS "https://github.com/pnmcosta/go-meta-webhooks/blob/main/options_instagram.go"
    click MESSAGING "https://github.com/pnmcosta/go-meta-webhooks/blob/main/messaging.go"
    click COMPOSABLE "https://github.com/pnmcosta/go-meta-webhooks/blob/main/handler/handler.go"
    click OPTIONS "https://github.com/pnmcosta/go-meta-webhooks/blob/main/options.go"

    %% Styles
    classDef http fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef processing fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef validator fill:#FFFF99,stroke:#000,stroke-width:2px;
    classDef handler fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef config fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef testing fill:#F5DEB3,stroke:#000,stroke-width:2px;
```
