Components
In some cases, you may want to add a role when a new user is created regardless of how the user is created (UI, GraphQL, Rest API, or something else). The hook_ENTITY_TYPE_presave() hook is perfect for this.
use Drupal\user\UserInterface;
function MY_MODULE_user_presave(UserInterface $user) {
if ($user->isNew() && !$user->hasRole('frontend_app')) {
$user->addRole('frontend_app');
}
}