Project Structure
This section provides an overview of Project Structure.
Overview
Pine uses src
folder for project source code. Files outside of this folder are mostly configuration and setup files which are not required to be edited but can be as per needs.
├── composer.json
├── .env.example
├── .gitignore
├── .htaccess
├── index.php
├── LICENSE
├── package.json
├── pine
├── public\
├── README.md
├── src
│ ├── App\
│ ├── config\
│ ├── Controllers\
│ ├── Exceptions\
│ ├── resources\
│ ├── routes.php
│ └── views\
└── vite.config.js
Project Root
The project root has all the config files that you may find in most projects.
package.json
This file contains all the information about the JavaScript side of this application, from installed packages to how to run the application.
composer.json
Like package.json, this file contains all the information related to dependencies and packages on the PHP side.
.env.example
This file contains all the dotenv variables of the application.
Info:
The database variables are useless out of the box as no ORM is being used by Pine at the moment but they can be used if database connection and the likes are manually developed using for example MySqli or PDO.
.htaccess
An .htaccess
file (short for "hypertext access") is a configuration file used by the Apache HTTP Server to control server settings on a per-directory basis. It enables developers and website administrators to make configuration changes without directly modifying the server's main configuration file.
index.php
This file is basically the starting point of Pine. It includes all the files including configuration files and autoloaders and loads the routes.
pine
This is a helper file which helps the user in scaffolding code.
App
src/App
directory encapsulates Pine's internal code. It can be edited if needed. It has the following files
├── Controller.php
├── ErrorHandler.php
├── LeafTemplateEngine.php
├── LeafTemplateLexer.php
├── LeafTemplateParser.php
├── RequestBody.php
├── Request.php
├── Response.php
├── Route.php
├── Util.php
└── View.php
These files are what makes Pine possible. They can be tinkered and changed as per the needs but it is important to tread with caution as a minor wrong change can end up causing your project to crash.
config
src/config
directory contains all the internal configuration such as setting up an exception handler and making sure .env is being read.
Controllers
src/Controllers
directory has all the controllers in it as the name suggests. All controllers you will create will be placed in this directory. We use PascalCase
for naming controllers. For example, if you create a controller for users, it will be named UserController
. Of course, this is not a hard and fast rule and you are free to use which ever naming convention you prefer. Although, as a general rule, we would advise to use a consistent convention, whichever you may choose. This is to avoid any kind of confusion and have a clean code throughout.
Exceptions
src/Exceptions
directory has all the exceptions in it as the name suggests. All exceptions you will create will be placed in this directory. We use PascalCase
for naming exceptions. For example, if you create an exception for authorization, it will can be named UserNotAuthorizedException
.
resources
src/resources
directory contains all CSS and JS files. Vite uses the files in this directory and builds them into public
folder.
It has the following Structure
├── css
│ └── index.css
└── js
└── index.js
These files come with default code which you can remove for a fresh start.
views
src/views
directory contains all leaf files. Leaf is the HTML Template that Pine uses. This directory has an errors
subdirectory which contains pages for errors you may want to show the user.
├── controller.leaf.html
├── errors
│ ├── 403.leaf.html
│ ├── 404.leaf.html
│ ├── 500.leaf.html
│ └── debug.leaf.html
└── index.leaf.html
The errors directory is not optional and we recommend keeping it in to avoid ViewNotFound
exception if incase the user does encounter an error.