This is a base NestJs application with a fully configured development environment. A mongodb database connection has been setup, and the compose.yaml
file provides a mongodb database configured for developing the application.
The application is configured using a .env
file. An example file: .env.example
is provided, and contains all the necessary environment variables that the application needs.
You can just copy the .env.example
file, and change any environment variable as needed.
cp .env.example .env
To add new configuration values to the application, the following need be done in order:
- Add the relevant environment variables & values to the
.env
file. - Create a new
<module-name>.config.ts
file to validate the new environment variable values pulled from the.env
file. - Register the default export of the
<module-name>.config.ts
file in the module viaConfigModule::forFeature
. - Add the relevant namespace & configuration type to the
NamespacedConfigurationType
in theConfigurationService
(which - in turn - is inConfigurationModule
).
The test configuration is expected to be in a .env.test
file. You create a new .env.test
file by copying the .env.example
file, and changing any environment variable as needed.
cp .env.example .env.test
Note: When running tests, the environment variables from .env.test
should be used to configure the docker containers if the environment variables for the containers differ between the environment files. As a consequence when testing the application, the containers need to be started using:
docker compose up --env-file .env.test
The following are instructions to start the application locally - for development purposes.
- Start the application dependencies' containers.
docker compose up
- Start the application
yarn run start:dev
The scripts related to the application are stored in: cli/script
, and are also present in the scripts
section the main package.json
file.
The following scripts are available:
Script | package.json script |
Description |
---|---|---|
seed.script.ts | db:seed |
Seeds the database |
generate-keys.script.ts | key:generate |
Generate environment secrets |
The model factory & database seed follows the same convention as Laravel.
The model factories are stored in the src/_application/_database/_factory
module, and the database seeders are stored in the src/_application/_database/_seeder
module.
Environment variables are sourced into the application through module configurations. The module configurations are - in turn - validated against a schema defined by the developer. Configuration files typically live in the modules that "own" them. For an example of a module configuration, see src/_application/application.config.ts
.
A sample JWT authentication system has been setup in the application. It uses JWT tokens embedded in headers to authenticate requests to the application. See the src/_authentication
module for more details.
The application has the following test suites:
Command | Test type | Description |
---|---|---|
yarn run test:unit |
Unit test | Run unit tests for the application |
yarn run test:cli:unit |
Unit test | Run unit tests for the cli |
yarn run test:e2e |
E2E test | Run e2e tests for the application |
Note: The application E2E tests are ordered/sequenced according to their filenames. They should therefore start with the number which describes their running order.
The project uses yarn berry for package management; husky for git-hooks; lint-staged for linting staged files; eslint for code linting; and prettier for code prettifying.
A compose.yaml
file is provided, and contains the application container dependencies' definitions.
Logging in the application is done using winston through the src/_application/_logger
module.
Model factories should live in the module where their schemas are found. They should however be registered in the factory
module - located at: src/_application/_database/_factory
.
- Any application-related feature definition or module should be defined in the
src/_application
module. - Module names start with an underscore (e.g.:
_authentication
). - Time related environment variables should conform to, and be parsed with
ms
. - Application E2E test files should start with a number.
The project has the following branches:
main
: The stable branch.development
: The branch where development occurs.- (wip)
feat/user-with-email
: In this branch, theUser
model has anemail
field instead of ausername
field. - (next)
feat/administration
: An administration section for the application - with authN, (authZ?), ...