I am no longer working on this repo.
If you are still interested in this NestJS starter, please checkout this other repo on which I am actively contributing. :)
https://github.com/monstar-lab-oss/nestjs-starter-rest-api
This is a proof-of-concept app which utilizes the following projects/technologies.
- NestJS - NodeJS Framework.
- Serverless - Build applications with serverless architectures using AWS Lambda.
Technology | Sub-task | Progress |
---|---|---|
NestJS | - | In-Progress |
Initial Setup | Done | |
JWT Auth guard | Done | |
Env Config service | Done | |
All exceptions filter | Done | |
Req/Res interceptor | Done | |
Logger service | Done | |
Auto-generated Swagger | In-Progress | |
Request ID middleware | Done | |
Serverless | - | Done |
Lambda Handler | Done | |
Lambda deployment | Done | |
CI/CD support | - | Done |
CircleCI | Done | |
Database | - | Not Started |
RDS | Not Started | |
TypeORM | Not Started | |
Logger | - | Done |
Winston | Done |
-
docker-compose
- It would be good to have it for local development.- This would be a good alternative since
serverless offline
does not support hot-reload (at least the way it's implemented right now in this repo). This should consider the use ofoffline DynamoDB
.
- This would be a good alternative since
-
Stages
- Configure various deployment stages likedev
,stg
,prd
. -
TypeORM
- Sample implementation covering TypeORM which uses some database.
.
├── .env (Make sure to create this file locally and fill the env vars)
├── src
│ ├── main.ts (This entry point is used for local server)
│ ├── lambda-main.ts (This entry point is used for lambda server)
│ ├── auth (module)
│ │ ├── guards
│ │ └── strategies (Implementation of JWT token check)
│ ├── users (module)
│ │ ├── users.controller.ts (Controllers call their services)
│ │ ├── users.service.ts (Services can call other services and their own repository)
│ │ └── user.repository.ts (Repository should be called only by its parent service)
│ └── shared (module with shared business logic)
├── test (Contains the end-to-end (e2e) tests)
└── serverless.yml (Serverless framework config file for infrastructure deployment)
As mentioned briefly in the project layout for users
, to keep layout clean, we follow this convention:
- Controllers: HTTP routes map to handler functions in controllers.
- Services: Controllers call their service function.
A) Auser controller
must call only auser service
, and not any other service if it can be avoided.
B) Auser service
can call other services likecats service
, etc.
C) Auser service
must call only auser repository
, and not any other repository if it can be avoided. If auser service
wants to modify data incats repository
, it must call correspondingcats service
function to do it. - Repositories: Repositories have data layer implementation, ex:
Firestore
in this project. They must be called only by their direct parent service, ex: Auser repository
is called by auser service
.
$ npm install
Make sure you add the env vars in .env
file. Just copy the .env.template
file.
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
- API: http://localhost:3000
- Swagger UI: http://localhost:3000/swagger
$ npm run sls-offline
# deploy to DEV environment
npm run deploy:dev
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov