Before an Idylle application starts, it loads components in a specific order.
Illustration describing the full setup of an Idylle Application.
For each step, if a promise is returned, idylle will wait the Promise to be resolve to continue. If a Promise is rejected during the init process. The application won't start.
Going with the flow
By default Idylle will requirerecursively all files in specific directories for each step.
It means you dont have anything to do except to put your files at the right place. Idylle will load each of them automatically.
As an example, an action with the path actions/users/create.js will be available through app.actions.users.create()
Customizing the flow
For each step of the flow, you can subscribe to events to customize the behavior.
When you register one listener in the phase, you automatically disable the recursive require made by Idylle.
Note that you can subscribe multiple time to the same event if you want to split responsibilities.
1. The dependencies
Each of these dependencies will be used during the lifecycle of the application. To understand the responsibility of each of these components check CriteriaBuilder, ResponseHandler, ErrorHandler documentation.
2. The settings
The settings loading phase is the only step where the app object is not injected.
When it comes to configure the server, you need to listen on a specific event Core.events.init.settings.
3. The models
Loading the models is associated to Core.events.init.models.
4. The middlewares
Loading the middlewares is associated to Core.events.init.middlewares.
5. The Actions
Loading the actions is associated to Core.events.init.actions.
6. The Routes
Loading the routes is associated to Core.events.init.routes.
7. The Boot
Booting phase is associated to Core.events.booting.
8. The Post Start
Post start phase is associated to Core.events.started.
Conclusion
As you can see it is very easy to customize the initialization of an Idylle application. Most of the time you will keep the default behavior, but since Idylle will require all the files in specific paths from the Node Working Directory (CWD), when you build a library with Idylle, you might want to explicitly load directories.