RESTful/gRPC api with Domain Driven Design
- Make sure you have
nvm
, nodev14.18.3
orLTS
version of node installed - Install
yarn
-npm install -g yarn
.
- Visit [http://localhost:30041/rest-api] for REST docs
- gRPC documentation should be added at the bottom of this readme. It can be access by visiting http://localhost:30041/readme
- This template documentation can be access by running
yarn serve:docs
then visit http://localhost:3000
Prerequisites
- Docker Community Edition v17 or higher
$ docker build -t raw-template .
$ docker run -p 30041:30041 -p 30042:30042 --env-file=.env raw-template
Access http://localhost:<PORT>
and you're ready to go!
- Clone the repository with
git clone --recursive https://github.com/YouverifyHQ/raw-template.git
- Install the dependencies with Yarn
- Run local Jaeger for distributed tracing
yarn start:jaeger:dev
- Run the application in development mode with
yarn start:dev:rs
- Access
http://localhost:<PORT>
and you're ready to go!
- uses Node.js > v9
- written using ES6
- uses Yarn for package dependency management
- uses Airbnb JavaScript Style
- uses
Mongoose
as ODM - Filename convention -
camelCase
yarn build
- build codebase for productionyarn start:dev
- start the application in development modeyarn start:dev:rs
- start the application in development mode with nodemon for automatic server restart on code changeyarn test
- run Unit testsyarn lint
- lint codebase using Airbnb styleyarn lint:fix
- fix code according to Airbnb styleyarn build:docs
- generate Rest API, Readme & JSDC documenationyarn update:stub
- update submodulesyarn start:jaeger:dev
- start a local Jaeger server and serveyarn stop:jaeger:dev
- stop a local Jaeger container
- Mongodb - Main datastore
- Redis - In-memory datastore for caching
- Elasticsearch - Elasticsearch is a distributed, RESTful search and analytics engine
- RabbitMq - Message Broker
-
Express - Node Framweork
-
Awilix - dependency resolution support powered by
Proxy
-
Nodemon - Use for development file reload.
-
CORS - a node.js package for providing a Connect/Express middleware that can be used to enable CORS with various options.
-
Compression - Node.js compression middleware.
-
Http-status - Utility to interact with HTTP status code.
-
Winston - A multi-transport async logging library for node.js.
-
Morgan - HTTP request logger middleware for node.js
-
Lodash - A modern JavaScript utility library delivering modularity, performance & extras
-
Mongoose - Mongoose provides a straight-forward, schema-based solution to model your application data. It includes built-in type casting, validation, query building, business logic hooks and more, out of the box.
-
Chance - generate massive amounts of fake data in the browser and node.js
-
Moment - Parse, validate, manipulate, and display dates and times in JavaScript.
-
Moment-timezone - Parse and display dates in any timezone.
-
APIdocjs- Inline Documentation for RESTful web APIs
- Fluentd - Data collector for unified logging layer..
- Jaeger - end-to-end distributed tracing. Monitor and troubleshoot transactions in complex distributed systems
- mocha - JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple and fun
- chai - a BDD / TDD assertion library for node and the browser that can be delightfully paired with any javascript testing framework.
- supertest - HTTP assertions made easy via superagent.
- cross-env - makes it so you can have a single command without worrying about setting or using the environment variable properly for the platform
- We mainly use this so mocha can use the absolute path of files
Adding pre-commit
to your project can be helpful to encourage consistency and quality of your code repository.
- pre-commit - pre-commit is a pre-commit hook installer for
git
. It will ensure that youryarn lint
(or other specified scripts) passes before you can commit your changes. This all conveniently configured in yourpackage.json
. - lint-staged - Linting makes more sense when running before committing your code. By doing that you can ensure no errors are going into repository and enforce code style. But running a lint process on a whole project is slow and linting results can be irrelevant. Ultimately you only want to lint files that will be committed.
- gRPC Documentations here
const config = {
httpPort: {
doc: "The rest port to bind",
format: "port",
default: 30007,
env: "HTTP_PORT",
sensitive: false,
},
grpcPort: {
doc: "The grpc port to bind",
format: "port",
default: 30015,
env: "GRPC_PORT",
sensitive: false,
},
env: {
doc: "The application environment",
format: ["production", "development", "test", "qa", "staging", "local"],
default: "local",
env: "NODE_ENV",
sensitive: false,
},
};
exports.app = config;
This boilerplate is open to suggestions and contributions, documentation contributions are also important! :)
This boilerplate is forked and modified from node-api-boilerplate - Talysson de Oliveira Cassiano ๐
MIT License - fork, modify and use however you want.