The default project structure of AdonisJS serves as a great getting started point to develop new applications. AdonisJS ships with a conventional set of files and directories to speed the development process and eliminate the need of wiring the application by hand.
By the end of this guide, you will have a fairly good understanding of the project structure and the purpose of different files.
. ├── app ├── commands ├── config ├── contracts ├── providers ├── public ├── resources │ └── views ├── start │ ├── kernel.ts │ └── routes.ts ├── .adonisrc.json ├── .editorconfig ├── .env ├── .env.example ├── .eslintignore ├── .eslintrc.json ├── .gitignore ├── ace ├── package.json ├── server.ts ├── tsconfig.json
The Project Root
The root of the project has all the necessary config/meta files to setup the development workspace. Let's skim through the list of files and their purpose.
.eslintrc.json and .eslintignore
These files are created to lint your TypeScript code using eslint. You can run
npm run lint command to run the linter or install the eslint plugin for your text editor for a tighter feedback loop.
.adonisrc.json file configures the workspace for AdonisJS projects. The application runtime, the CLI commands and your project dependencies rely on this file to understand the requirements of your project.
This file contains the bare minimum config required to run the application. However, you can execute the following command to see the possible configuration options and their default values.
node ace dump:rcfile
AdonisJS relies on environment variables to hold the environment specific configuration.
For example: The database credentials on your local machine will always be different from the one in production and hence you must use the environment variables to configure them.
During development, you can define these variables inside the
.env file as key-value pairs.
Since you never commit
.env file to the version control systems like GIT. We create an additional
.env.example file to work as a template for your environment variables with just keys and no values. Using the
.env.example file, your team mates can create their own
AdonisJS creates the
.gitignore file by default with an assumption that you maybe using Git for version control.Remove this file if you are not using Git.
The .editorconfig file makes it possible to use consistent coding styles when collaborating on a single project.
Instead of asking every developer in your team to re-configure their editor settings, you can create an
.editorconfig file in your project root and many modern editors will adjust themselves based on this file.
AdonisJS creates this file with the settings used by the core team. However, you are free to change it as per you or your team preference.
app directory contains the source files for your application. Controllers, Models, Services, all are stored inside this directory.
All of the application runtime configuration is stored inside the
config directory. AdonisJS ships with a bunch of well documented configuration files used by the core of the framework.
As your application will grow, you can also use this directory to store additional configuration files.
Applicable to TypeScript projects. The
contracts directory stores the interfaces, types, enums or any other TypeScript constructs.
start directory contains the files that must be loaded only once during the initial boot process.
Even though the framework doesn't automatically load these files, keeping them in a separate directory indicates a clear purpose.
After compiling the frontend assets, you must move them to the
public directory, since the
resources directory is not exposed to the internet.
All of the files inside the
public directory are accessible by typing their path as part of the URL. For example: You can access
./public/style.css file by visiting http://localhost:3333/style.css URL.
database directory holds the database migrations and seed files. Just like the
start directory, the
database directory is created to indicate a clear purpose for the given files.
providers directory holds the Service providers local to your application. Always make sure to register the provider inside
.adonisrc.json file. Alternatively, you can also run the following command to create the provider and also register it at the same time.
node ace make:provider MySampleProvider
ace file and the
AdonisJS is the only Node.js framework, that ships with an embedded command line framework called
ace file in the project root is the starting point for executing CLI commands that are part of your source code or added by the dependencies of your project.
The commands local to your project are stored inside the
commands directory. You can create a new command by running the following instruction.
node ace make:command Greet
node ace build node build/server.js # Starts the server
API Server Exclusions
The API Server boilerplate has following exclusions.
publicdirectory. Also, the static files server is disabled for API only projects.