Canonical splittings of groups and 3-manifolds