Skip to content

jpb06/nest-prisma-monorepo

Repository files navigation

nest-prisma-monorepo

Open in Visual Studio Code Github workflow Quality Gate Status Maintainability Rating Security Rating Reliability Rating Coverage Technical Debt Code Smells Bugs Vulnerabilities Duplicated Lines (%) Last commit

Here is the POC of a monorepo built with nestjs and prisma used to expose several apps, relying on several databases.

                 

⚡ Requirements

You will need the following to use this POC :

Item Description Documentation
nodejs Duh! https://nodejs.org/en/
Docker we will use docker to launch a postgres instance https://www.docker.com/get-started
bun We will use bun as the package manager for this project https://bun.sh/docs

⚡ How to start

🔶 Firstof, let's start our database using docker

You may need to give execution permission to the entry point script file, that is responsible for creating our three databases:

chmod +x docker/pg-init-scripts/create-multiple-db.sh

Let's then use docker compose :

bun docker

🔶 Then we can migrate our schemas and seed the databases

bun dev:db

🔶 Launching our backends in dev mode

# Hiking app (port 5001)
bun dev hiking-app
# Projects app (port 5002)
bun dev projects-app

🔶 Accessing apps swaggers

Now we can access the swaggers of our apps using the following urls:

🔶 Building our apps for production

bun run build

⚡ Project structure

🎉 Apps

Database Description
🚀 Hiking app This kiking app allows users to check and join hiking groups planning to do a walk on some trail. This app owns a database but also uses the Users database.
🚀 Projects app This projects app allows users to check contributions made to repositories. This app owns a database and also uses the Users database.

🧩 Libs

Database Description
🧩 Boostraper The code necessary to create an app is defined there and shared between apps.
🧩 Databases The base prisma services are defined on this shared module.
🧩 Decorators Decorators used in all our apps.
🧩 Filters Filters used in all our apps.
🧩 Pipes Pipes used in all our apps.
🧩 Rxjs Rxjs helpers.
🧩 Tests Test related code.

⚡ Data model

We have three databases:

Database Description
👨 Users Contains our users (duh). This database will serve as the single base of truth for everything user related in our apps.
🏔️ Hiking Database dedicated to the hiking backend service.
🧳 Projects Database dedicated to the projects backend service.

Let's take a look at the schema:

Diagram