Giter VIP home page Giter VIP logo

nestjs-prisma-monorepo's Introduction

Nest Prisma Monorepo

This template is what I came up with after I learned about monorepos and played with them for a while, hope you find it helpful!

About

  • Nest.js + JWT + GraphQL (code-first) + REST + Swagger*
  • Prisma + utilities
  • Front-end app **
  • Full Typescript support
  • Common package
  • Core package + NestJS utilites
  • ESLint Ready (yarn lint)
  • Prettier Ready
  • CI for GitHub Actions
  • Yarn (berry) version 3.1.0 (PnP disabled since it's not supported by NestJs and Prisma yet)

*The api app is a clone of this other awesome template

** The front-end app is just a static HTML file, since people might use different frameworks with NestJS, so feel free to add a NextJS / NuxtJS / Angular / Svelte / etc. as your front-end

Structure

This template follows Nest.js's convention of monorepo, so there are Apps and then there are Libraries.

๐Ÿ“ฆ nest-prisma-monorepo
 โ”ฃ ๐Ÿ“‚ apps
 โ”ƒ โ”ฃ ๐Ÿ“‚ api
 โ”ƒ โ”ฃ ๐Ÿ“‚ web
 โ”ƒ โ”— ๐Ÿ“‚ etc.
 โ”ฃ ๐Ÿ“‚ libs
 โ”ƒ โ”ฃ ๐Ÿ“‚ common 
 โ”ƒ โ”ฃ ๐Ÿ“‚ core 
 โ”ƒ โ”ฃ ๐Ÿ“‚ prisma
 โ”ƒ โ”— ๐Ÿ“‚ etc.
 โ”ฃ ๐Ÿ“œ.eslintrc.js
 โ”ฃ ๐Ÿ“œ.prettierrc
 โ”ฃ ๐Ÿ“œ.yarnrc.yml
  • core and common are imported from your back-end apps.
  • prisma is used by your back-end apps that need database.
  • common is shared between all of your apps.

How to import from other apps/libraries

To import an package (app or library) into another one:

  1. Add the package as a dependency like so:
{
  "dependencies": {
    "@acme/common": "workspace:*"
  }
}

Note that the @acme/common name, comes from libs/common/package.json's name key:

{
  "name": "@acme/common"
}
  1. Use it in your code like this:
import { MyCommonModule } from '@acme/common';

Note: After cloning, replace all acmes with your organization/project name.

Note about Prisma

Instead of importing your Prisma modules from @prisma/client, now you import them from @acme/prisma.

This way you can defined your schema in a "library" and then import the prisma client in different apps, accessing the same database.

For instance:

import { PrismaClient } from '@acme/prisma';

const prisma = new PrismaClient();

Note about .env files

After you clone the template, you gotta create two environment files, one in apps/api and one in lib/prisma. You could just copy .env.example and rename it to .env and fill it with your own values.

Alternatives

  • https://nx.dev/ (Currently, I just use NX. I didn't know about NX while making this template)

nestjs-prisma-monorepo's People

Contributors

alitnk avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.