Directory Structure
Introduction
The default application structure is intended to provide a great starting point for both large and small applications. Radiate imposes almost no restrictions on where any given class is located - as long as Composer can autoload the class.
The theme and plugin directories have been implemented almost identically to allow for less cognitive load when switching between plugin and theme development. There are some exceptions however, and these are down to the way WordPress implements themes and plugins differently.
.
├── app/
│ └── Providers/
│ ├── EventServiceProvider.php
│ ├── RouteServiceProvider.php
│ ├── ThemeServiceProvider.php
│ └── WordPressServiceProvider.php
├── config/
├── routes/
│ ├── ajax.php
│ └── api.php
├── vendor/
├── composer.json
├── functions.php
├── helpers.php
├── index.php
├── LICENSE
├── package.json
├── README.md
├── screenshot.png
└── style.css
The Root Directory
The App Directory
The app
directory is where the core of your application will be located. We'll explore the app directory in more detail further on. This directory is where most of your classes will be located. Classes in the app
directory are namespaced Theme
or Plugin
as per the project type.
The Config Directory
As the name suggests, the config
directory contains all the framework configuration files. These files handle the configurations that aren't handled by WordPress, for example, where to store your template files.
The Routes Directory
The routes directory is where your AJAX and REST routes are registered.
ajax.php
This is where the AJAX routes are registered. They automatically have the
ajax
middleware applied. For more information about Radiate's routing, see The default route files.api.php
This is where the REST API routes are registered. They are automatically namespaced and have the
api
middleware applied.
The Vendor Directory
The vendor
directory contains your composer dependencies.
The Root Files
The Radiate Theme
and Plugin
both contain a few files in the root directory, but files of note are:
functions.php
The entry point for themes and plugins. This is where Radiate registers the middleware and service providers before booting.
helpers.php
Add any application helper functions here. This file is autoloaded by Composer. Radiate doesn't use helper functions as they can cause conflicts with other themes or plugins running on your site. We recommend namespacing your helper functions to avoid this issue.
The App Directory In Detail
The majority of your application is housed in the app
directory. By default, this directory is namespaced under Theme
and Plugin
and is autoloaded by Composer using the PSR-4 autoloading standard.
The app directory contains a Providers
directory by default. This directory contains your application service providers such as the EventServiceProvider
where your WordPress actions/filters can be declared, and the RouteServiceProvider
where your REST and AJAX routes can be configured.
A variety of other directories will be generated inside the app
directory as you use the make
Radiate commands to generate classes. So, for example, the app/Mail
directory will not exist until you execute the make:mail
Radiate command to generate a mail class.
Many of the classes in the app
directory can be generated by Radiate via the wp-cli
. To review the available commands, run the wp radiate list
command in your terminal.
Console
The Console
directory contains any custom Radiate commands that you create. The directory does not exist by default, but will be created for you by the make:command
Radiate command.
Events
The Events
directory does not exist by default, but will be created for you by the make:event
Radiate command.
Http
The Http
directory contains your controllers and middleware. Almost all of the logic to handle REST and AJAX requests entering your application will be placed in this directory.
Listeners
This directory does not exist by default, but will be created for you if you execute the make:listener
and make:subscriber
Radiate commands. The Listeners
directory contains the classes that handle your events. Events extend WordPress actions and filters which helps keep all action/filter logic in one place.
This directory does not exist by default, but will be created for you if you execute the make:mail
Radiate command. The Mail
directory contains all of your classes that represent emails sent by your application.
Providers
The Providers
directory contains all of the service providers for your application. Service providers bootstrap your application by binding services in the service container, registering events, or performing any other tasks to prepare your application for incoming requests.
Rules
The Rules
directory contains custom validation rules generated with the make:rule
Radiate command. This directory doesn't exist by default.
WordPress
The WordPress
directory contains the classes that register functionality in WordPress. This directory doesn't exist by default, but will be created when executing make:post-type
, make:taxonomy
or make:shortcode
Radiate commands.