We give a realization of Nakajima varieties and the action of the Weyl group on them using certain canonical structures of homological algebras and their natural generalization, which we develop in this paper. We consider in detail the case of an affine quiver, where we present a simple homological characterization of Nakajima varieties and its relation to moduli of sheaves on the projective plane.