This is a example designed to help you quickly set up a Turborepo monorepo with a Next.js app and Prisma ORM. This is a community-maintained example. If you experience a problem, please submit a pull request with a fix. GitHub Issues will be closed.
This turborepo includes the following packages/apps:
web: a Next.js app@repo/eslint-config:eslintconfigurations (includeseslint-config-nextandeslint-config-prettier)@repo/database: Prisma ORM to manage & access your database@repo/typescript-config:tsconfig.jsons used throughout the monorepo
Each package/app is 100% TypeScript.
This turborepo has some additional tools already setup for you:
- TypeScript for static type checking
- ESLint for code linting
- Prettier for code formatting
- Prisma ORM for accessing the database
- Docker Compose for a local MySQL database
Follow these steps to set up and run your Turborepo project with Prisma ORM:
Start by creating a new Turborepo project using the following command:
npx create-turbo@latest -e with-prismaChoose your desired package manager when prompted and a name for the app (e.g., my-turborepo). This will scaffold a new Turborepo project with Prisma ORM included and dependencies installed.
Navigate to your project directory:
cd ./my-turborepoWe use Prisma ORM to manage and access our database. As such you will need a database for this project, either locally or hosted in the cloud.
To make this process easier, a docker-compose.yml file is included to setup a MySQL server locally with a new database named turborepo:
Start the MySQL database using Docker Compose:
docker-compose up -dTo change the default database name, update the MYSQL_DATABASE environment variable in the docker-compose.yml file.
Once the database is ready, copy the .env.example file to the /packages/database and /apps/web directories as .env:
cp .env.example ./packages/database/.env
cp .env.example ./apps/web/.envThis ensures Prisma has access to the DATABASE_URL environment variable, which is required to connect to your database.
If you added a custom database name, or use a cloud based database, you will need to update the DATABASE_URL in your .env accordingly.
Once your database is running, you’ll need to create and apply migrations to set up the necessary tables. Run the database migration command:
# Using npm
npm run db:migrate:devExpand for yarn, pnpm or bun
# Using yarn
yarn run db:migrate:dev
# Using pnpm
pnpm run db:migrate:dev
# Using bun
bun run db:migrate:devYou’ll be prompted to name the migration. Once you provide a name, Prisma will create and apply the migration to your database.
Note: The
db:migrate:devscript (located in packages/database/package.json) uses Prisma Migrate under the hood.
For production environments, always push schema changes to your database using the prisma migrate deploy command. You can find an example db:migrate:deploy script in the package.json file of the database package.
To populate your database with initial or fake data, use Prisma's seeding functionality.
Update the seed script located at packages/database/src/seed.ts to include any additional data that you want to seed. Once edited, run the seed command:
# Using npm
npm run db:seedExpand for yarn, pnpm or bun
# Using yarn
yarn run db:seed
# Using pnpm
pnpm run db:seed
# Using bun
bun run db:seedTo build all apps and packages in the monorepo, run:
# Using npm
npm run buildExpand for yarn, pnpm or bun
# Using yarn
yarn run build
# Using pnpm
pnpm run build
# Using bun
bun run buildFinally, start your application with:
yarn run devExpand for yarn, pnpm or bun
# Using yarn
yarn run dev
# Using pnpm
pnpm run dev
# Using bun
bun run devYour app will be running at http://localhost:3000. Open it in your browser to see it in action!
You can also read the official detailed step-by-step guide from Prisma ORM to build a project from scratch using Turborepo and Prisma ORM.
Learn more about the power of Turborepo: