Skip to main content
version 1.0.0

Directory Structure

Introduction

info

We highly recommend using the node artisan make command to generate the files of your application. If using the Artisan, it will automatically generate the file and register it wherever is needed. Take as an example the node artisan make:command command. First it will generate the file and then will register the command inside the commands array property of app/Console/Kernel.js file.

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. Almost all the classes in your application will be in this directory.

The bootstrap directory

The bootstrap directory, contains all of your application's bootstrap files. It's here that Athenna holds the main file that bootstrap the application using the Ignite class.

The config directory

The config directory, 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 the options available to you.

The database directory

This directory does not exist by default, but will be created for you if you execute the athenna install:database command. 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 providers directory

The providers directory contains all 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 to run.

Inside this directory we also have the Container file. This file is just a type that defines the type that exists inside the container. Very useful to use inside other providers' constructor such as Services. See the example above:

export class UserService {
/**
* @type {import('#app/Services/MyAppService').MyAppService}
*/
#myAppService

/**
* Create a new controller instance.
*
* @param {any} myAppService
*/
constructor(myAppService) {
this.#myAppService = myAppService
}

/**
* Find one user by id.
*
* @param id
*/
async findOne(id: string) {
return this.#myAppService.findOne(id)
}
}

The routes directory

The routes directory contains all the route definitions for your application. By default, several route files are included with Athenna: http, console.

The http file is where you will define the entrypoint of your api using the Route facade that is provided by the HttpRouteProvider.

The console file is where you will define the entrypoint of your commands using the Artisan facade that is provided by the ArtisanProvider.

The storage directory

The storage directory contains your logs, file caches, files uploaded locally 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 and the logs directory contains your application's log files.

The tests directory

You can create a test executing the node artisan make:test command. The tests directory contains your unitary and E2E tests. Japa unit tests and feature tests are provided out of the box. Each test class should be suffixed with the word Test. You may run your tests using the npm test command.

The app directory

The majority of your application is housed in the app directory.

The app directory contains a variety of additional directories such as Http. Think of the Http directory as providing an API into the core of your application. The HTTP protocol is a mechanism to interact with your application, but do not actually contain application logic. In other words, it's a way of issuing commands to your application. The Http directory contains your controllers, middleware, and requests.

A variety of other directories will be generated inside the app directory as you use the node artisan make commands to generate classes. So, for example, you can generate a new model inside App/Models directory executing the node artisan make:model command to generate a model class.

tip

Many of the classes in the app directory can be generated via artisan make commands. To review the available commands, run the node artisan list make command in your terminal.

The Console directory

The Console directory contains all the custom Artisan commands for your application. These commands may be generated using the make:command command. This directory also houses your console kernel, which is where your custom Artisan commands are registered.

The Http directory

The Http directory contains your controllers and middlewares. Almost all the logic to handle http requests entering your application will be placed in this directory.

The Models directory

caution

The Models directory will not come installed with the framework and the node artisan make:model will not work until you run athenna install:database command to set up @athenna/database package in your project.

This directory does not exist by default, but will be created for you if you execute the node artisan make:model command. The Models directory contains all of your ORM model classes. The ORM included with Athenna provides beautiful and simple methods 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 Repositories directory

This directory does not exist by default, but will be created for you if you execute the node artisan make:repository command. The Repositories directory contains all the classes that retrieve data from somewhere. It can be a SQL, NoSQL Database or an ElasticSearch. Usually you are going to use the ORM with these classes to get your data and treat it before returning

The Resources directory

caution

The Resources directory will not come installed with the framework and the node artisan make:resource will not work until you run athenna install:database command to set up @athenna/database package in your project.

This directory does not exist by default, but will be created for you if you execute the node artisan make:resource command. The Resources directory contains all the classes that will be responsible to transform your ORM models to a simple Object. For example, you may wish to display certain attributes for a subset of users and not for others.

The Services directory

The Services directory contains the business logic of your application. The entrypoint of your application should have only the logic responsible to receive the request, delegate to your service and return what service return. Every file in Services will be registered inside the Ioc container by the ServiceProvider class. This way you can easily use this services inside your entrypoint classes like controllers using the constructor method in camelCase format, example: the class name is UserService but in the constructor you call the userService. You can explore the container in more detail in the container architecture concepts section.