Statistical Mechanics Of Community Detection