At my day job, we're working on a design doc to mi...
# orm-help
m
At my day job, we're working on a design doc to migrate our node.js backend monolith to a microservice architecture. Likely we'll convert the repo to an Nx monorepo. Each service would then live in
apps/**
, and have it's own
prisma/schema.prisma
file, since the services will be backend by their own postgres dbs. For example:
Copy code
apps/
  service1/
    src/
      ...
    prisma/
      schema.prisma
  service2/
    src/
      ...
    prisma/
      schema.prisma
libs/
  ...
Has anyone done a setup like this using Nx + Prisma? Are there any gotchas that I'm not foreseeing?
e
Heya! I’m using Nx, Prisma ( and Docker ) together fairly often and started with this approach. This will work well until you need to share Prisma clients between apps. In my case, I need to run cron jobs so the Prisma client needs to be imported into the main app and the cron job app. To make it scaleable, I’d break Prisma into its own libs:
Copy code
apps/
  service1/
  service1-crons/
  service2/
  service2-crons/
libs/
  service1-prisma/
    src/
      prisma/
        schema.prisma
  service2-prisma/
    src/
      prisma/
        schema.prisma
If you don’t foresee a scenario where Prisma clients need to be shared between apps, then I think your current approach should work well 😄
👍 2
m
Thank for the insight! That is definitely a scenario we'll run in to. We actually have a design in review right now to split the crons out into their own service... currently they share the same process as the api.
e
Nice one! I also forgot to mention generating Prisma client into each Prisma lib will make best use of Nx’s dep management logic but I’m sure you are across that already! 🙂
m
Yeah, I think eventually we will create an Nx generator to spin up new services with a prisma lib and cron service. But we're pretty far away from that point. I haven't sold the rest of the org on using Nx yet. So hopefully I can build some momentum in that direction.
❤️ 1