Folder structure
Frontend code resides by default in the src
folder placed in the root of the project. Everything gets compiled and assembled in the standard Laravel folders /resources
and /public
, whose content is gitignored.
Each path used in the build scripts can be overridden in the specific project package.json
file, but the ideal and default folder configuration assumed is the following:
#
Overview- All files marked with
**
are autogenerated by@acanto/laravel-scripts
initially, and can be customised afterward. - All files marked
autogenerated
are autogenerated by@acanto/laravel-scripts
on each run, they cannot be customised (TODO: maybe allow it).
Everything greyed out is gitignored.
Here in details:
#
bootstrapRefer to Laravel documentation. This folder is gitignored here.
#
configThe config directory contains all of your application's configuration files, see Laravel documentation. Unlike standard laravel you usually do not have many files here, but actually just one config/laravel-frontend.php
as Laravel Frontend will already includes all the typical config files you need. If something outside laravel-frontend
need to be overriden in your project, for instance to add some custom cached env
variables, you can create the same config file (with the same name, e.g. config/env.php
) and override or add just the keys you want, without redeclaring the ones already present. Your file will be merged on top of the default one provided by Laravel Frontend. See all configuration files in the source code.
#
publicRefer to Laravel documentation. Typically you should only have here your environment sensible .htaccess
files, these files are automatically generated if missing each time you run a workflow command from the acanto CLI. All the rest here is processed, compiled and gitignored.
#
resourcesRefer to Laravel documentation. It contains all processed blade templates and php files. This folder is gitignored
as all its typical files are put in src/
and processed before getting here.
#
srcAll the actual code of your project resides here.
#
src/assetsThis folders contains all static assets that gets manipulated, optimized and copied over the October's default public/assets
folder, they are divided as such:
#
src/assets/fontsAll fonts files, they will get automatically optimized, content hashed. An .htaccess
with long term expiration headers will be placed in this folder on build.
#
src/assets/imagesAll static theme images, they will get automatically optimized and copied with the same file name in the public/assets/images
folder. A content hashed version is also create when the image is used through webpack processing. An .htaccess
with long term expiration headers will be placed in this folder on build.
#
src/assets/images/placeholder.pngRequired image used as fallback for broken images.
#
src/assets/mediaAll static theme video, audio and other files, their filenames will not be hashed. No .htaccess
will be placed here.
#
src/assets/svgiconsAll svg icons that will be optimized and inlined in an automated component <x-svgicons/>
to be usually included in src/layouts/main/index.blade.php
. They will be later used in the templates by using the core component <x-icon id="arrow_left"/>
#
src/assets/favicon.pngRequired png image (1024x1024 is the optimal resolution) used to automatically generate all needed favicons. The script builds an automated <x-favicons/>
component to be usually included in src/layouts/main/index.blade.php
#
src/componentsThis folder contain components that are quite specific pieces of UI usually reused within the same project and that can, but not necessarily need, to be reused accross different projects. They should be responsible of specific functionalities and should be configurable from outside enought to allow their reuse in the same project. Usual use cases for components are pieces of UI like the Header
, the Footer
, Card
s, Slider
s, ecc.
Each component resides in its folder with a js/scss
index file, a blade
template and an optional php
class. For an in-depth documentation on how to component works in Blade refer to Laravel documentation.
Components folders by convention are named PascalCase, e.g. ProductDetail
following a React like syntax and differentiating from the core components that follow a kebab-case syntax. This means that you use components defined in this folder with <x-ProductDetail />
in your templates.
#
src/configThe scss
files here (functions.scss
, mixins.scss
, variables.scss
, placeholders.scss
) are always made automatically available to the whole project files. This is also the place where to put JavaScript global configurations such as breakpoints, various forms of data, URLs etc.
#
src/fragmentsIn the routes.php
you can define your custom routes and async endpoints (with the same degree of freedom you would have in the standard routes/web.php
and routes/api.php
of a typical Laravel installation). You are free to implement custom controllers and services here, all php
files will be copied as they are, without renaming, to the resources/fragments
folder. so the php namespace for each file here will be resources\fragments
.
#
src/middlwaresOptional folder containing your project's custom middlewares, see specific docs on how to create custom middlewares.
#
src/routesThis folder contains Routes code, each folder represent a route endpoint and is usually but not necessarily tight to a CMS API endpoint. If a route defined in the /api/structure
endpoint is missing in your codebase the start CLI command will auto-generate it, likewise it will warn when a route is defined in the codebase and missing in the CMS (although this can be completely fine it is better to know it). Each route folder here must contain an index.js
file that is used as an entrypoint for webpack to generate the static assets. This way route's code is always scoped and outputted only to its specific template. So by default JS and SCSS code written here cannot interfere with other routes.
Route folders are by convention all lowercase alphanumeric strings, e.g. singleproduct
, to allow having route error folders named as numbers only (src/routes/404/index.php
) their names are translated to Route404.php
once processed and put in the resources
folder, otherwise their controllers would result in invalid php class names.
#
src/servicesOptional folder containing your project's custom services, composers and providers, see specific docs on services.
#
src/utilsHere we can put js
and scss
utilities to use and import where needed from either layouts
, components
or routes
. This is also a good place for tiny utils templates .blade.php
if needed, they will be watched and copied over to the /resources
directory and therefore become available in templates to use with <x-utils-my-util />
#
src/vendorThis is the folder where to put custom vendor files that cannot for various reasons be added and managed by npm
. A common use case is the presence of the premium gsap
package that cannot be installed from the public npm
repository. In order to force using the local version of gsap
add the following below your dependencies in the package.json
:
Under the hood it will use npm-force-resolutions, included automatically as a dependency of @acanto/laravel-scripts
, to force using the version specified as resolution.