Project structure
A Magento project consists of a dozen folders, but a developer writes code in only two of them. The rest hold the core, settings and files that Magento creates itself. It helps to learn right away what may be changed and what may not.
Project root
shop/
├── app/
│ ├── code/ your modules
│ ├── design/ your themes
│ └── etc/ installation settings
├── bin/magento the console command
├── generated/ generated classes
├── pub/ the site root
├── var/ cache, logs, error reports
├── vendor/ the core and third-party packages
└── composer.json the list of packagesWhat lives where
| Folder | What is in it | May you change it |
|---|---|---|
app/code | Your modules: app/code/Vendor/Module | Yes, all the work happens here |
app/design | Your themes | Yes |
app/etc | The env.php and config.php files | With care |
vendor/magento | Core modules | No |
generated | Classes created by Magento | No, only delete |
pub/static | Built styles, scripts and theme images | No, only delete |
pub/media | Uploaded product images | No |
var | Cache, logs in var/log | No, only read and delete |
The app/code folder may be missing right after installation — create it by hand.
Files in app/etc
The app/etc/env.php file stores server settings: database access, the admin address, the encryption key. It is different on every server and is not added to version control.
The app/etc/config.php file holds the list of modules and whether each one is enabled:
// app/etc/config.php
return [
'modules' => [
'Magento_Store' => 1,
'Magento_Catalog' => 1,
'Acme_Hello' => 1,
],
];A one means the module is enabled. The file is changed by bin/magento commands, not by a person, and is stored together with the project code.
Core modules
The core consists of the same kind of modules as the one you are about to write. The product catalog lives in vendor/magento/module-catalog, orders in vendor/magento/module-sales. In code the catalog module is called Magento_Catalog, and its classes start with Magento\Catalog.
These folders are worth reading: when it is unclear how an XML file or a class is built, a ready example can almost always be found in the core.
A module folder
Every module has the same structure. You will get to know it step by step; for now a general picture is enough:
| Folder | What is in it |
|---|---|
etc | XML configuration |
Controller | Actions that answer requests |
Model | Working with data |
view | Layouts, templates, styles and scripts |
Common mistake
The server was pointed at the project root instead of the pub folder. Then app/etc/env.php with the database password and the logs in var/log can be opened from a browser. The site root must always be the pub folder.