# gitsneidig/rest-api-oauth-example architecture

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

- Interactive diagram: https://gitdiagram.com/gitsneidig/rest-api-oauth-example
- Repository: https://github.com/gitsneidig/rest-api-oauth-example

## Overview

##### Project type and purpose
- This is a lightweight backend “webhook authentication” microservice written in PHP.
- Its sole purpose is to accept incoming WooCommerce webhooks, look up the corresponding secret key in a database, compute or encode the expected signature, compare it with the incoming signature header, and then allow or reject the webhook.

##### File structure
- Top-level files:
- README.md – describes purpose and flow
- oauth-wc.php – single PHP script implementing the webhook endpoint, OAuth signature lookup, and comparison
- No separate frontend, no build scripts, no sub-modules.
- Implicit components: a relational database (e.g., MySQL) holding store/event → secret-key mappings; PHP runtime + web server; external WooCommerce stores triggering webhooks.

##### README for additional insights
- Incoming headers:
- x-wc-webhook-source: the store name (used as a DB key)
- x-wc-webhook-signature: the HMAC or encoded signature to verify
- Only “create” and “update order” events are processed; each event type has its own secret.
- On successful authentication, the payload can be forwarded to the multi-channel sales service (not shown in code but implied).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Source
    WC["WooCommerce Store(s)"]:::external

    %% Webhook Receiver Service and Internals
    subgraph "Webhook Receiver Service"
        direction TB
        HL["HTTP Listener"]:::subcomp
        HP["Header Parser"]:::subcomp
        DC["DB Client"]:::subcomp
        SV["Signature Verifier"]:::subcomp
        RG["Response Generator"]:::subcomp
    end

    %% Database
    DB["Secret-Key Database"]:::db

    %% Downstream Service
    MS["Multi-Channel Sales Service"]:::downstream

    %% Documentation
    README["Project Documentation: README.md"]:::external

    %% Connections
    WC -->|"HTTP POST headers + JSON"| HL
    HL -->|"extract headers + payload"| HP
    HP -->|"SELECT secret_key WHERE source= x-wc-webhook-source"| DC
    DC -->|"SQL Query"| DB
    DB -->|"secret_key"| DC
    DC -->|"secret_key"| SV
    SV -->|valid| RG
    SV -->|invalid| RG
    RG -->|forward payload| MS
    RG -->|401 Unauthorized| WC
    README -.-> WC

    %% Click Events
    click HL "https://github.com/gitsneidig/rest-api-oauth-example/blob/main/oauth-wc.php"
    click HP "https://github.com/gitsneidig/rest-api-oauth-example/blob/main/oauth-wc.php"
    click DC "https://github.com/gitsneidig/rest-api-oauth-example/blob/main/oauth-wc.php"
    click SV "https://github.com/gitsneidig/rest-api-oauth-example/blob/main/oauth-wc.php"
    click RG "https://github.com/gitsneidig/rest-api-oauth-example/blob/main/oauth-wc.php"
    click README "https://github.com/gitsneidig/rest-api-oauth-example/blob/main/README.md"

    %% Styles
    classDef external fill:#eeeeee,stroke:#333,stroke-width:1px;
    classDef service fill:#BBDEFB,stroke:#2196F3,stroke-width:2px;
    classDef db fill:#FFCC80,stroke:#FB8C00,stroke-width:2px;
    classDef downstream fill:#C8E6C9,stroke:#388E3C,stroke-width:2px;
    classDef subcomp fill:#E3F2FD,stroke:#90CAF9,stroke-width:1px;
```
