Node.js Boilerplate for Back-End using TypeScript and Nest.js.
Nest Modules Graph and Classes
- JavaScript: Web programming language;
- TypeScript: JavaScript superset for typing;
- Node.js: JavaScript runtime;
- Nest.js: TypeScript Framework for Back-End;
- Express: Robust tooling for HTTP servers;
- Socket.io: WebSocket library;
- AWS-SDK: A Node.js SDK to access AWS resources, such as:
SQS: Queue management service;
SNS: Topic notification service;
S3: Files storage service;
Cognito: Users authenticator service; - TypeORM: ORM for databases;
- PostgreSQL: Relational (SQL) database;
- MongoDB: Schematic and document-oriented NoSQL database;
- Redis: Cache and in-memory key-value NoSQL database;
- Docker: Services isolation and process resources management with containers;
- Kubernetes: Containers orchestration system;
- SonarQube: Test coverage and code quality analyzer;
- Grafana: Containers data visualization and dashboards;
- Winston: Custom logger with transports;
- Joi: Schema validator library;
- Jest: Testing Framework;
- ESLint: JavaScript/TypeScript linter and formatter;
- Huksy: Git hooks tool used to check tests, format the code and the commits;
- Install project dependencies
yarn install
-
Install AWS CLI
-
Configure AWS CLI
$ aws configure
> AWS Access Key ID [****]: mock
> AWS Secret Access Key [****]: mock
> Default region name [us-east-1]: us-east-1
> Default output format [table]: json
- Start Docker containers or Kubernetes cluster;
- Mock external services;
- Create database entities and populate registers;
- Start HTTP REST API & GraphQL API;
- Start TCP WebSockets Server;
- Send message to Queue;
- Receive message from Queue;
- Check the logs;
- Test the dependencies and execution locally;
- Run automated tests;
- If necessary, merge with a hotfix on git;
- Rebuild the project and restart the service;
- Copy dotenv file
cp envs/.env.local ./.env # copy development local example
source ./.env # load envs on shell session
- Initialize the composefile (
docker-compose.yml
) available on project root folder.
# create and run essentials docker containers in background
docker-compose up -d cloud database data cache
# or
# create and run all docker containers in background
docker-compose up -d
# delete all containers and volumes
docker-compose down -v
- Prepare Kubernetes cluster locally.
# build locally application docker image
docker build -t boilerplate-image:1.0 . # replate './Dockerfile' to 'infra/docker/Dockerfile.prod'
# create Kind cluster (only for tests/development)
kind create cluster --config=infra/kubernetes/cluster/boilerplate-cluster-kind.yml
# load application docker image on Kind (only for tests/development)
kind load docker-image -n boilerplate-cluster boilerplate-image:1.0
# create namespace
kubectl create -f=infra/kubernetes/namespaces/boilerplate-namespace.yml
# secrets
kubectl create -f=infra/kubernetes/secrets/boilerplate-secrets.yml
# or
# create secrets from env (only for tests/development)
kubectl create secret generic -n boilerplate-namespace boilerplate-secrets --from-env-file=envs/.env.production
# deployments
kubectl create -f=infra/kubernetes/deployments/boilerplate-deployment.yml
# services
kubectl create -f=infra/kubernetes/services/boilerplate-service.yml
# connect CONTAINER:HOST ports
kubectl port-forward -n boilerplate-namespace services/boilerplate-service 3000
# tail deployment logs
kubectl -n boilerplate-namespace logs --follow deployments/boilerplate-deployment # follow first pod
kubectl -n boilerplate-namespace logs --follow boilerplate-deployment-76c9b5bdcc-2t4wp # follow pod with ID 'boilerplate-deployment-76c9b5bdcc-2t4wp'
# delete locally application docker image
docker image rm boilerplate-image:1.0
# delete all cluster and resources (only for tests/development)
kind delete cluster --name boilerplate-cluster
# delete resource
kubectl delete -f=<resource_config_path> # or kubectl delete -n <resource_namespace> <resource_type> <resource_name>
yarn run db:migration-run && yarn run db:seed # create database entities and populate database registers
yarn run mock-dependencies # create message queue and storager and start external services mock
yarn run start:dev # start application in development mode
yarn run receive-messages # create websocket client and start connection to receive events
yarn run send-message # send event message to queue
- localhost:3000 - Application Interface (API)
/
- WebSocket Root Endpoint/api
- REST Root Endpoint/api/docs
- Swagger API Documentation (Page)/api/docs.yml
- Swagger API Documentation (YAML)/api/docs.json
- Swagger API Documentation (JSON)
/graphql
- GraphQL Endpoint
- localhost:4000 - Mocked Service Page
- localhost:8000 - Nest.js DevTools Page
- localhost:8080 - Adminer Page
- localhost:8081 - Mongo Express Page
- localhost:8082 - Redis Commander Page
- localhost:9000 - Jenkins Page
- localhost:9001 - SonarQube Page
- localhost:9002 - Grafana Page
- Clustering
- Clusters
- Kubernetes
- Load Balancing
- Clusters
- CI/CD
- Jenkins
- Deployment
- Heroku
- Tests
- Integration
- Modules
- API
- Controllers
- DTO
- Pipes
- Schemas
- App
- API
- Controllers
- DTO
- Pipes
- Schemas
- Repositories
- Services
- API
- Core
- Configs
- Cron
- Tasks
- Infra
- [ ] Models
- [ ] Repositories
- Integration
- Rest
- Integration
- Logging
- Start
- Domain
- Events
- Queue
- Handlers
- Schemas
- Handlers
- Websocket
- Queue
- Graphql
- DTO
- Services
- API
- Modules
- End-to-End
- Modules
- API
- Controllers
- Filters
- Guards
- Middlewares
- App
- API
- controllers
- API
- Core
- Cron
- Jobs
- Infra
- Cache
- Data
- Database
- Models
- Repositories
- Integration
- AWS
- Providers
- Cron
- Domain
- Events
- Queue
- Consumers
- Producers
- Websocket
- Client
- Guards
- Server
- Queue
- Graphql
- DTO
- Resolvers
- API
- Modules
- Integration