Giter Site home page Giter Site logo

clean-architecture-express-typescript's Introduction

SimpleBookReader

About

  • Uncle Bob's clean architecture implementation in express/typescript/jest/sequelize

Features

  • get/post books
  • basic data validation via @hapi/Joi
  • sequelize fixtures enabled
  • basic jest test cases for data-access/services
  • typescript configuration

Getting Started

  1. Install Mysql and start Mysql.server.
  2. Create database simple-book-reader for development and
    simple-book-reader-test for test
  3. npm install
  4. npm run dev
  5. For test, run npm test

Folder Structure

  • 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 js Error and for 4XX errors, use ClientError.

  • Model-validations: This is the place where the business logic of each entity resides. It validates given data with Joi schema.
    It throws ClientError when data is invalid and returns getter methods for each field instead of returning data object directly.
    This makes service code more resilient to changes in entities structure.

  • Model: Place for sequelize model definition however you can use whatever ORM 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 use data-access to interact with database.

Reference

This repository is heavily inspired by dev-master and his repo - comments api.

clean-architecture-express-typescript's People

Contributors

leejh3224 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.