Application Structure

To make the most of PHPFast, you should understand its default structure and learn how to customize it to fit your application's needs.

Default Directories

A fresh installation includes five key directories:

  • application

  • public

  • system

  • vendor

  • writable

Each directory serves a specific purpose within the framework.

application

The application directory is where all of your application code lives. This comes with a default directory structure that works well for many applications.

The following folders make up the basic contents:

PHP-Fast follows a well-organized directory structure to keep the application clean and modular. Here's a detailed breakdown of each directory and its purpose:

ROOT
├── application/                     # Application-specific files
│   ├── Blocks/                      # UI blocks (footer, header, content)
│   │   ├── Footer/                  # Footer block
│   │   ├── Frontend/                # Head block 
│   │   │   ├── Header/              # Header block (nav, logo)
│   │   │   ├── Pagination/          # Pagination block
│   │   │   └── Content/             # Content block
│   │   │       ├── Views/           # Content layouts
│   │   │       │   ├── layout_1.php # Layout 1
│   │   │       │   ├── layout_2.php # Layout 2
│   │   │       │   └── layout_3.php # Layout 3
│   │   │       └── ContentBlock.php # Content block logic
│   │   ├── Head/                    # Head block (meta, CSS, JS)
│   │   └── Schema/                  # Schema block
│   ├── Config/                      # Configuration files
│   │   └── Config.php               # Main configuration file
│   ├── Controllers/                 # Controllers for handling requests
│   │   ├── Api/                     # API-related Controllers
│   │   │   └── UsersController.php  # Controller for user-related API
│   │   ├── Backend/                 # Folder contains controller in bacend
│   │   │   ├── HomeController.php   # Controller for home page in backend
│   │   │   └── UsersController.php  # Controller for user page in backend
│   │   ├── BackendController.php    # Frontnend controller for web requests
│   │   ├── Frontend/                # Folder contains controllers in frontend
│   │   │   ├── HomeController.php   # Controller for home page in frontend
│   │   │   └── UsersController.php  # Controller for user page in frontend
│   │   └── FrontendController.php   # Frontnend controller for web requests
│   ├── Helpers/                     # Store collections of standalone functions
│   │   ├── Backend_helper.php       # Backend helper functions
│   │   └── Frontend_helper.php      # Frontend helper functions
│   ├── Languages/                   # Manages multi-language support
│   │   ├── en/                      # English version
│   │   │   ├── Home.php/            # Home English version
│   │   │   └── Posts.php/           # Posts Vietnamese version
│   │   └── vi/                      # Vietnamese version
│   │       ├── Home.php/            # Home English version
│   │       └── Posts.php/           # Posts Vietnamese version
│   ├── Librabries/                  # Managing custom or built-in libraries
│   │   ├── FastLang.php             # Handles languages custom
│   │   ├── FastMail.php             # Handles mail
│   │   ├── FastToken.php            # Handles token 
│   │   └── iMagify.php              # Handles images 
│   ├── Middleware/                  # Custom middleware for request handling
│   │   ├── AuthMiddleware.php       # Handles authentication
│   │   └── PermissionMiddleware.php # Handles user permissions
│   ├── Models/                      # Models for database interactions
│   │   ├── UsersModel.php           # Model for interacting with the users table
│   │   └── PostsModel.php           # Model for interacting with the posts table
│   ├── Routes/                      # Route definitions
│   │   ├── Api.php                  # API route definitions
│   │   └── Web.php                  # Web route definitions
│   └── Views/                       # Views for frontend and backend
│       ├── default/                 # Default theme
│       │    ├── Backend/            # Backend views
│       │    └── Frontend/           # Frontend views (assets, php files)
│       │        ├── Assets/         # Frontend assets (CSS, JS)
│       │        │   ├── css/        # CSS files
│       │        │   └── js/         # JS files
│       │        └── home_index.php  # Homepage view
│       └── theme_custom             # Custom theme  

public

The public folder is the main access point for your web application. It makes sure that only files meant for the browser (like images, CSS, and JavaScript) are visible while keeping your source code safe.

This folder contains important files like .htaccess, index.php, and other assets needed for the website to work properly.

Since it acts as the web root (the main folder your site runs from), your web server should be set to use this folder. This setup keeps your project organized and improves security.

ROOT
├── public/                       # Publicly accessible directory (document root)
│   ├── .htaccess                 # Apache configuration for URL rewriting
│   └── index.php                 # Entry point for all HTTP requests

system

This folder contains the core files of the framework. While you can customize the application folder as needed, you should not modify anything inside the system folder.

If you need to change how the framework works, it's best to extend existing classes or create new ones instead of directly editing these core files. This ensures your application remains stable and easy to update.

ROOT
├── system/                          # Core framework files
│   ├── Commands/                    # Command-line tools
│   │   ├── BlockCommand.php         # CLI command to create Blocks
│   │   ├── ControllersCommand.php   # CLI command to create Controllers
│   │   ├── ModelsCommand.php        # CLI command to create Models
│   │   └── TableCommand.php         # CLI command to sync database tables
│   ├── Core/                        # Core system files of the framework
│   │   ├── AppException.php         # Custom exception handler
│   │   ├── BaseController.php       # Base class for all Controllers
│   │   ├── BaseBlock.php            # Base class for all Blockks
│   │   ├── BaseModel.php            # Base class for all Models
│   │   ├── Bootstrap.php            # Framework initialization and routing
│   │   ├── Middleware.php           # Base class for middleware
│   │   └── Router.php               # Handles routing and directs requests
│   ├── Drivers/                     # Drivers for handling caching and databases
│   │   ├── Cache/                   # Cache handling
│   │   │   ├── Cache.php            # Base cache class
│   │   │   ├── FilesCache.php       # File-based caching implementation
│   │   │   └── RedisCache.php       # Redis-based caching implementation
│   │   │   └── UriCache.php         # Uri-based caching implementation
│   │   ├── Database/                # Database handling
│   │   │   ├── Database.php         # Base database class
│   │   │   ├── MongodbDriver.php      # Mongodb-specific database driver
│   │   │   ├── MysqlDriver.php      # MySQL-specific database driver
│   │   │   └── PostgresqlDriver.php # PostgreSQL-specific database driver
│   ├── Helpers/                     # Helper functions for various tasks
│   │   ├── Core_helper.php          # Core helper functions
│   │   ├── Security_helper.php      # Security-related helper functions
│   │   ├── String_helper.php        # String-related helper functions
│   │   └── Uri_helper.php           # URL-related helper functions
│   └── Libraries/                   # Common system libraries
│       ├── Assets.php               # Asset management (e.g., CSS, JS)
│       ├── Assets.php               # Events management
│       ├── Logger.php               # Logging utility
│       ├── Monitor.php              # Performance monitoring utility
│       ├── Render.php               # View rendering and layout handling
│       ├── Security.php             # Security functions
│       ├── Session.php              # Session management
│       ├── TaskQueue.php            # Handle asynchronous jobs
│       ├── Template.php             # Template handling utility
│       └── Validate.php             # Input validation functions

vendor

folder is where third-party packages and dependencies are stored, managed by Composer (a dependency manager for PHP).

ROOT
├── vendor/                       # Composer-installed third-party libraries
│   ├── composer/
│   │   └── autoload.php          # Composer autoloader
└── composer.json

writable

This folder stores files that your application needs to write to while running. It includes directories for cache files, logs, and user uploads.

If your application needs to save other types of files, you should create additional directories here. Keeping all writable files in one place helps improve security, as it allows you to keep the rest of your project files read-only.

ROOT
├── writeable/                    # Writable directory for logs, uploads, etc.
│   ├── cache/
│   ├── logs/
│   │   ├── logger.log            # Log file for application logs

Last updated

Was this helpful?