# How are Zero-Knowledge Proof protocols designed?

There are some classic ZKP examples out there (the alibaba cave, the colored balls, etc. See the Wikipedia page for details)

To me it looks like these protocols were invented "ad-hoc". That is, someone came up with a clever solution for that particular problem, and it's not immediately clear how it applies to other problems.

Is there a more "direct" way of coming up with a protocol? Are there situations where a ZKP is not possible?