Skip to content

Template project workspace with Nrwl/Nx managing Angular, NestJS and PostgreSQL

License

Notifications You must be signed in to change notification settings

pschulzk/seed-nx

Repository files navigation

PSK Seed Nx

Description

A monorepository template based on Nrwl/Nx set up for Angular with Angular Material, NestJS and Prisma using PostgreSQL.

Inspired by this article: Building a REST API with NestJS and Prisma

Prerequisites

Structure

How to run

Install dependencies within repository folder:

npm ci

Boot Docker container containing sample database for sample backend app:

docker-compose up -d

Configure env vars for backend app by creating apps/psk-api/.env with e. g.:

DATABASE_URL="postgresql://psk_user:mYsEcReTpAsSwOrD@localhost:5432/psk?schema=public"

Run backend app:

npm run serve-api

In another CLI instance, run frontend app:

npm run serve-ui

This command also executes npm run generate-api-lib which reads dist/apps/psk-api/api-swagger-spec.json to generate and store interfaces, modules and services in @psk/psk-lib consumed by psk-ui.

See sample UI at http://localhost:4200/

See API Docs at http://localhost:3000/api/docs

Run unit tests:

npm run test:watch psk-ui
npm run test:watch psk-api

How to add new frontend app

npx nx g @nx/angular:application

How to add new backend app

Add new NestJS app:

npx nx g @nx/nest:application

Define new Entity

Define schema

In apps/psk-api/prisma/schema.prisma, e. g.

model MyEntity {
  id       String  @id @default(uuid())
  name     String
}

To apply schema changes to the Prisma init and migration process, run:

npx dotenv -e apps/{YOUR_APP_NAME}/.env -- npx prisma migrate dev --schema apps/{YOUR_APP_NAME}/prisma/schema.prisma

Because of the Nx folder structure dotenv-cli is required to pass environment variable from apps/psk-api/.env to Prisma CLI.

This will also run @brakebein/prisma-generator-nestjs-dto in order to generate all DTOs from the prism schema in apps/psk-api/generated.

Use nestjs-prisma-crud to generate new CRUD templates for entities:

npx nx g -c nestjs-prisma-crud-schematics crud-resource MyEntity

Then, import the generated DTOs in apps/psk-api/generated to the generated NestJS CRUD services.

Generate modules and services to corresponding library for Angular apps to consume:

npm run generate-api-lib

This is configured in psk-api-openapi-gen.json.

How to add new library

npx nx g @nx/node:library

About

Template project workspace with Nrwl/Nx managing Angular, NestJS and PostgreSQL

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published