Skip to content
Robert Lynch edited this page Sep 3, 2015 · 3 revisions

Nucleus follows a rough MVC paradigm, with a top level router, models to contol database access, views in the form of XHP, and controllers which handle the bulk of the logic.

The Router

All app requests start at app.php in the root of the project. This is done via the Nginx rule described above. From there, all services are setup, such as the Session manager, DB interface class, and Email system. This is also where the autoloader is brought into context. So that a manual "require" is not needed each time you use a class, they're simply required on usage by the autoloader from composer. Once all this is done, the Route class is called, which lives in lib/Route.php. This class includes the URIMap which was generated with robo, which maps a request path to a controller. Once a controller is selected, it is instanciated, the configurations are retreived and verified, and the controller is delegated.

The Controller

Controllers are the powerhouses behind Nucleus; they carry the bulk of the logic and create the views which render into either HTML or JSON. All controllers extend BaseController, which requires them to define a method getPath. This method will return the path the controller will respond to requests on, and is used by the build step in robo to generte the URI map. Additionally, a controller can define a getConfig option, which allows the controller to specify things like the required user state or roles to view that controller.

A controller has the option to return either an :xhp object, which will render into HTML in the main view, or a Map, which will return a JSON object. Typically, only API endpoints should return JSON.

The Model

A model is a simple object which defines ways to retreive and populate an object from the database, and mutations to update the data in the database. They are the main way to interact with the database, and most SQL queries should be contained within them.

Clone this wiki locally