Domain-driven design (DDD) based on particular use case scenario. In the context of building applications, DDD talks about problems as domains. The microservice code is divided into different sub components which is mostly independent of eachother.
There are 3 layers
-
Controller
- presentation layer which container the route and request, response validation. This layer can only talk to service layer and shouldnt contain business logic. -
Service
- contains business logic and responsible to return data from lower layer to controller. It can also communicate with service file of other domains. -
Repository
- data layer which wither talks to database model or makes a network call to fetch data. This layer is reponsible to talk to only service layer and shouldnt contain any business logic apart from CRUD operations.
The domains can be of 3 types.
CRUD operation
- directly performs operation on the collection of its database.Network operation
- only makes network calls and doesnt have a controller. The service layer is consumed by other services files.Common
- Files that are reused by other domains.
Each domain has a set of supporting files examples:
contants
- used only within the domainvalidator
- request - response validation + customer validationsutil
- helper functionstypes
- datatypes used between all layers within the domainmodel
- database model / ORM model
├── src
│ ├── __jest__
│ │ └── setup.ts
│ ├── common
│ │ ├── __tests__
│ │ │ └── errors.spec.ts
│ │ ├── constant.ts
│ │ ├── errors.ts
│ │ └── mongoDb.ts
│ ├── contact
│ │ ├── __mocks__
│ │ │ └── contacts.data.ts
│ │ ├── __tests__
│ │ │ ├── contact.controller.spec.ts
│ │ │ ├── contact.repository.spec.ts
│ │ │ └── contact.service.spec.ts
│ │ ├── contact.constant.ts
│ │ ├── contact.controller.ts
│ │ ├── contact.error.ts
│ │ ├── contact.model.ts
│ │ ├── contact.repository.ts
│ │ ├── contact.service.ts
│ │ ├── contact.type.ts
│ │ └── contact.validator.ts
│ ├── errors
│ │ └── AppError.ts
│ ├── heathcheck
│ │ └── healthcheck.controller.ts
│ ├── plugins
│ │ └── swagger.ts
│ ├── routes.ts
│ └── server.ts
├── package.json
├── package-lock.json
└── tsconfig.json
Node 14.9.0
Hapi 18.4.1
How to run application
npm run start
How to lint
npm run lint
How to run test
npm run test
How to run test coverage
npm run test:cov
npm run start
&& hit http://localhost:3000/documentation
- Domain Arch
- Plugins
- Swagger
- MongoDb integration
- Application Error Handling
- Health check endpoint
- Eslint check and min 90% test coverage check before pushing