Stability and diversity of ecological communities