Express ts ddd
Nodejs Express-TypeScript-DDD REST API
This is another Express + TypeScript + DDD (Domain Driven Design patterns) + IoC/DI (Inversion of control and Dependency injection) + Primsa ORM + API REST boilerplate. The project is written primarily in TypeScript, distributed under the MIT License license, first published in 2021. Key topics include: ddd, ddd-architecture, ddd-patterns, express-boilerplate, express-docker.
Express-TS-DDD REST API
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
bashyarn install yarn prisma generate
Generate .env file
bashcp .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:
envPORT=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)
bashyarn dev
Run tests and generate coverage report
bashyarn test yarn coverage
Build/Compile JS (to /dist folder)
bashyarn 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.
bashyarn 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:
bashdocker-compose build docker-compose up
Working docker compose environment (Port 8080)
bashcurl http://localhost:8080 curl http://localhost:8080/health_check
Example JSON response (/health_check):
json{ "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:
shdocker build -t express-ts-ddd .
And then run the container passing environment variables within the initialization:
shdocker 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
Contributors
Showing top 1 contributor by commit count.
