Albatross does not impose any particular application structure. Following a standard structure makes a developer's life much easier. The standard application design for applications using a user interface is MVC, model-view-controller, and this is ideal for designing usable and maintainable Albatross applications.
Overview of MVC in Albatross
XXX Draw a little MVC diagram
The three components each have specific roles within the application:
- Controller
- The controller drives the application. In a typical request, it will load models into the session context, request that they be presented to the user, and when the user responds, it will carry out an appropriate action, say, to save the values back to the database, request more information from the user, or to move the application into the next state.
In an Albatross application, the controller is the state in a state machine. Each time the application moves to a different state -- say, from login, to item selection, to item detail -- the controller will move in a state transition using the set_page method.
The entry point for the Albatross application is usually in a file called app.cgi. It acts as the state machine controller and is the destination of CGI requests. It reads the request, sets up the session context, and then passes the request and the session context to the handler.
The initial state for the state machine is passed to the application's contructor which is used when there isn't an active session; when it already exists it is loaded along with the rest of the session's context. The session is stored on the server by the al-session-manager process.
- The controller drives the application. In a typical request, it will load models into the session context, request that they be presented to the user, and when the user responds, it will carry out an appropriate action, say, to save the values back to the database, request more information from the user, or to move the application into the next state.
- Model
- The model is the set of objects that the application deals with on the server. Typically they are stored in a database and the controller will coordinate loading them. This structure makes the models independent of the application itself so that they can be reused or tested independently of the application, say by unit testing.
- View
- In Albatross, the view is the .html page that contains the Albatross tags to display the information that was prepared by the controller and saved in the session context.
The clear separation of each of these roles within the application helps contain application complexity and improves reuse and reliability. The data store can be changed with minimal impact on the controller, additional states can be added, and the display presented to the user can be tailored (using CSS perhaps) without needing changes to the models or controller.
In practice it's hard to partition these three functions cleanly but it's worth striving for.
Application Directory Structure
XXX should follow MVC paradigm
How to design an Albatross application
Draw a state diagram for the application. Each state will represent a controller class which will manage the transitions.
Design the models required to hold and update the users' interactions with the web site and implement them appropriately.
Layout the pages to be presented to the user and implement them to display the models' information as provided in the session context.