Laravel Folder Structure Overview
When you create a new Laravel project, it generates several directories and files. Each of these has
a specific purpose.
1. app/
- Contains your application's core code.
- Default namespace for PHP code.
Subfolders:
- Console/: Artisan commands.
- Exceptions/: Custom error handling.
- Http/: Controllers, Middleware, and Requests.
- Controllers/: Application logic.
- Middleware/: HTTP request filters.
- Models/: Eloquent models (e.g., User.php)
2. bootstrap/
- Initializes the Laravel framework.
- app.php file bootstraps the framework.
- cache/ directory for performance.
3. config/
- Configuration files for database, mail, app, etc.
- Common files: app.php, database.php, auth.php
4. database/
- Database-related files.
Subfolders:
- migrations/: Version control for database schema.
- factories/: Dummy data generators.
- seeders/: Insert default/test data.
5. public/
- Web root folder.
- Only this folder is publicly accessible.
- Contains index.php, CSS, JS, images.
6. resources/
- Contains views, raw assets, and language files.
Subfolders:
- views/: Blade templates.
- lang/: Language translation files.
- js/, sass/: Frontend assets.
7. routes/
- Route definition files.
Files:
- web.php: Web routes (sessions, CSRF).
- api.php: API routes (stateless).
- console.php: Artisan command routes.
- channels.php: Broadcasting event routes.
8. storage/
- Logs, file uploads, and cache.
Subfolders: app/, logs/, framework/
9. tests/
- Unit and feature tests using PHPUnit.
10. vendor/
- Third-party packages installed by Composer.
11. .env
- Environment variables like DB credentials, app name.
- Should not be committed to Git.