The LAMP Platform

The Sahana Architecture is based on LAMP (GNU/Linux, Apache, MySQL and PHP/Perl), which is a mature FOSS stack ensuring the software is “Free” end to end. Most of the Sahana development is done in PHP, however there are some tools and configurations scripts for the admin and developers that are written in Perl.

High level Sahana Architecture

Sahana has a pluggable modular architecture. Most of it's functionality comes in the form of add on modules which are dynamically picked up as soon as they are uncompressed in the right directories. To achive this automation we use certain naming conventions in the module filenames and function names. Based on the convention you use a module can become a application module (use <mod>/, an admin (e.g. <mod>/ module or have aspects of both [ see module convention for more information. ]

To achieve this automation, Sahana uses the front controller pattern. What this means is that all requests to the application is controlled by the main /www/index.php file, which in turn process the requests, performs authentication/authorization, ensure the database connection is available, loads all configuration variables and finally redirects to the module for further processing. The front controller also places certain default blocks on the page such as the HTML head, page header/footer, mainmenu, login. However all these sections can be overridden by the module if required by using certain function naming [ see module convention to see how this work ]. What this means for the module developer as with most frameworks is that they get to focus on writing the module to the application requirements without wasting time redoing things like authentication.

KISS "Keep It Simple Stupid"

As a team we follow the “KISS” philosophy. For example when creating the framework we have made sure that keep this as close to normal PHP as possible (few abstraction layers) and have tried our best to allow you to escape it and do something completely different. The reason for this is to reduce the learning curve, makeing the application easy to customize/maintain and to encourage more developers to join the team.

However to help you expedite the development of your module, you will find loads of useful library functions and template handlers (snippets of code to ease the creation of blocks of HTML code) in the library /inc/ directory [ see directory convention for more info ]. Not all these libraries are documented so going through the function descriptions might be the best way to do it, however we have documented some of the important ones in design. The most important two to review are the form_handler and the navigation_handler.

Workings of the Front Controller

The most important POST/GET variables processed by the Front controller are

  • mod - which gives the modules name to redirect to
  • act - which gives the respective action to be performed on the module

All other POST variables are passed to the module for processing. Some common ones are:

  • actseq - normally used to step through a series of forms for a common action type in the module

Front controller execution

The steps followed in a typical execution of the front controller is as folloes

  • Browser send a request to Front controller with mod and act POST/GET variables set
  • Front controller checks if Sahana is installed properly and redirects to setup if not
if ($conf['sahana_status'] == 'installed' ) {

} else { // Launch the web setup
    require ($global['approot'].'inst/');
  • Setup the session, database connection, locale setting,
require_once ($global['approot'].'inc/');
require_once ($global['approot'].'inc/lib_session/');
require_once ($global['approot'].'inc/lib_locale/');
  • Initialize global variables and extract module and action called from request
  • Authenticate and authorize the user
  $allow = (shn_acl_check_perms_action($_SESSION['user_id'],$req_act) ||
             !$acl_enabled)? true : false;
  • Set main/module and database configuration variables
  • Include HTML head, header, navigation if not overridden

shn_include_page_section('html_head', $module);

  • Dynamically include relevant module file (mod/<mod name>/ )
  • Include HTML footer if not overridden

  • Navigate