Exploring the Basic Structure of a Laravel Project

Nova Novriansyah
2 min readJul 2, 2024

--

Laravel is a powerful PHP framework known for its elegant syntax and developer-friendly features. When starting a new Laravel project, understanding its basic structure is essential for effective development. In this article, we’ll dive into the fundamental components and directories that make up a typical Laravel project.

Introduction to Laravel

Laravel follows the Model-View-Controller (MVC) architectural pattern, which separates the application’s concerns into distinct layers: handling business logic (Model), presenting data (View), and managing user requests (Controller). This separation promotes code organization, maintainability, and scalability.

Basic Structure Overview

Let’s explore the core directories and files you’ll encounter in a Laravel project:

  1. app/
  • The app directory contains the core application code. Key subdirectories and files include:
  • Console/: Houses Artisan commands used for tasks like database migrations and queue processing.
  • Exceptions/: Handles custom exception handling.
  • Http/: Contains Controllers, Middleware, and Requests.
  • Models/: Houses Eloquent ORM models for interacting with databases.

2. bootstrap/

  • The bootstrap directory initializes the Laravel framework and loads configuration files. It includes:
  • app.php: Initializes the Laravel application.
  • cache/: Stores framework bootstrap and cache files.

3. config/

  • Configuration files for various aspects of the application, including database connections, caching, and session handling. Key files:
  • app.php: Application configuration.
  • database.php: Database configuration.
  • cache.php: Cache configuration.

4. database/

  • Manages database-related operations. Key directories:
  • migrations/: Contains database migration files to manage database schema changes.
  • seeds/: Houses seed files for populating database tables with initial data.

5. public/

  • The public directory is the web server's document root. It contains the entry point (index.php) and publicly accessible assets like images, CSS, and JavaScript files.

6. resources/

  • Contains assets that are compiled and optimized for production. Key directories:
  • css/, js/: Stores CSS and JavaScript files.
  • views/: Contains Blade templates for rendering HTML.

7. routes/

  • Defines application routes that map URLs to controllers or closures. Key files and directories:
  • web.php: Routes for web interface.
  • api.php: Routes for API endpoints.
  • console.php: Defines Artisan commands.

8. storage/

  • Stores framework-generated files like logs, cache, and session data. Key directories:
  • app/: Stores files generated by your application.
  • framework/: Stores cache, sessions, and logs.
  • logs/: Contains application log files.

9. tests/

  • Houses PHPUnit test cases for automated testing of the application.

10. vendor/

  • Contains Composer dependencies.

Understanding the basic structure of a Laravel project is crucial for navigating and effectively developing applications using the framework. As you explore Laravel further, you’ll discover additional features and customization options within these directories. Leveraging Laravel’s conventions and powerful features can significantly streamline development and enhance productivity.

In future articles, we’ll delve deeper into each component, exploring best practices, advanced features, and practical tips for building robust applications with Laravel. Stay tuned for more insights into Laravel development!

--

--

Nova Novriansyah

C|CISO, CEH, CC, CVA,CertBlockchainPractitioner, Google Machine Learning , Tensorflow, Unity Cert, Arduino Cert, AWS Arch Cert. CTO, IT leaders. Platform owners