File structure

  

  

Let's take a look at the folder structure in a Magento 2 project.First of all, keep in mind that for development you will only be using one "app" folder and the composer.json and Composer.lock files.And that's it.All other files should be excluded from your repository..gitignore could be like this.As you can see, I excluded all the files, except "app/code" "app/design" and "app/etc" folders and composer.json and composer.lock files.And that's it.Actually, we can delete all other files and then run the composer install command and everything will work.Because all the files, except "app" folder and composer.json and composer.lock files can be restored by a composer or automatically generated by Magento.So let's check it.As you can see, we have only one folder "app".With some custom code, design, and configuration.We have .gitignore file and composer.json and composer.lock files.And that's it.So now we can run composer install command.And all the files will be restored.Let's check files.Looks like old files were downloaded.So let's check command line interface.Command Line works fine, and let's check storefront.Storefront works good too, so as you can see, we can use only one folder and two files.So let's review all of other folders. "app" folder.There are three main directories in this folder, which are "code", "design" and "etc." As we can see, we don't have "code" folder, so let's create it.This depends on your installation method.The code directory will be there in case you download the GitHub repository.Let's check it on official GitHub repository.So if you clone the code or download code from Magento, you will see all the Magento files in app code Magento directly.But if you use composer, You will see all of them in "vendor/magento" folder instead.In this case, all the Magento modules will be under "vendor" folderSo if we need to create some custom module, we have to create something like "VendorName/ModuleName" directory, and all of the custom logic will be placed here.All the files related to this particular module will be placed here too.So even JavaScript files or C S S files will be placed there too. "app/design" folder.You should save your custom store theme in the frontend "app/design" folder and the admin theme in the "app design admin html" subdirectory. The "Etc" folder contains the configuration we mentioned during installation, as well as other configuration values ​​for our project.For example "config.php" contains the list of all the enabled modules.At the same time, the "env.php" file contains credentials for the database and cache configuration.Let's move on to the next directory."Bin" directory.The executable Magento command line script is stored here.Using this file, Magento commands will be activated, which can be very useful.For example: clearing the cache, Enable/disable the cache, enable disable modules, reindexing, etc.And in general, you will always use this “bin/magento” command during development because it is very useful."dev" directoryMagento test scripts and a few tools for the development are placed in this folder.It also stores automated functional tests that were run by the Magento test framework.Actually, if you check the official Magento repository, you will find that all pull requests have been verified using functional, integration, unit and other types of tests.You can create your own test, for example a functional test based on the really useful Codeception framework.So it's pretty easy to create new functional tests.Let's move on to the next folder. "generated" directory.This is the place where Magento generated code is stored.If a class is injected in a constructor or you have created any plugin, Magento will automatically generate code to create a non-existent factory class or interceptor class.We will discuss this in detail a little later."lib" directory.this folder contains several libraries and is packaged separately from the Magento core.The internal directory contains server libraries and several font files.The "web" sub folder contains client-side JavaScript libraries like jQuery and Prototype. "PHP server" directory"PHP server" has "router.php" file which can be used to implement the PHP build-in server, but it's not really a good idea to use it.“pub”, as you noticed from the folder name, contains all public files such asJavaScript files C S S files, etc.So if we have added a JavaScript or C S S file to our folder, these files should be moved to the “pub” folder.The "setup" directory, this folder contains all the files related to installing the Magento, once the installation is complete you don't need this folder."Update" directoryThis folder contains modules that help Magento install all the dependencies."var" directory.This includes the generated cache, log files, and other temporary files.The "var/log" directory stores Magento log files. These are mainly Exception.log and system.log files. The "var/cache" directory contains Magento cache files. But this folder may be empty if you are using, for example, "Redis" as cache storage.And these were all the directories in the Magento project.
You have completed 0% of the lesson
0%