Documentation/Project structure

Project Structure

The HLEB2 framework implements a specific project directory structure, thus maintaining an agreement with the developer on which directories to store settings and classes necessary for the framework. It also allows developers to quickly understand the folder structure in a new project based on the HLEB2 framework.

The following diagram shows the folders of a new project after installing the framework:

app   - application code folder
     Bootstrap   - classes essential for managing the framework
     ⊢ Events   - actions for specific events
     |      ⊢ControllerEvent.php   - on controller initialization
     |      ⊢MiddlewareEvent.php   - on middleware initialization
     |      ⊢ModuleEvent.php   - on module controller call
     |      ⊢PageEvent.php   - on 'page' controller call
     |      ⊢TaskEvent.php   - when executing a command
     ⊢ Http
     |      ⊢ErrorContent.php   - content for HTTP errors
     |   ⊢BaseContainer.php   - container class
     |   ⊢ContainerFactory.php   - managing services in the container
     |   ⊢ContainerInterface.php   - container interface
     Commands   - folder with command classes
     |  ⊢DefaultTask.php   - empty template for creating a command
     |  ⊢RotateLogs.php   - command for log rotation
     Controllers   - folder for controller classes
     |  ⊢DefaultController.php   - empty template for creating a controller
     Middlewares   - folder for middleware
     |  ⊢DefaultMiddleware.php   - empty template for creating middleware
     Models
        ⊢DefaultModel.php   - empty template for creating a model
config   - configuration files
    ⊢common.php   - common settings
    ⊢database.php   - database settings
    ⊢main.php   - module-overridable settings
    ⊢system.php   - system settings
public   - public folder, where the web server should be pointed
     css   - public style files
     images   - public image files
     js   - public script files
     ⊢.htaccess   - server configuration
     ⊢favicon.ico
     ⊢index.php   - web server entry point
     ⊢robots.txt
resources   - custom project resources
     views   - view files (templates)
        ⊢default.php   - framework demo template
        ⊢error.php   - error page template
routes   - folder with route files
     ⊢map.php
storage   - storage folder, contains auxiliary files
     logs   - folder with log files
vendor   - folder with installed libraries
     phphleb   - folder with framework libraries
.gitignore   - Git visibility management for files
.hgignore   - Mercurial visibility management for files
composer.json   - Composer settings
console   - entry point for console commands
readme.md   - framework description

The files listed in the diagram are installed with the framework and are part of its structure, but are intended for modifications and filling by the developer. In addition to this, the developer can further develop the project according to this structure by adding new classes, folders, libraries, and more.

Unlike the previous version of the framework, there is now a new folder Bootstrap, which contains development classes that are tied to the core framework processes.
With these classes, the framework's operation is freed from unnecessary abstractions; previously, these classes were created from configuration, but now the developer can modify them directly at their discretion.


#app

The app folder is intended for the application code that is based on the framework.


#Bootstrap

This directory contains classes for creating containers and services, as well as others that serve as both editable classes and parts of the framework itself.


#Events

Contains classes responsible for handling specific events that occur during the processing of requests by the framework.


#Http

Includes the class ErrorContent.php for assigning custom content returned during HTTP errors.


#Commands

Here are commands to execute from the console or directly from the code. You can create custom commands based on the DefaultTask.php command template. The built-in framework commands are contained within the framework's code.


#Controllers

Folder for framework controllers. The template for creating a controller is the file DefaultController.php.

The controller is a part of the MVC architecture (Action-Domain-Responder for web), responsible for further managing the request processing that has already been identified by the router, but should not contain business logic.


#Middlewares

This directory is intended for middleware controllers, executed before or after a controller, which can be used only once in a route.


#Models

The folder is intended for Model classes.
The model is another part of the MVC architecture (Action-Domain-Responder for web), responsible for data.


#config

Configuration consists of PHP files containing the framework's settings.


#public

Public directory. Contains the file index.php as the entry point for the web server.


#resources

Intended for various auxiliary files.
This can include templates for pages or emails, as well as sources for compiling styles and scripts, etc.


#views

The view is a part of the MVC architecture (Action-Domain-Responder for web). This folder is intended for web page templates. Twig templates can also be stored here.


#routes

Routing is an important part of any web framework. This folder contains the file map.php, which holds the routing map of the framework.


#storage

Auxiliary files generated during the framework's operation.
Access permissions to this folder should allow full access for both the web server and a developer for terminal work.


#logs

Logs and error reports in a standardized format.


#console

This file without an extension contains PHP code and executes console commands. For example:

$php console --version

Displays information about the current version of the framework.

Framework Configuration Running on PHP Server

Page translated: chatgpt 4-o
Back to top