Magento 2 follows a modular and scalable directory structure that helps developers manage code efficiently. Here’s a breakdown of the most important folders in the Magento 2.4.8 codebase.
📁 Root Directory Overview
magento2/ ├── app/ ├── bin/ ├── dev/ ├── generated/ ├── lib/ ├── pub/ ├── setup/ ├── var/ ├── vendor/ ├── composer.json
📂 Key Directories Explained
app/
Contains custom code, configuration, and modules.
- app/code/ – Custom modules
- app/design/ – Themes and frontend designs
- app/etc/ – Global configuration files (e.g.,
env.php
,config.php
)
bin/
Contains the magento
CLI tool used for setup, deployment, and maintenance commands.
php bin/magento setup:upgrade
dev/
Used for development tools, tests, and debugging utilities.
generated/
Stores generated classes, factories, proxies, and interceptors created at runtime. Do not edit this folder manually.
lib/
Contains core libraries used by Magento for processing and framework operations.
pub/
Publicly accessible files (entry point). Contains:
- pub/index.php – Frontend entry point
- pub/static/ – Static assets (CSS, JS)
- pub/media/ – Uploaded images and media files
setup/
Contains Magento’s installation scripts and deployment tools.
var/
Stores cache, logs, and temporary files. Can be cleared during maintenance.
- var/cache/ – Magento cache
- var/log/ – Log files
- var/report/ – Exception reports
vendor/
Composer-managed packages. Core Magento modules and libraries are stored here. Do not modify directly.
composer.json
Defines the project dependencies and autoloading rules using Composer.
📝 Best Practices
- Do not modify
vendor/
orgenerated/
directly - Keep custom code in
app/code/
- Use version control for
app
andpub
changes - Regularly clear the
var
andgenerated
folders in dev environments
📌 Summary
The Magento 2 directory structure supports modular development, making it easier to customize, maintain, and scale your store. Understanding this structure is essential before working with modules, themes, or customizations.