A modern monorepo template for sharing Prisma schema and client between frontend and backend applications
This project is a monorepo configured with Turborepo that allows sharing a Prisma package between different applications, both frontend (Next.js) and backend (NestJS). This approach maintains a single source of truth for your database schema and types, offering a coherent and type-safe development experience across the entire stack.
├── apps/
│ ├── auth/ # NestJS application for authentication
│ └── web/ # Next.js frontend application
├── packages/
│ ├── db/ # Shared Prisma package
│ │ ├── prisma/ # Prisma schema and migrations
│ │ ├── src/ # Exported Prisma client
│ ├── eslint-config/ # Shared ESLint configuration
│ └── typescript-config/ # Shared TypeScript configuration
└── package.json # Monorepo configuration
- Shared Prisma Schema: Define your data model once, use it everywhere
- Type Safety: Complete TypeScript types across frontend and backend
- Rapid Development: Hot reloading and fast rebuilding with Turborepo
- Maintainability: Modular structure for easy maintenance and scalability
- Consistency: Standardized ESLint and TypeScript configuration across all packages
- ORM: Prisma - Modern ORM with TypeScript type generation
- Backend: NestJS - Progressive Node.js framework for efficient and scalable applications
- Frontend: Next.js - React framework with hybrid rendering
- Monorepo Management: Turborepo - Optimized build system for JavaScript/TypeScript monorepos
- Package Manager: pnpm - Fast and space-efficient package manager
-
Clone the repository
git clone https://github.com/edglz/prismashare.git cd prismashare -
Install dependencies
pnpm install
-
Set up the database
Create a.envfile inpackages/dbwith your PostgreSQL connection URL:DATABASE_URL="postgresql://username:password@localhost:5432/mydb?schema=public" -
Generate the Prisma client
cd packages/db pnpm prisma generate -
Run migrations
pnpm prisma migrate dev
-
Start development
cd ../.. # Return to the monorepo root pnpm dev
# Development
pnpm dev # Start all applications in development mode
# Building
pnpm build # Build all applications and packages
# Linting
pnpm lint # Run ESLint on all applications and packages
# Formatting
pnpm format # Format code with PrettierThe @repo/db package exposes both the Prisma client and generated types:
// In the backend (NestJS)
import { PrismaClient } from '@repo/db';
// In the frontend (Next.js)
import { Post, User } from '@repo/db';Contributions are welcome! Please follow these steps:
- Fork the project
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.
Created by Eduardo Gonzalez
