- Uncle Bob's clean architecture implementation in express/typescript/jest/sequelize
- get/post books
- basic data validation via
@hapi/Joi
- sequelize fixtures enabled
- basic jest test cases for data-access/services
- typescript configuration
- Install
Mysql
and startMysql.server
. - Create database
simple-book-reader
for development and
simple-book-reader-test
for test npm install
npm run dev
- For test, run
npm test
-
Controllers: Unlike huge and mighty typical express.js controllers, controllers focus
on returning response object for given custom request object(IHttpRequest
). -
Data-access: Instead of directly using
sequelize
model methods,data-access
wraps those api thus
provides proper abstractions over the framework. -
Errors: Generally, typical web application needs to handle two kinds of errors, one is 5XX error and
the other is 4XX error. So for 5XX errors, use native jsError
and for 4XX errors, useClientError
. -
Model-validations: This is the place where the business logic of each entity resides. It validates given data with
Joi
schema.
It throwsClientError
when data is invalid and returnsgetter
methods for each field instead of returning data object directly.
This makesservice
code more resilient to changes in entities structure. -
Model: Place for
sequelize
model definition however you can use whateverORM
or database client you like. It should work regardless of your selection of framework/library. -
Routes: It contains definition for each routes. For each route handlers, it must be wrapped with
buildExpressCallback
helper. Thus making our controller simple, dumb and not knowing which routing framework you're using. -
Services: It handles validations via
models-validation
and usedata-access
to interact with database.
This repository is heavily inspired by dev-master and his repo - comments api.