It is established that the Illusionary World is a dimension adjacent to the one the characters reside in , as speculated by Kotomi's parents before their untimely demise. It is not bound by time and space, as travellers who come in are able to exit in a different time.
This IW can only be accessed when one possess the right conditions.
Yukine mentions of the Town legend of light orbs, which only appear when one attains a moment of happiness. Only a select few people are blessed to see and receive such orbs, and Tomoya is one of them.
While Yukine makes first mention of the light orbs after Tomoya sees and receives one, they can also be seen during Fuuko's "class" with Sanae-san (series 1, episode 8), Kotomi receiving her teddy bear (series 1, episode 14), and Misae-san spending time with her cat (AS, episode 6), as well as Tomoya reconciling with his father (AS, episode 19).
These light orbs then travel beyond the dimensional plane into IW, carrying the thoughts of happiness of these townspeople.
Yukine makes mention of light orbs existing long before everyone's time, so it can be speculated that this Illusionary World existed for time immemorial, granting miracles to other people, and thus is born the legend.
Now onwards to even more walls of text. IW=Illusionary World RW=Real World(Or at least the real world as it applies to Clannad)
Events not run "chronologically", as IW is not bound by time and space, but run in the order that they occur.
1. Akio runs to the big tree in the mystical open plain and makes a wish to save Nagisa. The Town grants him this miracle by using the light orbs within the IW to save her. But in turn, this binds her life to the town. In a way, the IW now "feeds off" from Nagisa's attachments towards the town, resulting in her fragile health.
2. Tomoya and Nagisa meet and fall in love. This unintentionally causes Nagisa's attachment to shift from the Town towards Tomoya, as a result, the IW would "extract" the lifeforce from Nagisa in order to maintain its existence. (Before Akio made the contract, the IW had always been just a container for the light orbs. )
3. Nagisa dies, and Ushio inherits Nagisa's contract with the Town.
4. Ushio dies.
5. Due to her unique existence with the IW, and her subconscious will to save her mother (this is mostly speculated), Ushio is reborn in the IW and binds her will to it. Though she loses her memories in RW.
6. Tomoya, either through death (from grief, suicide?) or through a very strong will, also arrives in the IW, as a light orb (also losing his memories in RW).
7. Ushio sensed an orb that somehow seems more sentient than the others, and thus creates a body for that orb (Tomoya/the Robot).
8. Both Ushio and the Robot begin their life in IW.
9. The Robot somehow remembers something, but can't exactly place what it is, and is compelled to want to take Ushio out of the IW. As Ushio's will integrates even more with the IW, winter arrives.
10. Ushio now remembers part of her memories in RW and her desire to save her mother.
11. Ushio tells the Robot (Tomoya) about the light orbs, and sends him back in time, back to when Tomoya first met Nagisa, in order to collect as many orbs as possible.
12. Tomoya returns to that point in RW, but loses his memories in IW. Ushio becomes one with the IW, collecting the orbs as Tomoya receives them in various alternate timelines.
13. In the various alternate realities (as seen in the game, and in the DVD special episode 24, where Tomoya ends up with Tomoyo instead), Tomoya collects the various light orbs for every happiness he, or someone else he helps, attains.
14. Ushio in turns receives them, and "resets" the world to that point for every orb collected so that Tomoya may go and collect more. As there are more orbs, the IW regains its ability to sustain itself.
(Points 15-17 in the original refers to mechanics more relevant to the game players than the anime watchers, which I feel would be redundant, so I'll skip to point 18)
18. And finally, Tomoya enters the timeline we see in the anime, where he meets and marries Nagisa. Nagisa still dies in this timeline, but he still manages to collect a few more orbs before coming to RW Ushio's death.
19. As Tomoya now collected quite a lot of orbs, IW Ushio is now able to perform the miracle by sending Tomoya back to when RW Ushio is born, and with the power of the orbs, saves Nagisa's life again.
20. As history has been altered, the Ushio born in this RW is considered a different person than IW Ushio (though their souls are linked, think Tsubasa Chronicle for this one, i.e. same soul, different bodies).
21. Due to the family love created by the Okazakis, the IW is able to sustain itself, and RW Ushio no longer falls ill.
22. Her task completed, IW Ushio travels back to RW, where her soul "fuses" with RW Ushio, and she is found sleeping under the tree.
So while the anime never conveyed this point well. Thats the best explanation of it I can give.