# kyon147/laravel-shopify architecture

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

- Interactive diagram: https://gitdiagram.com/kyon147/laravel-shopify
- Repository: https://github.com/kyon147/laravel-shopify

## Overview

##### Main Components

a. Core Package Components:
- Authentication System
- Billing System
- Webhook Handler
- API Helper
- Session Management
- Database Layer

b. External Systems:
- Shopify API
- Laravel Application (host)
- Shopify Admin/Store

**┌─ Laravel Application ──────────────────────────────────────────┐**

- ┌─ Laravel Shopify Package ───────────────────────────┐      │

- ┌─ Controllers ─┐    ┌─ Services ──┐              │      │
- Auth        │    │ - ApiHelper │              │      │
- Billing     │    │ - Charge    │              │      │
- Webhook     │    │ - Theme     │              │      │
- API         │    └─────────────┘              │      │
- ┘                                  │      │

- ┌─ Middleware ──┐    ┌─ Actions ───┐              │      │
- AuthProxy   │    │ - Install   │              │      │
- Billable    │    │ - Activate  │              │      │
- VerifyShop  │    │ - Webhook   │              │      │
- ┘    └─────────────┘              │      │

- ┌─ Storage ─────┐    ┌─ Events ────┐              │      │
- Models      │    │ - Install   │              │      │
- Migrations  │    │ - Uninstall │              │      │
- Queries     │    └─────────────┘              │      │
- ┘                                  │      │
- ┘      │
- ┘

- ↕ HTTP/API Calls

**┌─ Shopify ──────────────────────────────────────────────────────┐**

- ┌─ Admin ─────┐    ┌─ Store ─────┐    ┌─ Webhooks ────┐      │
- Dashboard   │    │ Frontend    │    │ - App events  │      │
- App Bridge  │    │ Theme       │    │ - Store events│      │
- ┘    └────────────┘    └──────────────┘      │
- ┘

##### Key Relationships to Highlight

a. Authentication Flow:
- Shop → AuthController → OAuth → Shopify API
- Session management and token storage

b. Billing Flow:
- BillingController → Shopify Billing API
- Charge creation and verification

c. Webhook System:
- Shopify → WebhookController → Events → Jobs
- Event handling and processing

##### Important Details

- Database schema relationships (Plans, Charges, Shops)
- Authentication middleware chain
- API communication patterns
- Event/Job processing flow

##### Technical Specifications

- Laravel Framework integration points
- Shopify API version compatibility
- Database requirements
- Required PHP version

##### Implementation Notes

- Use standardized UML notation where applicable
- Version information
- Security implementations

Remember to include:
- Error handling paths
- Security checkpoints
- Data flow direction
- Scalability points
- Integration touchpoints

This will provide a clear understanding of how the package operates within both the Laravel and Shopify ecosystems while maintaining the appropriate level of detail for a principal software engineer to understand the system's architecture.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Laravel[Laravel Application]
        subgraph Package[Laravel Shopify Package]
            subgraph Controllers[Controllers Layer]
                Auth["Auth Controller"]
                Billing["Billing Controller"]
                Webhook["Webhook Controller"]
                API["API Controller"]
            end

            subgraph Middleware[Middleware Layer]
                AuthProxy["Auth Proxy"]
                Billable["Billable"]
                VerifyShop["Verify Shopify"]
                VerifyScopes["Verify Scopes"]
                IframeProtect["IFrame Protection"]
            end

            subgraph Services[Services Layer]
                ApiHelper["API Helper"]
                ChargeHelper["Charge Helper"]
                ThemeHelper["Theme Helper"]
                CookieHelper["Cookie Helper"]
            end

            subgraph Storage[Storage Layer]
                Models["Models"]
                Migrations["Migrations"]
                Queries["Queries"]
                SessionMgmt["Session Management"]
            end

            subgraph Actions[Actions Layer]
                AuthAction["Authenticate Shop"]
                WebhookAction["Create Webhooks"]
                DispatchWebhook["Dispatch Webhooks"]
            end

            subgraph Events[Events System]
                AppInstall["App Installed"]
                AppUninstall["App Uninstalled"]
                ShopAuth["Shop Authenticated"]
            end
        end
    end

    subgraph Shopify[Shopify Platform]
        Admin["Admin Dashboard"]
        Store["Store Frontend"]
        ShopifyAPI["Shopify API"]
        WebhookSystem["Webhook System"]
    end

    %% Relationships
    ShopifyAPI <--> API
    ShopifyAPI <--> Auth
    ShopifyAPI <--> Billing
    WebhookSystem --> Webhook
    Auth --> AuthProxy
    Auth --> AuthAction
    Billing --> Billable
    Webhook --> WebhookAction
    WebhookAction --> DispatchWebhook
    ApiHelper <--> ShopifyAPI
    SessionMgmt --> CookieHelper

    %% Click Events
    click Auth "https://github.com/Kyon147/laravel-shopify/blob/master/src/Http/Controllers/AuthController.php"
    click AuthProxy "https://github.com/Kyon147/laravel-shopify/blob/master/src/Http/Middleware/AuthProxy.php"
    click AuthAction "https://github.com/Kyon147/laravel-shopify/blob/master/src/Actions/AuthenticateShop.php"
    click Billing "https://github.com/Kyon147/laravel-shopify/blob/master/src/Http/Controllers/BillingController.php"
    click Billable "https://github.com/Kyon147/laravel-shopify/blob/master/src/Http/Middleware/Billable.php"
    click Webhook "https://github.com/Kyon147/laravel-shopify/blob/master/src/Http/Controllers/WebhookController.php"
    click WebhookAction "https://github.com/Kyon147/laravel-shopify/blob/master/src/Actions/CreateWebhooks.php"
    click DispatchWebhook "https://github.com/Kyon147/laravel-shopify/blob/master/src/Actions/DispatchWebhooks.php"
    click API "https://github.com/Kyon147/laravel-shopify/blob/master/src/Http/Controllers/ApiController.php"
    click ApiHelper "https://github.com/Kyon147/laravel-shopify/blob/master/src/Services/ApiHelper.php"
    click SessionMgmt "https://github.com/Kyon147/laravel-shopify/blob/master/src/Objects/Values/SessionToken.php"
    click CookieHelper "https://github.com/Kyon147/laravel-shopify/blob/master/src/Services/CookieHelper.php"
    click Models "https://github.com/Kyon147/laravel-shopify/tree/master/src/Storage/Models"
    click Migrations "https://github.com/Kyon147/laravel-shopify/tree/master/src/resources/database/migrations"
    click Queries "https://github.com/Kyon147/laravel-shopify/tree/master/src/Storage/Queries"
    click AppInstall "https://github.com/Kyon147/laravel-shopify/blob/master/src/Messaging/Events/AppInstalledEvent.php"
    click AppUninstall "https://github.com/Kyon147/laravel-shopify/blob/master/src/Messaging/Events/AppUninstalledEvent.php"
    click ShopAuth "https://github.com/Kyon147/laravel-shopify/blob/master/src/Messaging/Events/ShopAuthenticatedEvent.php"
    click ChargeHelper "https://github.com/Kyon147/laravel-shopify/blob/master/src/Services/ChargeHelper.php"
    click ThemeHelper "https://github.com/Kyon147/laravel-shopify/blob/master/src/Services/ThemeHelper.php"
    click VerifyShop "https://github.com/Kyon147/laravel-shopify/blob/master/src/Http/Middleware/VerifyShopify.php"
    click VerifyScopes "https://github.com/Kyon147/laravel-shopify/blob/master/src/Http/Middleware/VerifyScopes.php"
    click IframeProtect "https://github.com/Kyon147/laravel-shopify/blob/master/src/Http/Middleware/IframeProtection.php"

    %% Styling
    classDef default fill:#f9f9f9,stroke:#333,stroke-width:2px
    classDef controller fill:#ddf1fd,stroke:#0077cc
    classDef middleware fill:#ffe7d3,stroke:#ff6b00
    classDef service fill:#e1f7e1,stroke:#2d862d
    classDef storage fill:#e6e6fa,stroke:#6a329f
    classDef action fill:#fff0f5,stroke:#c71585
    classDef event fill:#f0f8ff,stroke:#4682b4
    classDef external fill:#f5f5f5,stroke:#666

    class Auth,Billing,Webhook,API controller
    class AuthProxy,Billable,VerifyShop,VerifyScopes,IframeProtect middleware
    class ApiHelper,ChargeHelper,ThemeHelper,CookieHelper service
    class Models,Migrations,Queries,SessionMgmt storage
    class AuthAction,WebhookAction,DispatchWebhook action
    class AppInstall,AppUninstall,ShopAuth event
    class Admin,Store,ShopifyAPI,WebhookSystem external
```
