This is the example repository from the blog post 'Bulletproof node.js project architecture'
Please read the blog post in order to have a good understanding of the server architecture.
Also, I added lots of comments to the code that are not in the blog post, because they explain the implementation and the reason behind the choices of libraries and some personal opinions and some bad jokes.
The API by itself doesn't do anything fancy, it's just a user CRUD with authentication capabilities. Maybe we can transform this into something useful, a more advanced example, just open an issue and let's discuss the future of the repo.
We use node
version 10.15.0
nvm install 10.15.0
nvm use 10.15.0
The first time, you will need to run
npm install
Then just start the server with
npm run start
It uses nodemon for livereloading :peace-fingers:
By using celebrate the req.body schema becomes clary defined at route level, so even frontend devs can read what an API endpoint expects without need to writting a documentation that can get outdated quickly.
route.post(
'/signup',
celebrate({
body: Joi.object({
name: Joi.string().required(),
email: Joi.string().required(),
password: Joi.string().required()
})
}),
controller.signup
);
Example error
{
"errors": {
"message": "child \"email\" fails because [\"email\" is required]"
}
}
Read more about celebrate here and the Joi validation API
- unify config: typeorm, mongodb, nodeenv => config.ts
- setup CI/CD
- polish up logging with winston
- write tests
- check if user exists upon registration
- implement verify-token endpoint to be used in microservice architecture
- make feature initilization modular (e.g.: mailing, agenda)
- add dependency injection for typeORM repositories in services
- adjust readme
- clean up repository files
- prevent committing code that doesn't compile using pre hooks and tsc (with husky, lint-staged, prettier and tsc)
- API Validation layer (Celebrate+Joi)
- Unit tests examples
- Cluster mode
- The logging 'layer'
- Add agenda dashboard
- Continuous integration with CircleCI ๐
- Deploys script and docs for AWS Elastic Beanstalk and Heroku
- Integration test with newman ๐
- Instructions on typescript debugging with VSCode