>>64147503
Federal gets complicated because there isn't one agency but a whole alphabet soup of them specialized in different things. That doesn't mean they outrank an HP, SD or PD (although they often act like it), federal agencies are only out there to enforce federal laws and assist smaller state/county/municipal agencies. Some criminal activity violated both state and federal law, so different levels of government and therefore levels of law enforcement frequently collaborate on investigation and prosecution.
For instance a person can be arrested by a PD for multiple violations and face charges in local court for violating state law, get acquitted and dragged into federal court to face charges for violating federal law as well.
An SD can ask the FBI for information about a criminal who is wanted outside of their jurisdiction and records, or ask the ATF to help with an arson investigation or to trace a recovered gun.
This sort of collaboration happens a lot in the LE world, but isn't a matter of bossing each other around. For instance feds often have a cultural attitude of superiority, but that doesn't mean they actually go shoving themselves where they aren't needed or wanted unless there is a compelling reason to do so. That's mostly a Hollywood trope. It is notable also that most of the routine day in/day out work is done on the local level.
Also I missed a point earlier. Not every incorporated city or town has a PD. A lot of smaller ones don't have a budget to organize and run one, so they contract with the SD to provide LE services for their town instead.