The way caffeine and Adenosine work is that they block certain receptors in the brain that react to dopamine, which makes it slow down. This means, for example, that coffee does not give you energy, but rather, doesn’t let the brain realize it needs more energy. This is why people crash after caffeine. The effect goes away and all the tiredness catches up to you. Modafinil doesn't have that problem.
Its action is not really known yet, but it looks like instead of blocking the brain's dopamine processing, it just slows production of dopamine. On top of that, it also prevents the re-uptake of another neurotransmitter called noradrenaline, which triggers sleep. And one of the most mysterious result is that modafinil doesn't trigger sleep debt. People who stay awake for a day or two on modafinil don't report a need to catch up on sleep after the effect wears off. They can sleep the normal amount.