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/config
folder contains all your configuration files such as theapp/config/Dbh.php
short for Database Handler that manage the connection to your database. app/config/constants.php
contains all the defined constants mostly for errors and responses handling.- The
app/config/Middleware.php
is 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.php
class. app/config/Scripts.php
file provides information when certain commands are run in the terminal.app/config/Status.php
manages the state of the error handling and request responses.- The
app/core
folder contains all essential files and it is advisable to not modify its contents. - The
app/core/templates
folder contains all templates that the classapp/core/Make.php
will base off to create migration files, seeder classes, controllers and models with the help of custom script commands. app/core/Router.php
with the help ofapp/core/Request.php
,app/core/Response.php
andapp/core/Views.php
handle 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.php
handles the inclusion of all components automatically (static or dynamic) in a specific view with a specific layout.app/core/Migrations.php
handles the database and table migrations depending on the migrations files generated in yourapp/migrations
.app/core/Seeders.php
handles any data set to be seeded inapp/seeders
. Useful to have some data to work with when testing your application.- The
app/controllers
folder contains all the Web and API controllers, any generated controller through the commandcomposer make:controller
will end up here. - By default, an
app/controllers/AuthApiController
and anapp/controllers/UserApiController
are 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/WebController
is 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/models
folder contains all the models, any generated model through the commandcomposer make:controller
will 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/controllers
folders, it already contains anapp/controllers/AuthModel
and anapp/controllers/UserModel
. - The
app/migrations
folder 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/seeders
folder 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/views
folder 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/static
that 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/dynamic
attached 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
public
folder's root is where requests are redirected to thepublic/index.php
file 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
public
folder - The
css
folder will contain all your stylesheets (or compiled stylesheets from SASS/SCSS if used). - The
fonts
folder will contain all your fonts if hosted on the server to be used with the `@font-face` rule. - The
icons
folder will contain all your icons. - The
images
folder will contain all your image assets. - *You can use one folder for both your icons and images and structure it however fit.
- The
js
folder 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
scss
folder 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.