So, this has been bugging me for a while.
Consider the isothermal expansion of an ideal gas in a container. As the gas is allowed to expand, it does work on the surroundings which causes the temperature of the gas to drop. Since it is isothermal expansion, energy must flow via heat into the gas from the surroundings to maintain the temperature. The total change in entropy is given by
$$\mathrm dS_\text{total}=\mathrm dS_\mathrm{system}+\mathrm dS_\mathrm{surroundings}$$
Now, the entropy change for the system is
$$\mathrm dS_\mathrm{system}=\mathrm dS_\mathrm{produced}+\mathrm dS_\mathrm{exchanged}$$
where, $\mathrm dS_\mathrm{produced}$ is internally produced entropy in the system and $\mathrm dS_\mathrm{exchanged}$ is entropy change due to exchange of energy via heat.
Let the amount of heat exchanged be
$$\delta q_\mathrm{system}=-\delta q_\mathrm{surroundings},$$
so $\mathrm dS_\mathrm{exchanged}$ over the temperature $T$ is $$\frac{\delta q_\mathrm{system}}T=-\frac{\delta q_\mathrm{surroundings}}T$$
Then, $$\mathrm dS_\mathrm{total}=\mathrm dS_\mathrm{system}+\mathrm dS_\mathrm{surroundings}\\ =\mathrm dS_\mathrm{produced}+\frac{\delta q_\mathrm{system}}T-\frac{\delta q_\mathrm{surroundings}}T\\ =\mathrm dS_\mathrm{produced}$$
My question is that why should we account for the energy given via heat by surroundings which is $\frac{\delta q_\mathrm{system}}T$, to the system, as it is already used by the gas to maintain the temperature. For an irreversible isothermal expansion the internally produced entropy will be greater than zero due to increase in volume of the gas. But how will heat exchanged add to total entropy when it is only used to maintain the temperature of the system.