Directory Structure
Understand the directory structure of your project.
We highly recommend you to use the node artisan make
command to generate the files of your application. If
using this command, it will automatically generate the
file and register it wherever it 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
map property of .athennarc.json
file.
Default structure
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.ts
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 following command:
# To install the library and configure it
node artisan install @athenna/database
# To just configure the library
node artisan configure @athenna/database
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.
The routes directory
The routes
directory contains all the route definitions
for your application. By default, several route files are
included with Athenna:
- The
http.ts
file is where you will define the entry point of your api using the Route facade that is provided by the HttpRouteProvider. - The
console.ts
file is where you will define the entry point of your commands using the Artisan facade that is provided by the ArtisanProvider.
As you may have noticed your project does not have the
console.ts
file. We only recommend using this file when
you don't want to use TypeScript in your application or
when you want to add some personalized option of commander
to your command. Check the example:
import { Artisan } from '@athenna/artisan'
Artisan.route('hello', function (helloArg: string, options: { hello: string }) {
console.log(helloArg)
console.log(options.hello)
}) // 👈 Artisan.route return an instance of Commander
.argument('<hello>', 'Description for hello argument.')
.option('--hello', 'Description for hello flag.')
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 the following
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. - 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. Each test file name should always end with the word
Test at the end. You may run your tests using the node artisan test
command.
If your test file name does not end with Test
, it will
be ignored and the test class will not run. But, you can
customize this behavior in the configure function of Japa
inside your
Path.bin('test.ts')
./bin/test.ts
Do your own structure
There are some files in your project that are crucial to keep in certain places. Let's analyze some of them:
- The file is the entry point of the
Path.bin('main.ts')
./bin/main.ts
node artisan serve
command. Every time that you run this command, Athenna will use this file to run your application. - The file is the entry point of the
Path.bin('artisan.ts')
./bin/artisan.ts
artisan.js
script. - The path is where you are going to set up your configuration files. You can learn more about configuration files at the configuration documentation section.
Path.config()
./src/config
- The file is where you are going to register your Http server routes.
Path.routes('http.ts')
./src/routes/http.ts
Athenna is a framework with a lot of opinions, with predefined project structures; it was built that way to make your life easier. But speaking from developer to developer, we know how fun is to be able to have control over everything in your application, especially the structure of your project 😎.
With that in mind, Athenna was built in a fully configurable way. You can create your files and folders anywhere, even the one that is crucial to keep in certain places.