Coder Social home page Coder Social logo

express-ts-ddd's Introduction

Express-TS-DDD REST API

TypeScript GitHub Repo Size Github CI License MIT

This is another Express + TypeScript + DDD (Domain Driven Design patterns) + IoC/DI (Inversion of control and Dependency injection) + Primsa ORM + API REST boilerplate.

Installation and Configuration

yarn install
yarn prisma generate

Generate .env file

cp .env.dist .env

You have to configure local environment variables such as PostgreSQL connection string with your own parameters inside .env file. These are the default values:

PORT=3000
APP_NAME="express-ts-ddd"

# Prisma supports the native connection string format for PostgreSQL, MySQL and SQLite.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings

APP_DATABASE_URL="postgresql://user:password@localhost:5432/dbname?schema=public"
APP_LOG_LEVEL="debug"

COGNITO_USER_POOL="your_cognito_user_pool"
COGNITO_CLIENT_ID="your_cognito_client_id"
COGNITO_REGION="your-aws-region-x"

Development with nodemon (Runs on 3000 port)

yarn dev

Run tests and generate coverage report

yarn test
yarn coverage

Build/Compile JS (to /dist folder)

yarn build

Access Prisma Studio (Database preview for dev)

We are using Prisma ORM to handle database connections, migrations, code schema management and also its studio web UI to preview database content in development environment. Please check Prisma documentation for more detailed information.

yarn prisma studio

Authentication with AWS Cognito

AWS Cognito is implemented as default authentication service. Please, check documentation on how to configure it for more details: https://aws.amazon.com/cognito/getting-started/


Docker Compose

This project is ready to work with docker-compose 3.8 to initalize the needed stack during development process. To start working run the following commands:

docker-compose build
docker-compose up

Working docker compose environment (Port 8080)

curl http://localhost:8080
curl http://localhost:8080/health_check

Example JSON response (/health_check):

{
  "id": "cd6f2876-5de5-4433-b0b9-fb7a8d47abbb",
  "success": true,
  "date": "2021-02-07T20:13:21.720Z"
}

Build Docker image for production

You can build an optimized Docker production-ready image with the standard command:

docker build -t express-ts-ddd .

And then run the container passing environment variables within the initialization:

docker run --rm -it -p 3000:3000 \
  -e NODE_ENV=production \
  -e APP_DATABASE_URL="postgresql://user:password@host:5432/dbname?schema=public" \
  -e COGNITO_USER_POOL="your_cognito_user_pool" \
  -e COGNITO_CLIENT_ID="your_cognito_client_id" \
  -e COGNITO_REGION="your-aws-region-x" \
  --name express-ts-ddd express-ts-ddd

Next steps

  • Adds Prisma ORM with PostgreSQL implementation
  • Adds Github CI + CI testings
  • Adds better documentation
  • Kubernetes support (Local environment microk8s, minikube...)
  • Docker for development (docker-compose) and production environments
  • Global logger service (Morgan + Winston)
  • Integration basic testing (supertest)
  • Authentication service with Cognito
  • Adds test coverage report, SonarCloud Scan integration

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.