Directory Structure¶
Here's an overview of the directory structure for a default Web Hive application:
├── app
│ ├── controllers
│ │ ├── HomeController.php
│ │ └── UserController.php
│ │ └── ...
│ ├── models
│ │ └── AuthModel.php
│ │ └── UserModel.php
│ │ └── ...
├── config
│ ├── app.php
│ └── database.php
├── core
│ ├── App.php
│ ├── Controller.php
│ ├── Database.php
│ ├── functions.php
│ ├── Model.php
│ ├── Router.php
│ └── View.php
├── views
│ └── home.php
│ └── user.php
│ └── ...
├── public
│ ├── assets
│ │ └── ...
│ ├── css
│ │ └── ...
│ ├── js
│ │ └── ...
│ ├── index.php
│ └── .htaccess
├── routes
│ └── web.php
│ └── api.php
└── autoload.php
Introduction¶
Directory structures are an essential component of any software project. They organize the files and folders of an application in a logical manner that makes it easier to manage, maintain, and scale the project. By using a consistent directory structure, developers can quickly locate the files they need and maintain a clear separation of concerns between the different components of the application.
In this documentation, we will provide examples of common directory structures for various types of applications, including web applications, MVC OOP frameworks, and more. By understanding these directory structures, you will be able to create organized and maintainable applications that are easy to navigate and scale.
The Root Directory¶
The app Directory¶
The app
directory contains your application's core code, including controllers, models, and other classes. The app
directory is further organized into subdirectories for controllers, models, and other related classes.
In addition to these subdirectories, the app directory may also contain other files and directories related to the application logic, such as helpers or middlewares.
The core Directory¶
The core
directory typically contains the core components of the application, such as classes
and libraries
that are shared across the application. These components often provide functionality related to routing, database interaction, view rendering, and more.
The core directory may also contain other classes and libraries related to the core functionality of the application, such as authentication or caching libraries. By storing these components in a separate directory, it's easier to maintain and update the core functionality of the application without affecting the application-specific logic.
The config Directory¶
The config
directory contains all of your application's configuration files, including app.php
, which contains the configuration options for your application, and database.php
, which contains the configuration options for your application's database connection.
The public Directory¶
The public
directory contains all of your application's publicly accessible files, including the index.php
file, which is the entry point for all HTTP requests to your application.
The routes Directory¶
The routes
directory contains your application's route definitions, including the web.php
file, which contains the route definitions for your application's web interface, and api.php
file, which contains the apis route definitions for your application's.
The view Directory¶
The views
directory typically contains the HTML, CSS, JavaScript
, and other assets that make up the user interface of the application. These files are responsible for presenting the data to the user and allowing them to interact with the application.
The app Directory¶
The Controllers Directory¶
The controllers
directory typically contains PHP
files that define the controller classes for the application. These classes receive requests from the routes and use the models to retrieve and manipulate data before passing
it to the views to be displayed
The Models Directory¶
The models
directory typically contains PHP
files that define the model classes for the application. These classes are responsible for retrieving and manipulating data from the database or other data sources
By following this directory structure, you can easily organize your code and files in a way that makes sense for your application. Laravel imposes almost no restrictions on where any given class is located, as long as Composer can autoload the class.