The geometry of $G$-structures