We develop a generalized group-based epidemic model (GgroupEM) framework for any compartmental epidemic model (for example; susceptible-infected-susceptible, susceptible-infected-recovered, susceptible-exposed-infected-recovered). Here, a group consists of a collection of individual nodes. This model can be used to understand the important dynamic characteristics of a stochastic epidemic spreading over very large complex networks, being informative about the state of groups. Aggregating nodes by groups, the state space becomes smaller than the individual-based approach at the cost of aggregation error, which is strongly bounded by the isoperimetric inequality. We also develop a mean-field approximation of this framework to further reduce the state-space size. Finally, we extend the GgroupEM to multilayer networks. Since the group-based framework is computationally less expensive and faster than an individual-based framework, then this framework is useful when the simulation time is important.