Structure of classical (finite and affine) W-algebras