Validating application design against specifications

I am also trying to follow the rule, that domain model should never contain an invalid data.

So, how do you design validation mechanism in your application so that validation errors, that take place in the domain, propagate properly to the client?

For example, when domain model raises an exception about duplicate username, how to correctly bind that exception to the submitted form? You should consider designing a form with a uniqueness validation button and all it does is perform a query.

Some article, that inspired this question, can be found here: I've seen no such mechanisms in web frameworks known to me. Then when you submit the form you can let the database throw the uniqueness exception and the service layer can catch it and wrap it in a nice http depends how your application is architechtured.

You define the validation strategies based on specifications, regulations and risks.