AdonisJS Project Structure — Let’s Learn Adonis 5, Lesson 1.1
--
View all lessons in the Let’s Learn Adonis 5 series here.
Now that we have our Adonis application created and we’ve verified that it runs okay, let’s go ahead and start to dive into our project and learn the actual project structure.
So, go ahead and open up your newly created project in your text editor of choice, I’m using Visual Studio Code, and off to the left-hand side, you can see that we’re started with a number of directories and files. Some of these you might be familiar with, if not that’s okay we’re going to spend some time in this lesson going through each of these different folders and files so that you know exactly where you are within your project structure at all times.
To start, there are going to be two directories we’re going to spend the vast majority of our time within. The app
directory and the resources
directory.
App Directory
The app directory is going to contain almost, if not all, of our business logic. It’s going to contain our controllers, models, services, exceptions, middleware, and so on.
Each of those is going to get its own subdirectory within the app directory. Adonis actually starts us off with an Exceptions directory, which contains a single file called Handler.ts
. This file is in charge of handling our application's exceptions during an HTTP Request.
By default, the Handler.ts
file looks like this:
// app/Exceptions/Handler.ts/*
|--------------------------------------------------------------------------
| Http Exception Handler
|--------------------------------------------------------------------------
|
| AdonisJs will forward all exceptions occurred during an HTTP request to
| the following class. You can learn more about exception handling by
| reading docs.
|
| The exception handler extends a base `HttpExceptionHandler` which is not
| mandatory, however it can do lot of heavy lifting to handle the errors
| properly.
|
*/import Logger from '@ioc:Adonis/Core/Logger'
import HttpExceptionHandler from '@ioc:Adonis/Core/HttpExceptionHandler'