   routesFile: 'routes.yml'
   codeFilePattern: 'code/**/*.@(coffee|js)'
   i18nFilePattern: 'i18n/**/*.@(yml|yaml)'
+  viewFolderPattern: 'views/*.@(jade)'
   defaultHTTPMethod: '*' # can be get|put|post|delete|patch|all|*(is for all)
   debug: true
   encoding: 'utf8'
   moduleNamePattern: '^[a-zA-Z\\_\\-0-9]+$'
-  basedir: null
+  basedir: null # with `null` => process.cwd()
+  configOnLocals: true
+  defaultMountpoint: '/' # is able to contain a $module variable, e.g. '/$module'
+  expressjsSettings:
+    'view engine': 'jade'
 }
 
 _options = {}


exports.getTranslation = exports.getI18N

exports.applyOnApp = (app) ->
  modules = _modules
  options  = _options
  for route in _sortedRoutes
    routes = modules[route].routes.routes
    codeFiles = {}
    for file in modules[route].codeFiles
      #codeFiles[]
      key = file.replace(/^.*\/([^\\]+?)\.[^\.]+?$/, '$1')
      if codeFiles[key]
        throw Error("'#{file}' is an ambigious code file to '#{codeFiles[key]}'; files with identical name are not allowed")
      codeFiles[key] = file

    routes = modules[route].routes.routes



    for url, action of routes
      urlParts = url.match(/^((post|put|get|delete|patch|all|\*)\:)*(.+)$/i)
      if urlParts
        # e.g. POST:/about
        httpMethod = urlParts[2]?.toLowerCase() or 'all'
        httpMethod = 'all' if httpMethod is options.defaultHTTPMethod
        urlRule = urlParts[3]
        # e.g. index.about (index -> code file, about -> method)
        actionParts = action.match(/^([^\.]+)\.([^\.]+)/)
        codeFile = actionParts[1]
        method = actionParts[2]
        if actionParts and codeFile and method
          # abort if code file doesnt exists
          throw Error("Cannot find file '#{codeFile}' for route '#{url}' in module '#{route}'") unless codeFiles[codeFile]
          if method
            try
              app[httpMethod](urlRule, require(options.basedir+'/'+codeFiles[codeFile])[method])
            catch e
              throw Error("Cannot find method '#{method}' in file '#{codeFile}' for route '#{url}' in module '#{route}'")

  return app

exports.setOptions = (options) ->
  # apply options over default options
  _.extendOwn(_options, defaultConfig, options)
  _options.basedir ?= process.cwd()
  _options

exports.applyOnExpress = (instanceMethod) ->
  return @log.error('instanceMethod argument needs to be a function') if typeof instanceMethod isnt 'function'
  exports.buildModuleIndex()
  app = exports._applyOnInstanceMethod(instanceMethod)
  app.locals.config = @getConfig() if _options.configOnLocals
  return app

exports.log = {
  error:      ->
