Here is the POC of a monorepo built with nestjs and prisma used to expose several apps, relying on several databases.
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 |
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
bun dev:db
# Hiking app (port 5001)
bun dev hiking-app
# Projects app (port 5002)
bun dev projects-app
Now we can access the swaggers of our apps using the following urls:
bun run build
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. |
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. |
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: