Skip to content
/ boilerplate Public template

This is a boilerplate ESM, TypeScript, mongoose, openapi, etc. microservice template that I use for my work. It can be run as a docker container or a lambda function.

Notifications You must be signed in to change notification settings

theBoEffect/boilerplate

Repository files navigation

Boilerplate Service

A boilerplate typescript micro service that runs as docker or lambda. Click "Use this Template" to use this for your service.

CI

follow me:

Key Stack Components

  • TypeScript
  • ESM
  • Express
  • Mongoose -> MongoDB
  • Serverless-http
  • openAPI/Swagger
  • Express-OpenAPI-Validate
  • @hapi/boom
  • oData API query
  • JSON Patch
  • Passport (see libs in package.json)
  • Jest

Features

  • Authentication and Authorization via UE Auth
  • Configurable MongoDB connection
  • oData support for queries
  • JSON Patch implemented for updates with mongodb
  • OpenAPI (swagger) and Swagger UI (/swagger)
  • Automatic API Documentation Generated via ReDoc (/api)
  • Automatic schema validation using the OpenAPI spec built in as middleware
  • Automatic Type definitions using OpenAPI spec (yarn swag-spec SWAGGER-OBJEC TYPE-NAME)
  • Error handling via @hapi/Boom
  • Works with Docker or Lambda
  • Jest test harness

Have other ideas? Feel free to PR!

oData Spec

https://www.odata.org/documentation/

JSON Patch

http://jsonpatch.com/

DB

If you'd rather use a different database or ODM, the following modifications are necessary:

  • change connection.ts to the appropriate DB
  • validate that slsapp and start both correctly implement connection.ts
  • in each of your api/resources, change the dal.ts file to access the new DB using the new ODM/ORM

Quickstart Run

  • Click "Use this Template" at the top of the repository and setup your project
  • clone your project to your machine
  • start mongodb on port 27017
    • I find the easiest way to do this is via docker in a terminal
    • docker run -p 27017:27017 mongo
  • Copy ./.env_ci to ./.env and modify env.dev.json to set runtime configuration data
  • yarn test (will install dependencies and build first)
  • yarn dev
  • navigate to localhost:3000

Configure For Your Service

  • Update the following in package.json
    • name
    • author
    • person
    • description
    • homepage (your website or project website)
    • logo (your logo or project logo url)
  • Do the above quickstart now...
  • Add src/api resources using the logging example

About

This is a boilerplate ESM, TypeScript, mongoose, openapi, etc. microservice template that I use for my work. It can be run as a docker container or a lambda function.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published