File structure

Dotkernel API follows the PSR-4 standards.

It is a good practice to standardize the file structure of projects.

When using Dotkernel API the following structure is installed by default:

Dotkernel API File Structure!

Main directories

  • bin - executable files from CLI
  • config - various configuration files
  • data - should contain project-related data (AVOID storing sensitive data on VCS)
  • documentation - should contain project-related documentation
  • log - storage of log files generated by dot-error-log library
  • public - publicly visible files. The webserver need to have this folder as www-document root folder.
  • src - should contain the source code files
  • test - should contain the test files

Special purpose folders

  • .github - containes workflow files
  • .laminas-ci - contains laminas-ci workflow files

bin directory

This directory contents are

  • clear-config-cache.php which removes the config cache file (data/cache/config-cache.php - available only when development mode is enabled).
  • cli.php used to build console applications based on laminas-cli
  • doctrine used by the doctrine fixtures to populate the database tables

config directory

This directory contains all application-related config files:

  • cli-config.php: command line interface configuration used by migrations, fixtures, crons
  • config.php: registers ConfigProviders for installing packages
  • container.php: main service container that provides access to all registered services
  • development.config.php.dist: activates debug mode; gets symlinked as development.config.php when enabling development mode
  • migrations.php: configuration for database migration, like migration file location and table to save the migration log
  • pipeline.php: contains a list of middlewares, in the order of their execution
  • twig-cs-fixer.php: configuration file for Twig code style checker/fixer

config/autoload directory

This directory contains all service-related local and global config files:

  • authorization.global.php: configures access per route for user roles
  • cli.global.php: configures cli
  • content-negotiation.global.php: configures request and response formats
  • cors.local.php.dist: configures Cross-Origin Resource Sharing, like call origin, headers, cookies
  • dependencies.global.php: config file to set global dependencies that should be accessible by all modules
  • development.local.php.dist: gets symlinked as development.local.php when enabling development mode - activates error handlers
  • doctrine.global.php: configuration used by Object–relational mapping
  • error-handling.global.php: configures and activates error logs
  • local.php.dist: local config file where you can overwrite application name and URL
  • local.test.php.dist: local configuration for functional tests
  • mail.local.php.dist: mail configuration; e.g. sendmail vs smtp, message configuration, mail logging
  • mezzio.global.php: Mezzio core config file
  • mezzio-tooling-factories.global.php: add or remove factory definitions
  • response-header.global.php: defines headers per route
  • templates.global.php: dotkernel/dot-twigrenderer config file

data directory

This directory is a storage for project data files and service caches. It contains these folders:

  • cache: cache for e.g. Twig files
  • doctrine: database migrations and fixtures
  • oauth: encryption, private and public keys needed for authentication
  • data/lock - lock files generated by dotkernel/dot-cli

AVOID storing sensitive data on VCS.

log directory

This directory stores daily log files. When you access the application from the browser, (if not already created) a new log file gets created in the format specified in the config/autoload/error-handling.global.php config file under the stream array key.

public directory

This directory contains all publicly available assets and serves as the entry point of the application:

  • uploads: a folder that normally contains files uploaded via the application
  • .htaccess: server configuration file used by Apache web server; it enables the URL rewrite functionality
  • index.php: the application's main entry point
  • robots.txt.dist: a sample robots.txt file that allows/denies bot access to certain areas of your application; activate it by duplicating the file as robots.txt and comment out the lines that don't match your environment

src directory

This folder contains a separate folder for each Module. Each Module folder, in turn, should contain following directories, unless they are empty:

  • Handler - Action classes (similar to Controllers but can only perform one action)
  • Entity - Used by database entities
  • Service - Service classes
  • Collection - Database entities collections
  • Repository - Entity repository folder

The above example is just some of the directories a project may include, but they should give you an idea about the recommended structure.

Other classes in the src directory may include InputFilter, EventListener, Helper, Command, Factory etc.

The src directory normally also contains these files:

  • ConfigProvider.php - Configuration data for the module
  • OpenAPI.php - Detailed descriptions for each endpoint in the OpenAPI format
  • RoutesDelegator.php - Module specific route registrations Module main routes entry file

templates directory

This directory contains the template files, used for example to help render e-mail templates.

Dotkernel API uses twig as Templating Engine. All template files have the extension .html.twig