Directory Structure
The structure is based of the MVC design pattern, with an app folder containing the backend side of your application (config, core, middleware, controllers, models, views etc...). The public folder is the frontend side of your structure with an public/index.php file that runs the appplication and where you define your routes and endpoints.
All classes are namespaced and autoloaded with composer with the PSR-4 autoloading standart.
StackSync comes included with a SASS architecture based on the 7-1 architecture and make use of JavaScripts native ES6 modules. If you're only a backend developer and don't intend on using or learning these methods, and wish to either work normally or with a CSS framework, you can safely delete the scss folder (and clear the js folder if necessary) and use the css folder for your styling normally as it does not interfere with how the framework works and is optional.
The Root Directory
Your root directory will contain an Application.php file that initializes your app and gets called in public/index.php to run.
The .htaccess file redirects any request to the public folder.
A .env file with all your environement variables configured. If not refer to the Configuration section.
The composer.json file contains various informations about the mini-framework and all the available scripts/commands. Under the config section, the `process-timeout` setting is by default at `3600` (which means scripts will timeout after one hour). It can be safely modified to `0` if one wishes no interruptions when the local server is running for example.
The App Directory
- The
app/configfolder contains all your configuration files such as theapp/config/Dbh.phpshort for Database Handler that manage the connection to your database. app/config/constants.phpcontains all the defined constants mostly for errors and responses handling.- The
app/config/Middleware.phpis the heart of the custom API system, it handles everything from requests, content-type, authorization header and token. Validates and sanitizes the data, processes methods and parameters for the controllers with the help of theapp/config/Process.phpclass. app/config/Scripts.phpfile provides information when certain commands are run in the terminal.app/config/Status.phpmanages the state of the error handling and request responses.- The
app/corefolder contains all essential files and it is advisable to not modify its contents. - The
app/core/templatesfolder contains all templates that the classapp/core/Make.phpwill base off to create migration files, seeder classes, controllers and models with the help of custom script commands. app/core/Router.phpwith the help ofapp/core/Request.php,app/core/Response.phpandapp/core/Views.phphandle any request made to Web side of your application and resolve it to render a view depending on your views setup (layouts and components for each page).app/core/Components.phphandles the inclusion of all components automatically (static or dynamic) in a specific view with a specific layout.app/core/Migrations.phphandles the database and table migrations depending on the migrations files generated in yourapp/migrations.app/core/Seeders.phphandles any data set to be seeded inapp/seeders. Useful to have some data to work with when testing your application.- The
app/controllersfolder contains all the Web and API controllers, any generated controller through the commandcomposer make:controllerwill end up here. - By default, an
app/controllers/AuthApiControllerand anapp/controllers/UserApiControllerare included and should not be removed or modified (unless some columns where added in the `user` table, then some changes could be made reguarding the data sent and the MySQL statements in the model). For each `ApiController`, a route must be defined (which is an endpoint in this case) inpublic/index.php, with it's respective processMethod inapp/config/Process.php. - The
app/controllers/WebControlleris the only and main controller for handling the Web side of your application, it contains the methods for rendering a view under a certain layout. Any new method added for a view must have a defined route inpublic/index.php. - The
app/modelsfolder contains all the models, any generated model through the commandcomposer make:controllerwill end up here (models are created at the same time of a controlled since they rely on each other). - As it is with the
app/controllersfolders, it already contains anapp/controllers/AuthModeland anapp/controllers/UserModel. - The
app/migrationsfolder contains all the generated migrations through the commandcomposer make:migration. - Currently there's two types of migrations: create a table and update a table. All migrations file begin with a prefix and an id (ex: m0001, m0002) that determines their order of execution through the command
composer migrate:apply - You can drop your currently applied migrations anytime with the command
composer migrate:drop. Keep in mind that this command will drop all tables generated through migrations, but any table created normally will not be affected. - The
app/seedersfolder contains all the generated seeders through the commandcomposer make:seeder. - Any newly created seeder should have it's respective method added in the
app/seeders/DatabaseSeeder.php`seedDatabase` method to be able to run all seeders with the commandcomposer seed:all. - A command to seed to the `user` table is already setup
composer seed:user. To run other seeders separately, a command for it must be added under the `scripts` section incomposer.json. - The
app/viewsfolder is where all your elements that will render a view depending on different factors. - Each requested view through a defined route will have a layout attached to it. You can modify the base layout or create others under the
app/views/layouts. - Layouts are considered the base architecture of the view and can contain static components
app/views/components/staticthat will be present in all views under the specified layout. - Static components are wrapped inside double brackets
[[ static ]]. - A head tag static component is essential and already exists in
app/views/components/static/head.php. It should be customized and included in all layouts between the head tags. - A views content will be different depending on which route is requested, it is advisable to name your route and view method with the same name of your view content file under
app/views. - The view content is defined inside the layout as a string wrapped inside double parentheses
(( content )). - Each view content can have dynamic components
app/views/components/dynamicattached to them and are not part of the layout. That means they are not going to be present in all pages unless they are defined in all views with a certain layout. - Dynamic components are wrapped inside double curly braces
{{ dynamic }}.
Config:
Core:
Controllers:
Models:
Migrations:
Seeders:
Views:
The Public Directory
- The
publicfolder's root is where requests are redirected to thepublic/index.phpfile and where all your frontend folders and files reside, any frontend library (jQuery, Bootstrap etc...) needed should be installed under this directory. - Your favicons should also be under the root of the
publicfolder - The
cssfolder will contain all your stylesheets (or compiled stylesheets from SASS/SCSS if used). - The
fontsfolder will contain all your fonts if hosted on the server to be used with the `@font-face` rule. - The
iconsfolder will contain all your icons. - The
imagesfolder will contain all your image assets. - *You can use one folder for both your icons and images and structure it however fit.
- The
jsfolder will contain all your JavaScript files. By default you will find a structure made for the use of JavaScript's native ES6 modules that can be deleted if planning on using normal JavaScript or some libraries like jQuery or other. - The
scssfolder will contain a SASS/SCSS Architecture based on the 7-1 architecture. The use of SASS/SCSS is optional and this folder can be deleted safely.