/node-express-mysql-template

This is a template project which will help in doing a quick POC or anything of that sorts.

Primary LanguageTypeScript

Implementation Details:

General Approach

Architecture Diagram

API

  • GET /api/v1/* -> This is just a placeholder to show how a request and response JSON looks like.

    Sample Request Body

    {
      "data": {
          "type": "replies",
          "attributes": {
          }
      }
    }
    

    Sample Response Body

    {
      "meta": {},
      "data": {
          "type": "reply",
          "attributes": {
          }
      }
    }
    

How to run

Create a mysql db and update the configs accordingly. Build the project

yarn build

Runs the migrations

yarn db migration:run

Start the server in watch mode

yarn start

Run tests

yarn test

yarn test:coverage #for test coverage report

Linting

yarn lint

yarn lint --fix #for fixing all the lint errors

Folder Structure

A top level brief of structure

src
├── controllers            # All the controllers
├── db                     # Migrations and orm config
├── entity                 # Typeorm entities
├── errors                 # Custom errors
├── lib                    # Any third party and first party integrations
├── middlewares            # Just middlewarawes
├── routes                 # Register all the controller with express
├── schema                 # Joi schema definitions
├── serializers            # JSONAPI serilizer files
├── services               # Core business logic
├── types                  # Type definitions
└── config files

Architecture Notes

  • API Design:

    • Follows REST standarads.
    • Future scope for versioning of APIs.
    • I wanted to write something more standardised so I chose to follow https://jsonapi.org standards. The API expects and also reponds back accoding to the jsonapi standards.
  • Database

  • Exception Handling

  • Specs

  • Request/Response Validations:

    • Joiful schema is used to validate the requests and any repsonses from third part APIs.
  • Github Actions

    • Currenlty there's one workflow, which is triggered on push to master, to build and run the tests in github actions

ToDo

  • Logging
  • Authorization
  • Dockerize the application
  • API documentation (Swagger)

Things I am contemplating

  • Deployment strategy
  • Rate limiting
  • Load testing