Directory Structure
Introduction
The default LaraGram application structure is intended to provide a great starting point for both large and small applications. But you are free to organize your application however you like. LaraGram imposes almost no restrictions on where any given class is located - as long as Composer can autoload the class.
The Root Directory
The App Directory
The app
directory contains the core code of your application. We'll explore this directory in more detail soon; however, almost all of the classes in your application will be in this directory.
The Bootstrap Directory
The bootstrap
directory contains the app.php
file which bootstraps the framework. This directory also houses a cache
directory which contains framework generated files for performance optimization such as the listen and services cache files.
The Config Directory
The config
directory, as the name implies, contains all of your application's configuration files. It's a great idea to read through all of these files and familiarize yourself with all of the options available to you.
The Database Directory
The database
directory contains your database migrations, model factories, and seeds. If you wish, you may also use this directory to hold an SQLite database.
The Public Directory
The public
directory contains the index.php
file, which is the entry point for all requests entering your application and configures autoloading. This directory also houses your assets such as images.
The Listens Directory
The listens
directory contains all of the listen definitions for your application. By default, two listen files are included with LaraGram: bot.php
and console.php
.
The bot.php
file contains listens that LaraGram places in the bot
middleware group.
The console.php
file is where you may define all of your closure-based console commands. Each closure is bound to a command instance allowing a simple approach to interacting with each command's IO methods. Even though this file does not define listens, it defines console based entry points (listens) into your application. You may also schedule tasks in the console.php
file.
The Storage Directory
The storage
directory contains your logs, compiled Temple8 templates, file caches, and other files generated by the framework. This directory is segregated into app
, framework
, and logs
directories. The app
directory may be used to store any files generated by your application. The framework
directory is used to store framework generated files and caches. Finally, the logs
directory contains your application's log files.
The storage/app/public
directory may be used to store user-generated files, such as profile avatars, that should be publicly accessible. You should create a symbolic link at public/storage
which points to this directory. You may create the link using the php laragram storage:link
Commander command.
The Vendor Directory
The vendor
directory contains your Composer dependencies.
The App Directory
The majority of your application is housed in the app
directory. By default, this directory is namespaced under App
and is autoloaded by Composer using the PSR-4 autoloading standard.
By default, the app
directory contains the Controllers
, Models
, and Providers
directories. However, over time, a variety of other directories will be generated inside the app directory as you use the make Commander commands to generate classes. For example, the app/Console
directory will not exist until you execute the make:command
Commander command to generate a command class.
Both the Console
and Controllers
directories are further explained in their respective sections below, but think of the Console
and Controllers
directories as providing an API into the core of your application. The Bot updates and CLI are both mechanisms to interact with your application, but do not actually contain application logic. In other words, they are two ways of issuing commands to your application. The Console
directory contains all of your Commander commands, while the Controllers
directory contains your controllers.
NOTE
Many of the classes in the app
directory can be generated by Commander via commands. To review the available commands, run the php laragram list make
command in your terminal.
The Console Directory
The Console
directory contains all of the custom Commander commands for your application. These commands may be generated using the make:command
command.
The Controllers Directory
The Controllers
directory contains your controllers. Almost all of the logic to handle requests entering your application will be placed in this directory.
The Conversations Directory
The Conversations
directory contains all of the conversations classes for your application. These classes are generated using the make:conversation
command. This directory does not exist by default, but will be created for you when you create your first conversation. To learn more about conversation, check out the documentation on [conversation].
The Events Directory
This directory does not exist by default, but will be created for you by the event:generate
and make:event
Commander commands. The Events
directory houses event classes. Events may be used to alert other parts of your application that a given action has occurred, providing a great deal of flexibility and decoupling.
The Exceptions Directory
The Exceptions
directory contains all of the custom exceptions for your application. These exceptions may be generated using the make:exception
command.
The Jobs Directory
This directory does not exist by default, but will be created for you if you execute the make:job
Commander command. The Jobs
directory houses the queueable jobs for your application. Jobs may be queued by your application or run synchronously within the current request lifecycle. Jobs that run synchronously during the current request are sometimes referred to as "commands" since they are an implementation of the command pattern.
The Listeners Directory
This directory does not exist by default, but will be created for you if you execute the event:generate
or make:listener
Commander commands. The Listeners
directory contains the classes that handle your events. Event listeners receive an event instance and perform logic in response to the event being fired. For example, a UserRegistered
event might be handled by a SendWelcomeEmail
listener.
The Models Directory
The Models
directory contains all of your Eloquent model classes. The Eloquent ORM included with LaraGram provides a beautiful, simple ActiveRecord implementation for working with your database. Each database table has a corresponding "Model" which is used to interact with that table. Models allow you to query for data in your tables, as well as insert new records into the table.
The Middlewares Directory
The Middlewares
directory contains all of your Middlewares. The middlewares handle requests entering your application.
The Policies Directory
This directory does not exist by default, but will be created for you if you execute the make:policy
Commander command. The Policies
directory contains the authorization policy classes for your application. Policies are used to determine if a user can perform a given action against a resource.
The Providers Directory
The Providers
directory contains all of the service providers for your application. Service providers bootstrap your application by binding services in the service container, registering events, or performing any other tasks to prepare your application for incoming requests.
In a fresh LaraGram application, this directory will already contain the AppServiceProvider
. You are free to add your own providers to this directory as needed.
The Rules Directory
This directory does not exist by default, but will be created for you if you execute the make:rule
Commander command. The Rules
directory contains the custom validation rule objects for your application. Rules are used to encapsulate complicated validation logic in a simple object. For more information, check out the validation documentation.
The Templates Directory
This directory does not exist by default, but will be created for you if you execute the make:template
Commander command. The templates
directory contains the messages templates for your application. For more information, check out the Temple8 Engine.