.
├── ace
├── package.json
├── public
├── server.js
└── start
├── app.js
├── kernel.js
└── routes.js
You are viewing the legacy version of AdonisJS. Visit https://adonisjs.com for newer docs. This version will receive security patches until the end of 2021.
In this guide, we learn how AdonisJs apps are structured and how gracefully it scales as your project grows.
The philosophy of AdonisJs is always to start lean and grow big on demand. The adonis
command-line comes with a bunch of commands to create new directories/files whenever you need them.
.
├── ace
├── package.json
├── public
├── server.js
└── start
├── app.js
├── kernel.js
└── routes.js
File/Directory | Description |
---|---|
ace |
The ace file bootstraps the command line tool for your project-specific commands. Running |
package.json |
The standard Node.js packages file. |
public |
The public directory is used to store static assets like Css, Javascript files or images |
server.js |
This file bootstraps the HTTP server. Running |
start/app.js |
This file is required to register the providers, commands, and aliases. You can ignore this file for now especially if you are not familiar with providers. |
start/kernel.js |
The HTTP Middleware are registered inside this file. |
start/routes.js |
This file is used to define HTTP routes. |
The app
directory stores all of your application code such as Controllers, Models, Commands.
AdonisJs has the concept of autoloading the app
directory. This means that instead of requiring files with the relative path, you can require files with a namespace. For example:
├── app
│ └── Services
│ └── User.js
Normally you would require the above file as
const UserService = require('../app/Services/User')
With autoloading in place, it can be imported as
const UserService = use('App/Services/User')
The benefit of the latter approach is that the namespace always remains same and you never have to deal with relative paths by typing ../
.
The application views are stored inside resources/views
directory. Each view file ends with .edge
and uses edge as the templating engine.
You can create new views using the adonis make:view
command.
adonis make:view welcome
For nested views running the following command
adonis make:view users.list
The public
directory in your app is dedicated to store all of the frontend related assets like css, images or javascript files.
You access these files without adding /public
to the URL. For example:
The public/style.css
file can be accessed by visiting 127.0.0.1:3333/style.css