This post is old but it does a great job of explaining how device handlers and smartapps work (and it’s still applicable).