Laravel - Application Structure

Laravel - Application Structure

The application structure in Laravel is basically the structure of folders, sub-folders and files included in a project. 

 

πŸ“‚ Main Folders of a Laravel Project

1. app/

This contains the core logic of your application (the heart of your business logic).

  • Console/ β†’ Custom Artisan commands.
  • Exceptions/ β†’ Application’s exception handling.
  • Http/ 
  • β€”  Controllers/ β†’ Handle incoming requests and return responses.
  • β€”  Middleware/ β†’ Filters HTTP requests (before/after handling).
  • β€”  Requests/ β†’ Form request validation logic.
  • Models/ β†’ Eloquent models for database interactions.
  • Policies/ β†’ Authorization logic.
  • Providers/ β†’ Service providers to bind services and configure app services.
  • Events/ β†’ Events represent actions that have occurred in your application.
  • Listeners/ β†’ Handle the events and execute logic when an event is fired.
  • Jobs/ β†’ Queued jobs for background tasks.
  • Mail/ β†’ Classes for sending emails (Mailable).
  • Notifications/ β†’ Classes for sending notifications (email, SMS, etc.).
  • Rules/ β†’ Custom validation rules.

2. bootstrap/

Contains files that initialize the framework.

  • app.php β†’ Initializes the Laravel framework.
  • cache/ β†’ Stores cached files for faster loading.

3. config/

Contains all the configuration files for your app (database, mail, etc.).

4. database/

Contains everything related to your database.

  • migrations/ β†’ Database schema migrations.
  • factories/ β†’ Model factories for seeding the database with sample data.
  • seeders/ β†’ Classes that populate the database with data.

5. public/

This is the web server's document root.

  • index.php β†’ The main entry point of the application.
  • assets/ β†’ Publicly accessible files such as images, CSS, and JS.

6. resources/

Contains assets that need to be processed or compiled.

  • views/ β†’ Blade templates (HTML).
  • lang/ β†’ Localization files (translations).
  • js/ β†’ JavaScript files (if using Laravel Mix).
  • sass/ β†’ SCSS files (if using Laravel Mix).

7. routes/

Defines your application’s route files.

  • web.php β†’ Routes for the web (browser-based).
  • api.php β†’ Routes for APIs (stateless).
  • console.php β†’ Artisan command-line routes.
  • channels.php β†’ Routes for broadcasting events.

8. storage/

Contains various types of file storage.

  • app/ β†’ Application-generated files.
  • framework/ β†’ Caches, session files, and compiled views.
  • logs/ β†’ Application log files.

9. tests/

Contains automated tests for your application.

  • Feature/ β†’ Tests for routes, controllers, etc.
  • Unit/ β†’ Unit tests for smaller, isolated functions.

10. vendor/

Contains all third-party dependencies managed by Composer.

– Do not modify this folder directly.

 

Key Files

  • .env β†’ Environment variables (app key, database credentials).
  • composer.json β†’ PHP dependencies and autoloading.
  • artisan β†’ Command line interface for Laravel.
  • package.json β†’ Node dependencies (frontend assets).
  • webpack.mix.js β†’ Laravel Mix config (frontend asset compilation).

In short:

  • app/ = logic
  • routes/ = URLs
  • resources/ = views/assets
  • config/ = settings
  • database/ = database
  • public/ = web root
  • storage/ = files
  • tests/ = tests

Root Folder

  • helpers.php β†’ Optional file for global helper functions (you can create it yourself).