This project has been created to explore Node functionalities and backend patterns. The main idea of this project is to be a template project. Then, use it in the future in new projects or to improve current ones I hope you enjoy it and learn something new. See more here
This project follows a programmatic pattern
, which means using the project tools to force contributors to follow the pattern instead of creating massive docs that nobody reads, in a nutshell.
To do so, we must create programmatic constraints that will guarantee contributors have been following them, mainly by using:
Nx is used to create the project structure and help contributors to create things automatically as much as possible. That includes creating new services, for example.
Eslint is our rules manager. Used to validate pattern definitions programmatically. That includes denying using a serviceA code into a serviceB context, denying controllers to throw 400 errors as it is a middleware responsibility, and so on. See our custom rules here. See the screenshots to understand:
Importing ChallengeModel at the User controller:
Throwing a 400 error at a controller:
We might create an article about it soon, for now, consults the project source code and play it!
OBS: It does not remove the documentation needs (even because this readme is a doc haha), but it reduces the amount and helps contributors to follow the team definitions.
This project uses Nx to manage the monorepo, including its structure suggestion. So:
apps/*
folder -> See each one as a Node service;libs/model/*
folder -> Database table structure and they access the databases;- other folders in
libs/*
-> helpers, types, and middleware.
It's possible to see the current project structure by running the following script
yarn graph
Screenshot of the project structure - it might be outdated
Using the challenges service as an example, you can run the following scripts (it's possible to do the same at any other project in the repository - See more at anatomy).
Running Challenges service
# requires a mongo connection
nx serve challenges
Running Challenges tests
nx test challenges
Running Challenges build
nx build challenges
... other projects have the same structure. See more at anatomy
Running tests in all projects
yarn test:ci-many
Running build in all projects
yarn build:ci-many
nx <target> <project> <...options>
You can also run multiple targets:
nx run-many -t <target1> <target2>
..or add -p
to filter specific projects
nx run-many -t <target1> <target2> -p <proj1> <proj2>
You must follow the project pattern to create new stuff, including service. Ideally, the project itself must help you to follow them.
Let's create a new service checkout
. You have 2 options: prompt and VS extension. Both will generate service for you, including database configuration, minimal CRUD routing and controller methods, and the database data structure (model):
Using prompt to help you
yarn nx generate @backend-pattern/plugin:service
Using the full command
yarn nx generate @backend-pattern/plugin:service --name=checkout --no-interactive
You can either use Nx Console extension to make it for you:
Wanna know how it works? See the local plugin using Nx generators
Hi, I'm Tássio Jordão (TJ), a Chemical with Front-End experience. Actually, I'm a Frontend developer with some Chemistry knowledge. See more here