Magento Backend Tutorial – Application Directory Structure / Coding Standards

Application Directory Structure

  • app – core & extended application code, templates, layout, translation, configuration.
    • app/code – application code (see more: code pools).
    • app/design – frontend and admin templates & layout XML files.
    • app/etc – system configuration files (ex. database connection), and module declaration (pools, namespaces, and dependencies).
    • app/locale – localization.
  • js – JavaScript libraries (ex. Prototype). Do not put skin specific JavaScript files into this directory.
  • lib – PHP libraries which Magento, or its modules, depend upon (ex. Zend Framework).
  • media – storage of product images, category images, CMS WYSIWYG, etc.
  • skin – CSS, JS, and images that are unique to a given theme.
  • var – dynamically created system files (ex. cache, FPC, sessions, index locking).

Coding Standards

  • Do not write raw SQL queries.
  • Do not execute SQL queries inside a loop.
  • Do not directly instantiate classes (ex. new Mage_Catalog_Helper_Data).
  • Minimize collection loading (ex. avoid addAttributeToSelect(‘*’)).
  • Do not use PHP superglobal arrays (ex. use Mage::app()->getRequest()->getPost() instead of $_POST).
  • Choose observers over overwriting core classes whenever possible (see more: list of events).