Describe Magento File Structure
Understanding the foundational Magento file structure is essential for locating code, configuration, and assets quickly.
Visual Overview
Root Directory Structure
The root Magento directory contains several primary folders, each serving a specific purpose:
Core Configuration and Code Areas
This is where your custom modules are found.
Why? Installing modules via app/code makes it difficult to keep them up-to-date.
This directory stores themes for the frontend and admin areas.
- app/design/frontend- Customer-facing themes
- app/design/adminhtml- Admin panel themes
Location for translation (language) packages.
Used for multi-language store configurations.
Stores critical configuration files:
app/etc/env.php
    ⚠️ Should NOT be included in Git - contains sensitive information!
Configuration includes:
- Database connection details
- Redis configuration
- Advanced Message Queuing Protocol (AMQP) settings
app/etc/config.php
    Contains:
- Module enable/disable configuration
- Store configuration defaults
- Theming configuration
Merges with env.php at runtime.
Application Execution and Tools
Contains the bin/magento file - the command-line interface (CLI) tool.
- Cache management: bin/magento cache:flush
- Module management: bin/magento module:enable
- Setup commands: bin/magento setup:upgrade
Contains configuration for built-in tools:
- Grunt configuration
- Magento's test suite
Files are automatically created by Magento.
Contains:
- Factory classes
- Interceptor classes (required for plugins)
- Proxy classes (used for lazy-loading)
- Extension attribute interfaces/classes
Contains internal libraries that Magento relies on.
Example: jQuery is located in lib/web/jquery/
Contains files related to installing Magento.
bin/magento setup:install
        ❌ Avoid using the
/setup URL in production
    Web Root and Assets
This should be the HTTP root for the webserver.
/pub helps prevent exposing sensitive folders like var/
    How it works:
- When a user requests a URL, if the exact file doesn't exist, the webserver rewrites to pub/index.php
- This starts the Magento request
pub/media/
    Where the website's images are stored.
pub/static/
    Contains processed files (.css, .js, .html) ready for end-users to download.
- Developer mode: Files are symlinked using bin/magento dev:source-theme:deploy
- Production mode: Files are processed and copied using bin/magento setup:static-content:deploy
.htaccess file in this directory - it prevents theme files from downloading!
    Temporary and Third-Party Directories
Stores temporary files used by Magento or generated by the application.
Examples:
- var/log/- Application logs
- var/report/- Error reports
- var/cache/&- var/page_cache/- File-system cache
Where all Composer-installed modules are located.
composer install
    vendor/ directory!
        Any changes will be destroyed the next time
composer update or composer install runs.
    Quick Reference Table
| Directory | Purpose | Key Points | 
|---|---|---|
| app/code | Custom modules | Use Composer for 3rd-party modules | 
| app/design | Themes | Frontend & adminhtml themes | 
| app/etc/env.php | Environment config | ❌ DO NOT commit to Git | 
| app/etc/config.php | Module config | ✅ Should commit to Git | 
| bin/ | CLI tools | Contains bin/magento | 
| generated/ | Auto-generated code | Factories, interceptors, proxies | 
| pub/ | Web root | Should be HTTP document root | 
| var/ | Temporary files | Can be deleted anytime | 
| vendor/ | Composer packages | ⚠️ NEVER modify directly | 
Exam Tips
Key Points to Remember
- Know which files should/shouldn't be committed to version control
- Understand the difference between env.phpandconfig.php
- Remember that pub/should be the document root for security
- Understand that vendor/code should never be modified
- Know where generated code is stored and when it's created
- Understand the purpose of the var/directory and its scalability limitations
