A traffic stop and detention must be based on "reasonable suspicion." That means they officer has to have sufficient facts and information to show that some sort of criminal activity is occurring and that the person they want to stop is connected.
In a traffic stop, they will point to some violation of the vehicle code in your state as the basis for reasonable suspicion. Any violation will do - the idea is that if they can prove they were "investigating" a traffic violation, they needed to stop you and contact you about it.
I don't know where else you're going with this question. Did they search your car and find something? That's a whole different analysis. Is this just a question to contest a traffic ticket? Without more details, the above answer is the best I can do.