Delete database records when Shopify app gets removed from store

I’m building a PHP-based Shopify application and need to clean up database entries when merchants remove my app from their stores. I discovered this webhook configuration code but I’m unsure about the implementation details and how to properly set it up to execute during app removal.

$uninstall_webhook = [
    'webhook' => [
        'topic' => 'app/uninstalled',
        'address' => 'https://mysite.com/app/cleanup_merchant_data.php?store=' . $store_domain,
        'format' => 'json',
    ],
];
$response = $api_client('POST /admin/webhooks.json', $uninstall_webhook);

Can someone explain where this webhook registration should be placed in my app structure and how the cleanup process gets triggered automatically?

register that webhook right after the merchant installs ur app, like in the oauth callback or installation flow. when they uninstall, shopify will automatically hit your cleanup_merchant_data.php endpoint and you can delete their records there. dont forget to verify the webhook is legit tho