Geometry of optimality conditions and constraint qualifications