Hello! NExp (Node Experience) is a boilerplate for Node, which makes use of a Clean Architecture + DDD, with TypeScript that combined allow a perfect cohesion thus achieving a clean and at the same time very powerful implementation.
https://github.com/DigiChanges/node-experience
NOTE: The v1 it's deprecated and don't have support in the future.
We can run the project directly with docker compose and then bash where the basic commands to feed the database are located.
- git clone https://github.com/DigiChanges/node-experience
- Create a folder on project root call it
dist
. - Install dependencies.
pnpm install
. - Copy
.env.dev
file to.env
. (.env.dev it's an environment example file) - Then execute
STAGE=dev docker-compose up --build
to up all containers. - Configure Keycloak.
Once you already login in the keycloak administration console, you can create the realm from the side menu
Then you just need to add a name to it and click on "Create".
To add a client, first you need to select the realm, then go to the side menu "Clients", you will see the option "Create client".
Complete the required fields and then click on "Next", after finish all the steps then you can save it.
NOTE: In docker/keycloak/themes folder you can find a theme for keycloak, you can use it to customize the login page. It's made with https://github.com/keycloakify/keycloakify
You need to select the new client and on credential tab copy the client secret and copy UUID client from URL.
Go to .env file and replace this values.
Example:
KEYCLOAK_CLIENT_ID=experience
KEYCLOAK_CLIENT_SECRET=eSKReacL00dAjlrQfv5HM8BWLcCDmkCK
KEYCLOAK_CLIENT_UUID=4693fe5e-4d33-43a0-b016-e19e827ca332
And .env file complete this is like this:
KEYCLOAK_CLIENT_ID=experience
KEYCLOAK_CLIENT_SECRET=eSKReacL00dAjlrQfv5HM8BWLcCDmkCK
KEYCLOAK_CLIENT_UUID=4693fe5e-4d33-43a0-b016-e19e827ca332
KEYCLOAK_MAIN_REALM=chespirito
KEYCLOAK_HOST=http://keycloak:8080
[email protected]
KEYCLOAK_PASSWORD=db_experience123
KEYCLOAK_AUTHORIZATION=true
5. Finally, generates an admin user, add roles with permissions and get a bucket for MinIO.
docker-compose exec node bash dev.init.sh
First, install nexp-cli using npm (we assume you have pre-installed node.js).
npm install -g nexp-cli
Then generate your new project:
nexp-cli create
Each module is divided by business domain:
- File
- Item
- Notification
There are also two particular cases:
- Config
- Shared
The directory structures for business domains are as follows:
Folder structure of a domain (business logic)
├── Domain
│ ├── Entities
│ ├── Exceptions
│ └── Services
│ └── UseCases
├── Infrastructure
│ ├── Repositories
│ ├── Schema
│ └── Seeds
├── Presentation
│ ├── Commands
│ ├── Controllers
│ ├── Criterias
│ ├── Exceptions
│ ├── Handlers
│ ├── Middlewares
│ ├── Requests
│ └── Transformers
├── Tests
│ ├── Fixtures
Tip I know it may sound repetitive, but it is not a framework. NExp is a set of tools or libraries working together through a common structure. All structural code within this project is not fixed and can be changed freely.
The advantages of using this boilerplate is to save time thinking about certain basic structures common to any project to make an API without having to get everything from scratch.
As it is only a boilerplate, you have the freedom to structure the code whatever you want.
Common structures found within this project are:
- Authentication and authorization with Keycloak.
- Filesystem with MinIO, 100% S3 compatible.
- Basic push Notification and Email with nodemailer.
- MikroORM and Mongoose Integration.
- Koa integration.
- Business logic independent of the HTTP and persistence libraries.
NExp is MIT licensed.